#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 */
int /*<<< orphan*/ crash(char *);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int now() {
  struct timeval tv;
  static int t0;
  if (gettimeofday(&tv, NULL) < 0)
    crash("gettimeofday()");
  if (t0 == 0)
    t0 = tv.tv_sec;
  return ((tv.tv_sec - t0) * 1000 + tv.tv_usec / 1000);
}


x86 assembly (clang, -O0):
<now>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmp    $0x0,%rax
jge    114b <now+0x2b>
lea    0xeba(%rip),%rdi
call   1030 <crash@plt>
cmpl   $0x0,0x2ee2(%rip)
jne    1161 <now+0x41>
mov    -0x8(%rbp),%eax
mov    %eax,0x2ed3(%rip)
mov    -0x8(%rbp),%eax
sub    0x2eca(%rip),%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
add    %ecx,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<now>:
push   %rax
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %rax,%rax
jns    113c <now+0x1c>
lea    0xec9(%rip),%rdi
call   1030 <crash@plt>
mov    0x2ef2(%rip),%ecx
mov    (%rsp),%eax
test   %ecx,%ecx
jne    1151 <now+0x31>
mov    %eax,0x2ee5(%rip)
mov    %eax,%ecx
sub    %ecx,%eax
imul   $0x3e8,%eax,%ecx
movslq 0x4(%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rax
add    %edx,%eax
add    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@now.t0 = internal global i32 0
@.str = [15 x i8] c"gettimeofday()\00"
define i32 @now() {
%1 = alloca %struct.timeval
%2 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @crash(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = load i32, i32* @now.t0
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%11 = load i32, i32* %10
store i32 %11, i32* @now.t0
br label %12
12: ; preds = %9, %6
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%14 = load i32, i32* %13
%15 = load i32, i32* @now.t0
%16 = sub nsw i32 %14, %15
%17 = mul nsw i32 %16, 1000
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%19 = load i32, i32* %18
%20 = sdiv i32 %19, 1000
%21 = add nsw i32 %17, %20
ret i32 %21
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@now.t0 = internal unnamed_addr global i32 0
@.str = [15 x i8] c"gettimeofday()\00"
define i32 @now() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @crash(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = load i32, i32* @now.t0
%9 = icmp eq i32 %8, 0
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%11 = load i32, i32* %10
br i1 %9, label %12, label %13
12: ; preds = %7
store i32 %11, i32* @now.t0
br label %13
13: ; preds = %7, %12
%14 = phi i32 [ %11, %12 ], [ %8, %7 ]
%15 = sub nsw i32 %11, %14
%16 = mul nsw i32 %15, 1000
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%18 = load i32, i32* %17
%19 = sdiv i32 %18, 1000
%20 = add nsw i32 %16, %19
ret i32 %20
}