#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 gettimeofday(struct timeval *, int /*<<< orphan*/ *);
unsigned long long date_now() {
  struct timeval tv;
  unsigned long long sec = 0;
  unsigned long long usec = 0;
  if (-1 == gettimeofday(&tv, NULL)) {
    return -1;
  }
  sec = (unsigned long long)(tv.tv_sec) * (1000);
  usec = (unsigned long long)(tv.tv_usec) / (1000);
  return (unsigned long long)sec + usec;
}


x86 assembly (clang, -O0):
<date_now>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1151 <date_now+0x41>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    117b <date_now+0x6b>
imul   $0x3e8,-0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<date_now>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
cmp    $0xffffffff,%eax
je     1153 <date_now+0x43>
imul   $0x3e8,0x10(%rsp),%rcx
mov    0x8(%rsp),%rax
shr    $0x3,%rax
movabs $0x20c49ba5e353f7cf,%rdx
9b c4 20
mul    %rdx
mov    %rdx,%rax
shr    $0x4,%rax
add    %rcx,%rax
add    $0x18,%rsp
ret
mov    $0xffffffffffffffff,%rax
add    $0x18,%rsp
ret

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

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