void delay_us(unsigned int us) {
  unsigned int i;
  while (us && us--) {
    for (i = 0; i < (100 * 1000 * 1000) / 1000 / 1000 / 5; i++)
      __asm__ __volatile__("nop");
  }
}


x86 assembly (clang, -O0):
<delay_us>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x9(%rbp)
je     112a <delay_us+0x2a>
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    113a <delay_us+0x3a>
jmp    115f <delay_us+0x5f>
movl   $0x0,-0x8(%rbp)
cmpl   $0x14,-0x8(%rbp)
jae    115a <delay_us+0x5a>
nop
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1141 <delay_us+0x41>
jmp    1107 <delay_us+0x7>
pop    %rbp
ret

x86 assembly (clang, -O2):
<delay_us>:
test   %edi,%edi
je     1129 <delay_us+0x29>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
add    $0xffffffff,%edi
jne    1110 <delay_us+0x10>
ret

LLVM IR (-O0):
define void @delay_us(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
br label %4
4: ; preds = %21, %1
%5 = load i32, i32* %2
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i32, i32* %2
%9 = add i32 %8, -1
store i32 %9, i32* %2
%10 = icmp ne i32 %8, 0
br label %11
11: ; preds = %7, %4
%12 = phi i1 [ false, %4 ], [ %10, %7 ]
br i1 %12, label %13, label %22
13: ; preds = %11
store i32 0, i32* %3
br label %14
14: ; preds = %18, %13
%15 = load i32, i32* %3
%16 = icmp ult i32 %15, 20
br i1 %16, label %17, label %21
17: ; preds = %14
br label %18
18: ; preds = %17
%19 = load i32, i32* %3
%20 = add i32 %19, 1
store i32 %20, i32* %3
br label %14
21: ; preds = %14
br label %4
22: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @delay_us(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %7, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %5, %3 ], [ %0, %1 ]
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
tail call void asm sideeffect "nop", "~{dirflag},~{fpsr},~{flags}"()
%5 = add i32 %4, -1
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %3
7: ; preds = %3, %1
ret void
}