#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 {
  float tv_sec;
  float tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, float);
scalar_t__ timeval_sub(struct timeval *, struct timeval, struct timeval);
float set_exec_time(int end) {
  static struct timeval time_start;
  struct timeval time_end;
  struct timeval time_diff;
  if (end) {
    gettimeofday(&time_end, NULL);
    if (timeval_sub(&time_diff, time_end, time_start) == 0) {
      if (end == 1)
        return time_diff.tv_sec + (time_diff.tv_usec / 1000000.0f);
      else if (end == 2)
        printf("%1.2fs", time_diff.tv_sec + (time_diff.tv_usec / 1000000.0f));
    }
    return -1;
  }
  gettimeofday(&time_start, NULL);
  return 0;
}


x86 assembly (clang, -O0):
<set_exec_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11ec <set_exec_time+0xbc>
xor    %eax,%eax
mov    %eax,%esi
lea    -0x10(%rbp),%rdi
call   1050 <gettimeofday@plt>
movsd  -0x10(%rbp),%xmm0
movsd  0x2edd(%rip),%xmm1
lea    -0x18(%rbp),%rdi
call   1030 <timeval_sub@plt>
cmp    $0x0,%rax
jne    11da <set_exec_time+0xaa>
cmpl   $0x1,-0x8(%rbp)
jne    11a0 <set_exec_time+0x70>
movss  -0x18(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
movss  0xe72(%rip),%xmm2
divss  %xmm2,%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1204 <set_exec_time+0xd4>
cmpl   $0x2,-0x8(%rbp)
jne    11d0 <set_exec_time+0xa0>
movss  -0x18(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
movss  0xe44(%rip),%xmm2
divss  %xmm2,%xmm1
addss  %xmm1,%xmm0
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
jmp    11d5 <set_exec_time+0xa5>
jmp    11da <set_exec_time+0xaa>
movss  0xe22(%rip),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1204 <set_exec_time+0xd4>
lea    0x2e49(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_exec_time>:
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
je     1189 <set_exec_time+0x59>
mov    %edi,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movsd  0x8(%rsp),%xmm0
movsd  0x2eeb(%rip),%xmm1
mov    %rsp,%rdi
call   1030 <timeval_sub@plt>
movss  0xe9b(%rip),%xmm0
test   %rax,%rax
jne    119a <set_exec_time+0x6a>
cmp    $0x2,%ebx
je     11a0 <set_exec_time+0x70>
cmp    $0x1,%ebx
jne    119a <set_exec_time+0x6a>
movss  0x4(%rsp),%xmm0
divss  0xe82(%rip),%xmm0
addss  (%rsp),%xmm0
jmp    119a <set_exec_time+0x6a>
lea    0x2eb0(%rip),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
xorps  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
ret
movss  0x4(%rsp),%xmm0
divss  0xe56(%rip),%xmm0
addss  (%rsp),%xmm0
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
movss  0xe39(%rip),%xmm0
jmp    119a <set_exec_time+0x6a>

LLVM IR (-O0):
%struct.timeval = type { float, float }
@set_exec_time.time_start = internal global %struct.timeval zeroinitializer
@.str = [7 x i8] c"%1.2fs\00"
define float @set_exec_time(i32 %0) {
%2 = alloca float
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %39
8: ; preds = %1
%9 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%10 = bitcast %struct.timeval* %4 to <2 x float>*
%11 = load <2 x float>, <2 x float>* %10
%12 = load <2 x float>, <2 x float>* bitcast (%struct.timeval* @set_exec_time.time_start to <2 x float>*)
%13 = call i64 @timeval_sub(%struct.timeval* %5, <2 x float> %11, <2 x float> %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %38
15: ; preds = %8
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%20 = load float, float* %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%22 = load float, float* %21
%23 = fdiv float %22, 1.000000e+06
%24 = fadd float %20, %23
store float %24, float* %2
br label %41
25: ; preds = %15
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 2
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%30 = load float, float* %29
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%32 = load float, float* %31
%33 = fdiv float %32, 1.000000e+06
%34 = fadd float %30, %33
%35 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), float %34)
br label %36
36: ; preds = %28, %25
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37, %8
store float -1.000000e+00, float* %2
br label %41
39: ; preds = %1
%40 = call i32 @gettimeofday(%struct.timeval* @set_exec_time.time_start, i32* null)
store float 0.000000e+00, float* %2
br label %41
41: ; preds = %39, %38, %18
%42 = load float, float* %2
ret float %42
}

LLVM IR (-O2):
%struct.timeval = type { float, float }
@set_exec_time.time_start = internal global %struct.timeval zeroinitializer
@.str = [7 x i8] c"%1.2fs\00"
define float @set_exec_time(i32 %0) {
%2 = alloca <2 x float>
%3 = alloca %struct.timeval
%4 = bitcast <2 x float>* %2 to i8*
%5 = bitcast %struct.timeval* %3 to i8*
%6 = icmp eq i32 %0, 0
br i1 %6, label %30, label %7
7: ; preds = %1
%8 = bitcast <2 x float>* %2 to %struct.timeval*
%9 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%10 = load <2 x float>, <2 x float>* %2
%11 = load <2 x float>, <2 x float>* bitcast (%struct.timeval* @set_exec_time.time_start to <2 x float>*)
%12 = call i64 @timeval_sub(%struct.timeval* %3, <2 x float> %10, <2 x float> %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %32
14: ; preds = %7
switch i32 %0, label %32 [
i32 1, label %15
i32 2, label %22
]
15: ; preds = %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%17 = load float, float* %16
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%19 = load float, float* %18
%20 = fdiv float %19, 1.000000e+06
%21 = fadd float %17, %20
br label %32
22: ; preds = %14
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%24 = load float, float* %23
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%26 = load float, float* %25
%27 = fdiv float %26, 1.000000e+06
%28 = fadd float %24, %27
%29 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), float %28)
br label %32
30: ; preds = %1
%31 = tail call i32 @gettimeofday(%struct.timeval* @set_exec_time.time_start, i32* null)
br label %32
32: ; preds = %7, %22, %14, %30, %15
%33 = phi float [ %21, %15 ], [ 0.000000e+00, %30 ], [ -1.000000e+00, %14 ], [ -1.000000e+00, %22 ], [ -1.000000e+00, %7 ]
ret float %33
}