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

/* Variables and functions */
scalar_t__ CLOCKS_PER_SEC;
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
uint64_t gtime_usec() {
  struct timeval tv;
  uint64_t rslt;
  if (gettimeofday(&tv, 0) != 0) {
    perror("gtime");
    return 0;
  }
  rslt = (uint64_t)tv.tv_sec * 1000000 + (uint64_t)tv.tv_usec;
  rslt = (uint64_t)((double)rslt / (double)CLOCKS_PER_SEC * (double)1000000);
  return rslt;
}


x86 assembly (clang, -O0):
<gtime_usec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
je     1155 <gtime_usec+0x35>
lea    0xec4(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    1196 <gtime_usec+0x76>
mov    -0x10(%rbp),%rax
imul   $0xf4240,%eax,%eax
mov    -0x18(%rbp),%rcx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
mov    0x2e74(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe7b(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gtime_usec>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
jne    1169 <gtime_usec+0x49>
imul   $0xf4240,0x8(%rsp),%eax
add    (%rsp),%eax
cvtsi2sd %eax,%xmm0
mov    0x2e9c(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
mulsd  0xea3(%rip),%xmm0
cvttsd2si %xmm0,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe98(%rip),%rdi
call   1040 <perror@plt>
jmp    1161 <gtime_usec+0x41>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [6 x i8] c"gtime\00"
@CLOCKS_PER_SEC = global i64 0
define i32 @gtime_usec() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca i32
%4 = call i64 @gettimeofday(%struct.timeval* %2, i32 0)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %25
8: ; preds = %0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%10 = load i64, i64* %9
%11 = trunc i64 %10 to i32
%12 = mul nsw i32 %11, 1000000
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%14 = load i64, i64* %13
%15 = trunc i64 %14 to i32
%16 = add nsw i32 %12, %15
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = sitofp i32 %17 to double
%19 = load i64, i64* @CLOCKS_PER_SEC
%20 = sitofp i64 %19 to double
%21 = fdiv double %18, %20
%22 = fmul double %21, 1.000000e+06
%23 = fptosi double %22 to i32
store i32 %23, i32* %3
%24 = load i32, i32* %3
store i32 %24, i32* %1
br label %25
25: ; preds = %8, %6
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [6 x i8] c"gtime\00"
@CLOCKS_PER_SEC = global i64 0
define i32 @gtime_usec() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i64 @gettimeofday(%struct.timeval* %1, i32 0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %22
7: ; preds = %0
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%9 = load i64, i64* %8
%10 = trunc i64 %9 to i32
%11 = mul nsw i32 %10, 1000000
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%13 = load i64, i64* %12
%14 = trunc i64 %13 to i32
%15 = add nsw i32 %11, %14
%16 = sitofp i32 %15 to double
%17 = load i64, i64* @CLOCKS_PER_SEC
%18 = sitofp i64 %17 to double
%19 = fdiv double %16, %18
%20 = fmul double %19, 1.000000e+06
%21 = fptosi double %20 to i32
br label %22
22: ; preds = %7, %5
%23 = phi i32 [ 0, %5 ], [ %21, %7 ]
ret i32 %23
}