int main(int argc, char *argv[]) {
  int i;
  for (i = 0; i < 50000; i++)
    asm volatile("" ::: "memory");
  foo();
  for (i = 0; i < 50000; i++)
    asm volatile("" ::: "memory");
  foo();
  for (i = 0; i < 50000; i++)
    asm volatile("" ::: "memory");
  bar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xc350,-0x14(%rbp)
jge    1158 <main+0x38>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <main+0x1d>
mov    $0x0,%al
call   1040 <foo@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xc350,-0x14(%rbp)
jge    1181 <main+0x61>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1166 <main+0x46>
mov    $0x0,%al
call   1040 <foo@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xc350,-0x14(%rbp)
jge    11aa <main+0x8a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118f <main+0x6f>
mov    $0x0,%al
call   1030 <bar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    $0xc350,%eax
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffff,%eax
jne    1130 <main+0x10>
xor    %eax,%eax
call   1040 <foo@plt>
mov    $0xc350,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%eax
jne    1150 <main+0x30>
xor    %eax,%eax
call   1040 <foo@plt>
mov    $0xc350,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%eax
jne    1170 <main+0x50>
xor    %eax,%eax
call   1030 <bar@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %7
7: ; preds = %11, %2
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 50000
br i1 %9, label %10, label %14
10: ; preds = %7
br label %11
11: ; preds = %10
%12 = load i32, i32* %6
%13 = add nsw i32 %12, 1
store i32 %13, i32* %6
br label %7
14: ; preds = %7
%15 = call i32 (...) @foo()
store i32 0, i32* %6
br label %16
16: ; preds = %20, %14
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 50000
br i1 %18, label %19, label %23
19: ; preds = %16
br label %20
20: ; preds = %19
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
br label %16
23: ; preds = %16
%24 = call i32 (...) @foo()
store i32 0, i32* %6
br label %25
25: ; preds = %29, %23
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 50000
br i1 %27, label %28, label %32
28: ; preds = %25
br label %29
29: ; preds = %28
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %25
32: ; preds = %25
%33 = call i32 (...) @bar()
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %3
%4 = phi i32 [ 0, %2 ], [ %5, %3 ]
tail call void asm sideeffect "", "~{memory},~{dirflag},~{fpsr},~{flags}"()
%5 = add nuw nsw i32 %4, 1
%6 = icmp eq i32 %5, 50000
br i1 %6, label %7, label %3
7: ; preds = %3
%8 = tail call i32 (...) @foo()
br label %9
9: ; preds = %7, %9
%10 = phi i32 [ 0, %7 ], [ %11, %9 ]
tail call void asm sideeffect "", "~{memory},~{dirflag},~{fpsr},~{flags}"()
%11 = add nuw nsw i32 %10, 1
%12 = icmp eq i32 %11, 50000
br i1 %12, label %13, label %9
13: ; preds = %9
%14 = tail call i32 (...) @foo()
br label %15
15: ; preds = %13, %15
%16 = phi i32 [ 0, %13 ], [ %17, %15 ]
tail call void asm sideeffect "", "~{memory},~{dirflag},~{fpsr},~{flags}"()
%17 = add nuw nsw i32 %16, 1
%18 = icmp eq i32 %17, 50000
br i1 %18, label %19, label %15
19: ; preds = %15
%20 = tail call i32 (...) @bar()
ret i32 0
}