#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 */
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
scalar_t__ foo();
scalar_t__ foo_local();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ stderr;
int main() {
  int i, j;
  unsigned res = 0;
  struct timeval t1, t2;
  for (j = 100; j < 1000000000; j *= 10) {
    fprintf(stderr, "START %d iter!\n", j);
    if (gettimeofday(&t1, NULL)) {
      perror("gettimeofday");
    }
    for (i = 0; i < j; i++) {
      res += foo();
      res += foo_local();
    }
    if (gettimeofday(&t2, NULL)) {
      perror("gettimeofday");
    }
    fprintf(stderr, "STOP !\n");
    fprintf(stderr, "res = %d\n", res);
    printf("%d\t%lf\n", j,
           ((t2.tv_sec - t1.tv_sec) * 1e6 + (t2.tv_usec - t1.tv_usec)) / j);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x64,-0xc(%rbp)
cmpl   $0x3b9aca00,-0xc(%rbp)
jge    12ae <main+0x14e>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmp    $0x0,%rax
je     11c7 <main+0x67>
lea    0xe56(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120e <main+0xae>
mov    $0x0,%al
call   1070 <foo@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <foo_local@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11ce <main+0x6e>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmp    $0x0,%rax
je     1231 <main+0xd1>
lea    0xdec(%rip),%rdi
call   1080 <perror@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%eax
sub    -0x18(%rbp),%eax
cvtsi2sd %eax,%xmm0
mov    -0x1c(%rbp),%eax
sub    -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm1
movsd  0xd7f(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
lea    0xd9a(%rip),%rdi
call   1030 <printf@plt>
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    117d <main+0x1d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x64,%ebx
mov    0x2e66(%rip),%r13
lea    0xeb6(%rip),%r14
xor    %r15d,%r15d
jmp    120b <main+0xab>
nopl   0x0(%rax)
mov    0x0(%r13),%edi
lea    0xe8a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xe80(%rip),%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
sub    0x10(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
sub    0x14(%rsp),%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
mulsd  0xe23(%rip),%xmm0
xorps  %xmm2,%xmm2
cvtsi2sd %ebx,%xmm2
addsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
cvttsd2si %xmm0,%edx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%ebx
cmp    $0x3b9aca00,%ebx
jae    1293 <main+0x133>
mov    0x0(%r13),%edi
lea    0xdf2(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %rax,%rax
jne    1285 <main+0x125>
cmp    $0x2,%ebx
mov    $0x1,%ebp
cmovae %ebx,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <foo@plt>
mov    %rax,%r12
add    %r15d,%r12d
xor    %eax,%eax
call   1050 <foo_local@plt>
mov    %rax,%r15
add    %r12d,%r15d
add    $0xffffffff,%ebp
jne    1240 <main+0xe0>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %rax,%rax
je     1190 <main+0x30>
lea    0xd9d(%rip),%rdi
call   1080 <perror@plt>
jmp    1190 <main+0x30>
lea    0xd8c(%rip),%rdi
call   1080 <perror@plt>
jmp    1230 <main+0xd0>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@stderr = global i32 0
@.str = [16 x i8] c"START %d iter!\0A\00"
@.str.1 = [13 x i8] c"gettimeofday\00"
@.str.2 = [8 x i8] c"STOP !\0A\00"
@.str.3 = [10 x i8] c"res = %d\0A\00"
@.str.4 = [8 x i8] c"%d\09%lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
store i32 0, i32* %1
store i32 0, i32* %4
store i32 100, i32* %3
br label %7
7: ; preds = %67, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 1000000000
br i1 %9, label %10, label %70
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = load i32, i32* %3
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i64 @gettimeofday(%struct.timeval* %5, i32* null)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
store i32 0, i32* %2
br label %19
19: ; preds = %34, %18
%20 = load i32, i32* %2
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %37
23: ; preds = %19
%24 = call i64 (...) @foo()
%25 = load i32, i32* %4
%26 = zext i32 %25 to i64
%27 = add nsw i64 %26, %24
%28 = trunc i64 %27 to i32
store i32 %28, i32* %4
%29 = call i64 (...) @foo_local()
%30 = load i32, i32* %4
%31 = zext i32 %30 to i64
%32 = add nsw i64 %31, %29
%33 = trunc i64 %32 to i32
store i32 %33, i32* %4
br label %34
34: ; preds = %23
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 1
store i32 %36, i32* %2
br label %19
37: ; preds = %19
%38 = call i64 @gettimeofday(%struct.timeval* %6, i32* null)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %42
42: ; preds = %40, %37
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%45 = load i32, i32* @stderr
%46 = load i32, i32* %4
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %3
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%50 = load i32, i32* %49
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%52 = load i32, i32* %51
%53 = sub nsw i32 %50, %52
%54 = sitofp i32 %53 to double
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%56 = load i32, i32* %55
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%58 = load i32, i32* %57
%59 = sub nsw i32 %56, %58
%60 = sitofp i32 %59 to double
%61 = call double @llvm.fmuladd.f64(double %54, double 1.000000e+06, double %60)
%62 = load i32, i32* %3
%63 = sitofp i32 %62 to double
%64 = fdiv double %61, %63
%65 = fptosi double %64 to i32
%66 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %48, i32 %65)
br label %67
67: ; preds = %42
%68 = load i32, i32* %3
%69 = mul nsw i32 %68, 10
store i32 %69, i32* %3
br label %7
70: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@stderr = global i32 0
@.str = [16 x i8] c"START %d iter!\0A\00"
@.str.1 = [13 x i8] c"gettimeofday\00"
@.str.2 = [8 x i8] c"STOP !\0A\00"
@.str.3 = [10 x i8] c"res = %d\0A\00"
@.str.4 = [8 x i8] c"%d\09%lf\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
br label %9
9: ; preds = %0, %36
%10 = phi i32 [ 0, %0 ], [ %28, %36 ]
%11 = phi i32 [ 100, %0 ], [ %54, %36 ]
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %11)
%14 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %9
%17 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %9
%19 = call i32 @llvm.umax.i32(i32 %11, i32 1)
br label %20
20: ; preds = %18, %20
%21 = phi i32 [ %10, %18 ], [ %28, %20 ]
%22 = phi i32 [ 0, %18 ], [ %29, %20 ]
%23 = tail call i64 (...) @foo()
%24 = trunc i64 %23 to i32
%25 = add i32 %21, %24
%26 = tail call i64 (...) @foo_local()
%27 = trunc i64 %26 to i32
%28 = add i32 %25, %27
%29 = add nuw nsw i32 %22, 1
%30 = icmp eq i32 %29, %19
br i1 %30, label %31, label %20
31: ; preds = %20
%32 = call i64 @gettimeofday(%struct.timeval* %2, i32* null)
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
%37 = load i32, i32* @stderr
%38 = tail call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%41 = load i32, i32* %5
%42 = load i32, i32* %6
%43 = sub nsw i32 %41, %42
%44 = sitofp i32 %43 to double
%45 = load i32, i32* %7
%46 = load i32, i32* %8
%47 = sub nsw i32 %45, %46
%48 = sitofp i32 %47 to double
%49 = tail call double @llvm.fmuladd.f64(double %44, double 1.000000e+06, double %48)
%50 = sitofp i32 %11 to double
%51 = fdiv double %49, %50
%52 = fptosi double %51 to i32
%53 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %11, i32 %52)
%54 = mul nsw i32 %11, 10
%55 = icmp ult i32 %54, 1000000000
br i1 %55, label %9, label %56
56: ; preds = %36
ret i32 0
}