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

/* Variables and functions */
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
unsigned long gettime(void) {
  struct timeval tv = {};
  unsigned long sec;
  while (gettimeofday(&tv, NULL) != 0)
    continue;
  sec = tv.tv_sec - 60 * 60 * 24 * 365 * 45;
  return sec * 1000 + tv.tv_usec / 1000;
}


x86 assembly (clang, -O0):
<gettime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
je     1154 <gettime+0x34>
jmp    1138 <gettime+0x18>
mov    -0x8(%rbp),%eax
sub    $0x54960d80,%eax
cltq
mov    %rax,-0x10(%rbp)
imul   $0x3e8,-0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettime>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
jne    1130 <gettime+0x20>
movslq 0x8(%rsp),%rax
imul   $0x3e8,%rax,%rax
movslq 0xc(%rsp),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
movslq %ecx,%rcx
add    %rax,%rcx
movabs $0xfffffeb595db4400,%rax
fe ff ff
add    %rcx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i64 @gettime() {
%1 = alloca %struct.timeval
%2 = alloca i64
%3 = bitcast %struct.timeval* %1 to i8*
br label %4
4: ; preds = %7, %0
%5 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %4
br label %4
8: ; preds = %4
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%10 = load i32, i32* %9
%11 = sub nsw i32 %10, 1419120000
%12 = sext i32 %11 to i64
store i64 %12, i64* %2
%13 = load i64, i64* %2
%14 = mul i64 %13, 1000
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%16 = load i32, i32* %15
%17 = sdiv i32 %16, 1000
%18 = sext i32 %17 to i64
%19 = add i64 %14, %18
ret i64 %19
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i64 @gettime() {
%1 = alloca i64
%2 = bitcast i64* %1 to %struct.timeval*
%3 = bitcast i64* %1 to i8*
store i64 0, i64* %1
br label %4
4: ; preds = %4, %0
%5 = call i64 @gettimeofday(%struct.timeval* %2, i32* null)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %4
7: ; preds = %4
%8 = bitcast i64* %1 to i32*
%9 = load i32, i32* %8
%10 = add nsw i32 %9, -1419120000
%11 = sext i32 %10 to i64
%12 = mul nsw i64 %11, 1000
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%14 = load i32, i32* %13
%15 = sdiv i32 %14, 1000
%16 = sext i32 %15 to i64
%17 = add nsw i64 %12, %16
ret i64 %17
}