#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 dummy;
};
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ diff_usec(struct timeval, struct timeval);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ load(int);
int /*<<< orphan*/ printf(char *, int, int /*<<< orphan*/, double);
void child_fn(pid_t id, struct timeval *buf, int nrecord, int nloop_per_resol,
              struct timeval start) {
  int i;
  for (i = 0; i < nrecord; i++) {
    load(nloop_per_resol);
    struct timeval tv;
    if (gettimeofday(&tv, NULL) == -1)
      err(EXIT_FAILURE, "gettimeofday() failed");
    buf[i] = tv;
  }
  for (i = 0; i < nrecord; i++) {
    printf("%d,%ld,%f\n", id, diff_usec(start, buf[i]),
           (double)(i + 1) / nrecord);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<child_fn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8d,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11db <child_fn+0x7b>
mov    -0x20(%rbp),%edi
call   1070 <load@plt>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    11bf <child_fn+0x5f>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1050 <err@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    -0x28(%rbp),%edx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1180 <child_fn+0x20>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1239 <child_fn+0xd9>
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    -0x8(%rbp),%edi
mov    (%rax,%rcx,4),%esi
call   1060 <diff_usec@plt>
mov    -0x2c(%rbp),%esi
mov    %eax,%edx
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xdf0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e2 <child_fn+0x82>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<child_fn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edx,%edx
jle    122e <child_fn+0xce>
mov    %ecx,%ebp
mov    %rsi,%rbx
mov    %edi,%r12d
mov    %r8d,0x14(%rsp)
mov    %edx,0x8(%rsp)
mov    %edx,%r15d
xor    %r14d,%r14d
lea    0x10(%rsp),%r13
jmp    11b1 <child_fn+0x51>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rsp),%eax
mov    %eax,(%rbx,%r14,4)
add    $0x1,%r14
cmp    %r14,%r15
je     11de <child_fn+0x7e>
mov    %ebp,%edi
call   1070 <load@plt>
mov    %r13,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    11a0 <child_fn+0x40>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1050 <err@plt>
jmp    11a0 <child_fn+0x40>
mov    0x8(%rsp),%eax
test   %eax,%eax
mov    0x14(%rsp),%r13d
jle    122e <child_fn+0xce>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %ebp,%ebp
lea    0xe18(%rip),%r14
xchg   %ax,%ax
mov    (%rbx,%rbp,4),%esi
mov    %r13d,%edi
call   1060 <diff_usec@plt>
add    $0x1,%rbp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
divsd  0x8(%rsp),%xmm0
mov    %r14,%rdi
mov    %r12d,%esi
mov    %eax,%edx
call   1030 <printf@plt>
cmp    %rbp,%r15
jne    1200 <child_fn+0xa0>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [22 x i8] c"gettimeofday() failed\00"
@.str.1 = [11 x i8] c"%d,%ld,%f\0A\00"
@EXIT_SUCCESS = global i32 0
define void @child_fn(i32 %0, %struct.timeval* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = alloca %struct.timeval*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.timeval
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
store i32 %4, i32* %13
store i32 %0, i32* %7
store %struct.timeval* %1, %struct.timeval** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 0, i32* %11
br label %14
14: ; preds = %33, %5
%15 = load i32, i32* %11
%16 = load i32, i32* %9
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %36
18: ; preds = %14
%19 = load i32, i32* %10
%20 = call i32 @load(i32 %19)
%21 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @err(i32 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %23, %18
%27 = load %struct.timeval*, %struct.timeval** %8
%28 = load i32, i32* %11
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %27, i64 %29
%31 = bitcast %struct.timeval* %30 to i8*
%32 = bitcast %struct.timeval* %12 to i8*
br label %33
33: ; preds = %26
%34 = load i32, i32* %11
%35 = add nsw i32 %34, 1
store i32 %35, i32* %11
br label %14
36: ; preds = %14
store i32 0, i32* %11
br label %37
37: ; preds = %59, %36
%38 = load i32, i32* %11
%39 = load i32, i32* %9
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %62
41: ; preds = %37
%42 = load i32, i32* %7
%43 = load %struct.timeval*, %struct.timeval** %8
%44 = load i32, i32* %11
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %43, i64 %45
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %46, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 @diff_usec(i32 %48, i32 %50)
%52 = load i32, i32* %11
%53 = add nsw i32 %52, 1
%54 = sitofp i32 %53 to double
%55 = load i32, i32* %9
%56 = sitofp i32 %55 to double
%57 = fdiv double %54, %56
%58 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %51, double %57)
br label %59
59: ; preds = %41
%60 = load i32, i32* %11
%61 = add nsw i32 %60, 1
store i32 %61, i32* %11
br label %37
62: ; preds = %37
%63 = load i32, i32* @EXIT_SUCCESS
%64 = call i32 @exit(i32 %63)
unreachable
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [22 x i8] c"gettimeofday() failed\00"
@.str.1 = [11 x i8] c"%d,%ld,%f\0A\00"
@EXIT_SUCCESS = global i32 0
define void @child_fn(i32 %0, %struct.timeval* nocapture %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca %struct.timeval
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %40
8: ; preds = %5
%9 = bitcast %struct.timeval* %6 to i8*
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%11 = zext i32 %2 to i64
br label %16
12: ; preds = %24
br i1 %7, label %13, label %40
13: ; preds = %12
%14 = sitofp i32 %2 to double
%15 = zext i32 %2 to i64
br label %29
16: ; preds = %8, %24
%17 = phi i64 [ 0, %8 ], [ %27, %24 ]
%18 = tail call i32 @load(i32 %3)
%19 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @err(i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %21, %16
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 %17, i32 0
%26 = load i32, i32* %10
store i32 %26, i32* %25
%27 = add nuw nsw i64 %17, 1
%28 = icmp eq i64 %27, %11
br i1 %28, label %12, label %16
29: ; preds = %13, %29
%30 = phi i64 [ 0, %13 ], [ %34, %29 ]
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 %30, i32 0
%32 = load i32, i32* %31
%33 = tail call i32 @diff_usec(i32 %4, i32 %32)
%34 = add nuw nsw i64 %30, 1
%35 = trunc i64 %34 to i32
%36 = sitofp i32 %35 to double
%37 = fdiv double %36, %14
%38 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %33, double %37)
%39 = icmp eq i64 %34, %15
br i1 %39, label %40, label %29
40: ; preds = %29, %5, %12
%41 = load i32, i32* @EXIT_SUCCESS
%42 = tail call i32 @exit(i32 %41)
unreachable
}