#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 {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
typedef int int64_t;

/* Variables and functions */
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int64_t hi_usec_now(void) {
  struct timeval now;
  int64_t usec;
  int status;
  status = gettimeofday(&now, NULL);
  if (status < 0) {
    return -1;
  }
  usec = (int64_t)now.tv_sec * 1000000LL + (int64_t)now.tv_usec;
  return usec;
}


x86 assembly (clang, -O0):
<hi_usec_now>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    113e <hi_usec_now+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    115e <hi_usec_now+0x4e>
mov    -0x10(%rbp),%rax
cltq
imul   $0xf4240,%rax,%rax
mov    -0x18(%rbp),%rcx
movslq %ecx,%rcx
add    %rcx,%rax
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):
<hi_usec_now>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %eax,%eax
js     1135 <hi_usec_now+0x25>
imul   $0xf4240,0x10(%rsp),%eax
add    0x8(%rsp),%eax
add    $0x18,%rsp
ret
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define i32 @hi_usec_now() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp slt i32 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %0
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%7 = load i64, i64* %6
%8 = shl i64 %7, 32
%9 = ashr exact i64 %8, 32
%10 = mul nsw i64 %9, 1000000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%12 = load i64, i64* %11
%13 = add i64 %10, %12
%14 = trunc i64 %13 to i32
br label %15
15: ; preds = %0, %5
%16 = phi i32 [ %14, %5 ], [ -1, %0 ]
ret i32 %16
}