When using ILDASM.exe on a compiled C# program, it shows that there is a label for every instruction within methods.
For example:
IL_0001: ldc.i4.4
IL_0002: stloc.0
IL_0003: ldc.r8 12.34
IL_000c: stloc.1
IL_000d: ldc.r8 3.1415926535897931
IL_0016: stloc.2
IL_0017: ldstr "Ehsan"
IL_001c: stloc.3
IL_001d: ret
Why is this? Is it not inefficient to do this or does the CIL compiler optimize these labels itself?
Labels are not present in the compiled CIL. They are displayed for your convenience in the dissassembled code.
These particular labels correspond to instruction offsets, while there is no such restriction on hand-made code (labels could be arbitrary strings).