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

/* Variables and functions */
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
unsigned long long getCurrentMillis(void) {
  unsigned long long result = 0;
  struct timeval tv;
  if (gettimeofday(&tv, NULL) == 0) {
    result = (unsigned long long)(tv.tv_sec * 1000) + (tv.tv_usec * .001);
  }
  return result;
}


x86 assembly (clang, -O0):
<getCurrentMillis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
jne    11a8 <getCurrentMillis+0x98>
mov    -0x18(%rbp),%eax
imul   $0x3e8,%eax,%eax
cltq
movq   %rax,%xmm1
movaps 0xeb2(%rip),%xmm0
punpckldq %xmm0,%xmm1
movapd 0xeb6(%rip),%xmm0
subpd  %xmm0,%xmm1
movaps %xmm1,%xmm0
unpckhpd %xmm1,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  0xeaa(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xe93(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCurrentMillis>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
jne    1183 <getCurrentMillis+0x73>
movslq (%rsp),%rax
imul   $0x3e8,%rax,%rax
movq   %rax,%xmm0
punpckldq 0xec2(%rip),%xmm0
subpd  0xeca(%rip),%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm2
mulsd  0xec4(%rip),%xmm2
addsd  %xmm0,%xmm1
addsd  %xmm1,%xmm2
cvttsd2si %xmm2,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
subsd  0xeb0(%rip),%xmm2
cvttsd2si %xmm2,%rbx
and    %rcx,%rbx
or     %rax,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, double }
define i64 @getCurrentMillis() {
%1 = alloca i64
%2 = alloca %struct.timeval
store i64 0, i64* %1
%3 = call i64 @gettimeofday(%struct.timeval* %2, i32* null)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %0
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%7 = load i32, i32* %6
%8 = mul nsw i32 %7, 1000
%9 = sext i32 %8 to i64
%10 = uitofp i64 %9 to double
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%12 = load double, double* %11
%13 = call double @llvm.fmuladd.f64(double %12, double 1.000000e-03, double %10)
%14 = fptoui double %13 to i64
store i64 %14, i64* %1
br label %15
15: ; preds = %5, %0
%16 = load i64, i64* %1
ret i64 %16
}

LLVM IR (-O2):
%struct.timeval = type { i32, double }
define i64 @getCurrentMillis() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %0
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%7 = load i32, i32* %6
%8 = mul nsw i32 %7, 1000
%9 = sext i32 %8 to i64
%10 = uitofp i64 %9 to double
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%12 = load double, double* %11
%13 = tail call double @llvm.fmuladd.f64(double %12, double 1.000000e-03, double %10)
%14 = fptoui double %13 to i64
br label %15
15: ; preds = %5, %0
%16 = phi i64 [ %14, %5 ], [ 0, %0 ]
ret i64 %16
}