You should add this option to the first command “-disable-O0-optnone” so clang -Xclang -disable-O0-optnone -emit-llvm -S -o without_dce.ll test.c then opt -dce -S < without_dce.ll > with_dce.ll
I feel like it might save people some significant time in the long run if opt printed a helpful little error message when it is instructed to run >0 transformation passes and also all functions it sees are optnone.