#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 int suseconds_t;
struct timezone {
  int dummy;
};
struct timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
scalar_t__ gettimeofday(struct timeval *, struct timezone *);
int /*<<< orphan*/ perror(char *);
suseconds_t tor_getclock() {
  static struct timeval tv;
  if (gettimeofday(&tv, (struct timezone *)NULL) < 0) {
    perror("getclock");
    exit(1);
  }
  return (suseconds_t)tv.tv_sec * 1000000 + tv.tv_usec;
}


x86 assembly (clang, -O0):
<tor_getclock>:
push   %rbp
mov    %rsp,%rbp
lea    0x2f05(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
jge    1164 <tor_getclock+0x34>
lea    0xeab(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2edd(%rip),%rax
imul   $0xf4240,%eax,%eax
add    0x2ec9(%rip),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<tor_getclock>:
push   %rax
lea    0x2f08(%rip),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
js     1156 <tor_getclock+0x26>
imul   $0xf4240,0x2efa(%rip),%eax
add    0x2eec(%rip),%eax
pop    %rcx
ret
lea    0xea3(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
%struct.timezone = type { i32 }
@tor_getclock.tv = internal global %struct.timeval zeroinitializer
@.str = [9 x i8] c"getclock\00"
define i32 @tor_getclock() {
%1 = call i64 @gettimeofday(%struct.timeval* @tor_getclock.tv, %struct.timezone* null)
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @tor_getclock.tv, i32 0, i32 1)
%8 = trunc i64 %7 to i32
%9 = mul nsw i32 %8, 1000000
%10 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @tor_getclock.tv, i32 0, i32 0)
%11 = add nsw i32 %9, %10
ret i32 %11
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
%struct.timezone = type { i32 }
@tor_getclock.tv = internal global %struct.timeval zeroinitializer
@.str = [9 x i8] c"getclock\00"
define i32 @tor_getclock() {
%1 = tail call i64 @gettimeofday(%struct.timeval* @tor_getclock.tv, %struct.timezone* null)
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @tor_getclock.tv, i64 0, i32 1)
%8 = trunc i64 %7 to i32
%9 = mul nsw i32 %8, 1000000
%10 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @tor_getclock.tv, i64 0, i32 0)
%11 = add nsw i32 %9, %10
ret i32 %11
}