#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 */
double gettimeofday_sec();
int /*<<< orphan*/ printf(char *, double, ...);
void gettimeofday_op(int mode, int arg) {
  static double t1, t2;
  switch (mode) {
  case 0:
    t1 = 0;
    t2 = 0;
    break;
  case 1:
    t1 = gettimeofday_sec();
    break;
  case 2:
    t2 = gettimeofday_sec();
    break;
  case 3:
    printf("Search Time = %.3f [msec]\n", (t2 - t1) * 1000);
    break;
  case 4:
    printf("Search Time (Ave.) = %.3f [msec] (#iteration = %d)\n",
           (t2 - t1) / (double)arg * 1000, arg);
    break;
  default:
    break;
  }
}


x86 assembly (clang, -O0):
<gettimeofday_op>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %rax,-0x10(%rbp)
sub    $0x4,%rax
ja     1200 <gettimeofday_op+0xe0>
mov    -0x10(%rbp),%rax
lea    0xebe(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2eda(%rip)
xorps  %xmm0,%xmm0
movsd  %xmm0,0x2ed7(%rip)
jmp    1205 <gettimeofday_op+0xe5>
mov    $0x0,%al
call   1040 <gettimeofday_sec@plt>
movsd  %xmm0,0x2ebb(%rip)
jmp    1205 <gettimeofday_op+0xe5>
mov    $0x0,%al
call   1040 <gettimeofday_sec@plt>
movsd  %xmm0,0x2eaf(%rip)
jmp    1205 <gettimeofday_op+0xe5>
movsd  0x2ea2(%rip),%xmm0
subsd  0x2e92(%rip),%xmm0
movsd  0xe52(%rip),%xmm1
mulsd  %xmm1,%xmm0
lea    0xe63(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1205 <gettimeofday_op+0xe5>
movsd  0x2e73(%rip),%xmm0
subsd  0x2e63(%rip),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe1a(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x8(%rbp),%esi
lea    0xe43(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    1205 <gettimeofday_op+0xe5>
jmp    1205 <gettimeofday_op+0xe5>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettimeofday_op>:
push   %rax
cmp    $0x4,%edi
ja     114e <gettimeofday_op+0x2e>
mov    %edi,%eax
lea    0xed9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movq   $0x0,0x2ef5(%rip)
movq   $0x0,0x2ef2(%rip)
pop    %rax
ret
xor    %eax,%eax
call   1040 <gettimeofday_sec@plt>
movsd  %xmm0,0x2ed9(%rip)
pop    %rax
ret
xor    %eax,%eax
call   1040 <gettimeofday_sec@plt>
movsd  %xmm0,0x2ed0(%rip)
pop    %rax
ret
movsd  0x2ec6(%rip),%xmm0
subsd  0x2eb6(%rip),%xmm0
mulsd  0xe76(%rip),%xmm0
lea    0xe8b(%rip),%rdi
mov    $0x1,%al
pop    %rcx
jmp    1030 <printf@plt>
movsd  0x2e9f(%rip),%xmm0
subsd  0x2e8f(%rip),%xmm0
cvtsi2sd %esi,%xmm1
divsd  %xmm1,%xmm0
mulsd  0xe47(%rip),%xmm0
lea    0xe77(%rip),%rdi
mov    $0x1,%al
pop    %rcx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@gettimeofday_op.t1 = internal global double 0.000000e+00
@gettimeofday_op.t2 = internal global double 0.000000e+00
@.str = [27 x i8] c"Search Time = %.3f [msec]\0A\00"
@.str.1 = [52 x i8] c"Search Time (Ave.) = %.3f [msec] (#iteration = %d)\0A\00"
define void @gettimeofday_op(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
switch i32 %5, label %27 [
i32 0, label %6
i32 1, label %7
i32 2, label %9
i32 3, label %11
i32 4, label %17
]
6: ; preds = %2
store double 0.000000e+00, double* @gettimeofday_op.t1
store double 0.000000e+00, double* @gettimeofday_op.t2
br label %28
7: ; preds = %2
%8 = call double (...) @gettimeofday_sec()
store double %8, double* @gettimeofday_op.t1
br label %28
9: ; preds = %2
%10 = call double (...) @gettimeofday_sec()
store double %10, double* @gettimeofday_op.t2
br label %28
11: ; preds = %2
%12 = load double, double* @gettimeofday_op.t2
%13 = load double, double* @gettimeofday_op.t1
%14 = fsub double %12, %13
%15 = fmul double %14, 1.000000e+03
%16 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), double %15)
br label %28
17: ; preds = %2
%18 = load double, double* @gettimeofday_op.t2
%19 = load double, double* @gettimeofday_op.t1
%20 = fsub double %18, %19
%21 = load i32, i32* %4
%22 = sitofp i32 %21 to double
%23 = fdiv double %20, %22
%24 = fmul double %23, 1.000000e+03
%25 = load i32, i32* %4
%26 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), double %24, i32 %25)
br label %28
27: ; preds = %2
br label %28
28: ; preds = %27, %17, %11, %9, %7, %6
ret void
}

LLVM IR (-O2):
@gettimeofday_op.t1 = internal unnamed_addr global double 0.000000e+00
@gettimeofday_op.t2 = internal unnamed_addr global double 0.000000e+00
@.str = [27 x i8] c"Search Time = %.3f [msec]\0A\00"
@.str.1 = [52 x i8] c"Search Time (Ave.) = %.3f [msec] (#iteration = %d)\0A\00"
define void @gettimeofday_op(i32 %0, i32 %1) {
switch i32 %0, label %22 [
i32 0, label %3
i32 1, label %4
i32 2, label %6
i32 3, label %8
i32 4, label %14
]
3: ; preds = %2
store double 0.000000e+00, double* @gettimeofday_op.t1
store double 0.000000e+00, double* @gettimeofday_op.t2
br label %22
4: ; preds = %2
%5 = tail call double (...) @gettimeofday_sec()
store double %5, double* @gettimeofday_op.t1
br label %22
6: ; preds = %2
%7 = tail call double (...) @gettimeofday_sec()
store double %7, double* @gettimeofday_op.t2
br label %22
8: ; preds = %2
%9 = load double, double* @gettimeofday_op.t2
%10 = load double, double* @gettimeofday_op.t1
%11 = fsub double %9, %10
%12 = fmul double %11, 1.000000e+03
%13 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), double %12)
br label %22
14: ; preds = %2
%15 = load double, double* @gettimeofday_op.t2
%16 = load double, double* @gettimeofday_op.t1
%17 = fsub double %15, %16
%18 = sitofp i32 %1 to double
%19 = fdiv double %17, %18
%20 = fmul double %19, 1.000000e+03
%21 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), double %20, i32 %1)
br label %22
22: ; preds = %2, %14, %8, %6, %4, %3
ret void
}