#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;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int util_timestamp_int() {
  static struct timeval tv1;
  struct timeval tv;
  if (tv1.tv_usec == 0 && tv1.tv_sec == 0)
    gettimeofday(&tv1, NULL);
  gettimeofday(&tv, NULL);
  return (int)(tv.tv_sec - tv1.tv_sec) * 1000000 +
         (int)(tv.tv_usec - tv1.tv_usec);
}


x86 assembly (clang, -O0):
<util_timestamp_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpq   $0x0,0x2f10(%rip)
jne    1144 <util_timestamp_int+0x34>
cmpq   $0x0,0x2f0a(%rip)
jne    1144 <util_timestamp_int+0x34>
lea    0x2ef5(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x8(%rbp),%rax
sub    0x2edc(%rip),%rax
imul   $0xf4240,%eax,%eax
mov    -0x10(%rbp),%rcx
sub    0x2ec3(%rip),%rcx
add    %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_timestamp_int>:
sub    $0x18,%rsp
mov    0x2f15(%rip),%rax
or     0x2f16(%rip),%rax
jne    1132 <util_timestamp_int+0x22>
lea    0x2f05(%rip),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%eax
mov    0x10(%rsp),%ecx
sub    0x2eec(%rip),%ecx
imul   $0xf4240,%ecx,%ecx
sub    0x2ed8(%rip),%eax
add    %ecx,%eax
add    $0x18,%rsp
ret

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

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