#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 errno;
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *, int);
char *strerror(int);
long long get_current_time() {
  struct timeval time = {};
  if (gettimeofday(&time, NULL) == -1) {
    printf("gettimeofday failed, errno = %s (%d)\n", strerror(errno), errno);
    return -1;
  }
  return (long long)time.tv_sec * 1000 + (long long)time.tv_usec / 1000;
}


x86 assembly (clang, -O0):
<get_current_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    11a1 <get_current_time+0x61>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    11c9 <get_current_time+0x89>
imul   $0x3e8,-0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_current_time>:
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
cmp    $0xffffffff,%eax
je     1175 <get_current_time+0x45>
imul   $0x3e8,0x8(%rsp),%rcx
movabs $0x20c49ba5e353f7cf,%rax
9b c4 20
imulq  (%rsp)
mov    %rdx,%rax
shr    $0x3f,%rdx
sar    $0x7,%rax
add    %rdx,%rax
add    %rcx,%rax
jmp    119b <get_current_time+0x6b>
mov    0x2e64(%rip),%rbx
mov    (%rbx),%edi
call   1050 <strerror@plt>
mov    (%rbx),%edx
lea    0xe74(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
mov    $0xffffffffffffffff,%rax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [38 x i8] c"gettimeofday failed, errno = %s (%d)\0A\00"
@errno = global i32 0
define i64 @get_current_time() {
%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 %5, label %10
5: ; preds = %0
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = load i32, i32* @errno
%9 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %8)
br label %18
10: ; preds = %0
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%12 = load i64, i64* %11
%13 = mul nsw i64 %12, 1000
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%15 = load i64, i64* %14
%16 = sdiv i64 %15, 1000
%17 = add nsw i64 %16, %13
br label %18
18: ; preds = %10, %5
%19 = phi i64 [ -1, %5 ], [ %17, %10 ]
ret i64 %19
}