#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;
typedef scalar_t__ time_t;
struct timeval {
  scalar_t__ tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
uint64_t ggh_walltime(uint64_t t0) {
  static time_t base_sec;
  struct timeval tp;
  gettimeofday(&tp, NULL);
  if (base_sec == 0)
    base_sec = tp.tv_sec;
  return ((uint64_t)(tp.tv_sec - base_sec)) * 1000000 + (uint64_t)tp.tv_usec -
         t0;
}


x86 assembly (clang, -O0):
<ggh_walltime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmpq   $0x0,0x2f00(%rip)
jne    1141 <ggh_walltime+0x31>
mov    -0x18(%rbp),%rax
mov    %rax,0x2eef(%rip)
mov    -0x18(%rbp),%rax
sub    0x2ee4(%rip),%rax
imul   $0xf4240,%eax,%eax
mov    -0x10(%rbp),%rcx
add    %ecx,%eax
sub    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ggh_walltime>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2f08(%rip),%rcx
mov    (%rsp),%rax
test   %rcx,%rcx
jne    113b <ggh_walltime+0x2b>
mov    %rax,0x2ef8(%rip)
mov    %rax,%rcx
sub    %ecx,%eax
imul   $0xf4240,%eax,%ecx
mov    0x8(%rsp),%eax
sub    %ebx,%eax
add    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@ggh_walltime.base_sec = internal global i64 0
define i32 @ggh_walltime(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
store i32 %0, i32* %2
%4 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%5 = load i64, i64* @ggh_walltime.base_sec
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%9 = load i64, i64* %8
store i64 %9, i64* @ggh_walltime.base_sec
br label %10
10: ; preds = %7, %1
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%12 = load i64, i64* %11
%13 = load i64, i64* @ggh_walltime.base_sec
%14 = sub nsw i64 %12, %13
%15 = trunc i64 %14 to i32
%16 = mul nsw i32 %15, 1000000
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%18 = load i64, i64* %17
%19 = trunc i64 %18 to i32
%20 = add nsw i32 %16, %19
%21 = load i32, i32* %2
%22 = sub nsw i32 %20, %21
ret i32 %22
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@ggh_walltime.base_sec = internal unnamed_addr global i64 0
define i32 @ggh_walltime(i32 %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = load i64, i64* @ggh_walltime.base_sec
%6 = icmp eq i64 %5, 0
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%8 = load i64, i64* %7
br i1 %6, label %9, label %10
9: ; preds = %1
store i64 %8, i64* @ggh_walltime.base_sec
br label %10
10: ; preds = %1, %9
%11 = phi i64 [ %8, %9 ], [ %5, %1 ]
%12 = sub nsw i64 %8, %11
%13 = trunc i64 %12 to i32
%14 = mul nsw i32 %13, 1000000
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%16 = load i64, i64* %15
%17 = trunc i64 %16 to i32
%18 = sub i32 %17, %0
%19 = add i32 %18, %14
ret i32 %19
}