#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 */
typedef long long uint64_t;
struct timeval {
  long long tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
uint64_t getCurrentTimestamp() {
  struct timeval t;
  int code = gettimeofday(&t, NULL);
  assert(code == 0);
  if (code != 0) {
    perror("error calling gettimeofday");
    assert(0);
  }
  uint64_t timestamp = t.tv_sec * 1000000LL;
  timestamp += t.tv_usec;
  return timestamp;
}


x86 assembly (clang, -O0):
<getCurrentTimestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x0,-0x14(%rbp)
je     1176 <getCurrentTimestamp+0x46>
lea    0xe96(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1040 <assert@plt>
imul   $0xf4240,-0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCurrentTimestamp>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    %eax,%ebx
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
test   %ebx,%ebx
jne    1165 <getCurrentTimestamp+0x35>
imul   $0xf4240,(%rsp),%rax
add    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe94(%rip),%rdi
call   1050 <perror@plt>
xor    %edi,%edi
call   1040 <assert@plt>
jmp    1152 <getCurrentTimestamp+0x22>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [27 x i8] c"error calling gettimeofday\00"
define i64 @getCurrentTimestamp() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = alloca i64
%4 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i32, i32* %2
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @assert(i32 0)
br label %14
14: ; preds = %11, %0
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%16 = load i64, i64* %15
%17 = mul nsw i64 %16, 1000000
store i64 %17, i64* %3
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%19 = load i64, i64* %18
%20 = load i64, i64* %3
%21 = add nsw i64 %20, %19
store i64 %21, i64* %3
%22 = load i64, i64* %3
ret i64 %22
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [27 x i8] c"error calling gettimeofday\00"
define i64 @getCurrentTimestamp() {
%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, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
br i1 %4, label %10, label %7
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @assert(i32 0)
br label %10
10: ; preds = %7, %0
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%12 = load i64, i64* %11
%13 = mul nsw i64 %12, 1000000
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%15 = load i64, i64* %14
%16 = add nsw i64 %13, %15
ret i64 %16
}