#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
unsigned long CLOCKS_PER_SEC;
unsigned long clock();
int /*<<< orphan*/ delay(unsigned long);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int main(void) {
  unsigned long loops_per_sec = 1;
  unsigned long ticks;
  unsigned long bogo;
  unsigned long sub;
  printf("Calibrating delay loop.. ");
  fflush(stdout);
  while ((loops_per_sec <<= 1)) {
    ticks = clock();
    delay(loops_per_sec);
    ticks = clock() - ticks;
    if (ticks >= CLOCKS_PER_SEC) {
      loops_per_sec = (loops_per_sec / ticks) * CLOCKS_PER_SEC;
      bogo = loops_per_sec / 500000L;
      sub = loops_per_sec / 5000L;
      sub %= 100;
      printf("ok - %lu.%s%lu BogoMips\n", bogo, (sub < 10) ? "0" : "", sub);
      printf("loops_per_sec=%lu\n", loops_per_sec);
      return 0;
    }
  }
  printf("failed\n");
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x1,-0x10(%rbp)
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1264 <main+0x124>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <delay@plt>
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2e31(%rip),%rcx
cmp    (%rcx),%rax
jb     125f <main+0x11f>
mov    -0x10(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    0x2e15(%rip),%rcx
imul   (%rcx),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x7a120,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x1388,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    $0x64,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rcx
lea    0xe2f(%rip),%rdx
lea    0xe0c(%rip),%rax
cmp    $0xa,%rcx
cmovb  %rax,%rdx
mov    -0x28(%rbp),%rcx
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1279 <main+0x139>
jmp    1173 <main+0x33>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xea5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0x1,%ebx
mov    0x2e6c(%rip),%r14
nopl   0x0(%rax)
add    %rbx,%rbx
je     11c5 <main+0x75>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1060 <delay@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rcx
sub    %rbp,%rcx
mov    (%r14),%rsi
cmp    %rsi,%rcx
jb     1180 <main+0x30>
mov    %rbx,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     11db <main+0x8b>
mov    %rbx,%rax
xor    %edx,%edx
div    %rcx
mov    %rax,%rbx
jmp    11e3 <main+0x93>
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
jmp    126b <main+0x11b>
mov    %ebx,%eax
xor    %edx,%edx
div    %ecx
mov    %eax,%ebx
imul   %rsi,%rbx
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mov    %rbx,%rax
mul    %rcx
mov    %rdx,%rsi
shr    $0x11,%rsi
movabs $0x346dc5d63886594b,%rcx
c5 6d 34
mov    %rbx,%rax
mul    %rcx
mov    %rdx,%rax
mov    %rdx,%rcx
shr    $0xa,%rcx
shr    $0xc,%rax
movabs $0x28f5c28f5c28f5c3,%rdx
c2 f5 28
mul    %rdx
shr    $0x2,%rdx
imul   $0x64,%rdx,%rax
sub    %rax,%rcx
cmp    $0xa,%rcx
lea    0xdf4(%rip),%rax
lea    0xdec(%rip),%rdx
cmovb  %rax,%rdx
lea    0xdc9(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdd4(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Calibrating delay loop.. \00"
@stdout = global i32 0
@CLOCKS_PER_SEC = global i64 0
@.str.1 = [25 x i8] c"ok - %lu.%s%lu BogoMips\0A\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [19 x i8] c"loops_per_sec=%lu\0A\00"
@.str.5 = [8 x i8] c"failed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
store i64 1, i64* %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdout
%8 = call i32 @fflush(i32 %7)
br label %9
9: ; preds = %44, %0
%10 = load i64, i64* %2
%11 = shl i64 %10, 1
store i64 %11, i64* %2
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %45
13: ; preds = %9
%14 = call i64 (...) @clock()
store i64 %14, i64* %3
%15 = load i64, i64* %2
%16 = call i32 @delay(i64 %15)
%17 = call i64 (...) @clock()
%18 = load i64, i64* %3
%19 = sub i64 %17, %18
store i64 %19, i64* %3
%20 = load i64, i64* %3
%21 = load i64, i64* @CLOCKS_PER_SEC
%22 = icmp uge i64 %20, %21
br i1 %22, label %23, label %44
23: ; preds = %13
%24 = load i64, i64* %2
%25 = load i64, i64* %3
%26 = udiv i64 %24, %25
%27 = load i64, i64* @CLOCKS_PER_SEC
%28 = mul i64 %26, %27
store i64 %28, i64* %2
%29 = load i64, i64* %2
%30 = udiv i64 %29, 500000
store i64 %30, i64* %4
%31 = load i64, i64* %2
%32 = udiv i64 %31, 5000
store i64 %32, i64* %5
%33 = load i64, i64* %5
%34 = urem i64 %33, 100
store i64 %34, i64* %5
%35 = load i64, i64* %4
%36 = load i64, i64* %5
%37 = icmp ult i64 %36, 10
%38 = zext i1 %37 to i64
%39 = select i1 %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%40 = load i64, i64* %5
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 %35, i8* %39, i64 %40)
%42 = load i64, i64* %2
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i64 %42)
store i32 0, i32* %1
br label %47
44: ; preds = %13
br label %9
45: ; preds = %9
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %47
47: ; preds = %45, %23
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str = [26 x i8] c"Calibrating delay loop.. \00"
@stdout = global i32 0
@CLOCKS_PER_SEC = global i64 0
@.str.1 = [25 x i8] c"ok - %lu.%s%lu BogoMips\0A\00"
@.str.2 = [2 x i8] c"0\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [19 x i8] c"loops_per_sec=%lu\0A\00"
@str = [7 x i8] c"failed\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%2 = load i32, i32* @stdout
%3 = tail call i32 @fflush(i32 %2)
br label %4
4: ; preds = %8, %0
%5 = phi i64 [ 1, %0 ], [ %6, %8 ]
%6 = shl i64 %5, 1
%7 = icmp eq i64 %6, 0
br i1 %7, label %25, label %8
8: ; preds = %4
%9 = tail call i64 (...) @clock()
%10 = tail call i32 @delay(i64 %6)
%11 = tail call i64 (...) @clock()
%12 = sub i64 %11, %9
%13 = load i64, i64* @CLOCKS_PER_SEC
%14 = icmp ult i64 %12, %13
br i1 %14, label %4, label %15
15: ; preds = %8
%16 = udiv i64 %6, %12
%17 = mul i64 %16, %13
%18 = udiv i64 %17, 500000
%19 = udiv i64 %17, 5000
%20 = urem i64 %19, 100
%21 = icmp ult i64 %20, 10
%22 = select i1 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 %18, i8* %22, i64 %20)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i64 %17)
br label %27
25: ; preds = %4
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %27
27: ; preds = %25, %15
%28 = phi i32 [ 0, %15 ], [ -1, %25 ]
ret i32 %28
}