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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct timeval *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, scalar_t__);
int /*<<< orphan*/ sleep(int);
int main() {
  struct timeval start1, end1;
  memset(&start1, 0, sizeof(struct timeval));
  memset(&end1, 0, sizeof(struct timeval));
  gettimeofday(&start1, NULL);
  sleep(1);
  gettimeofday(&end1, NULL);
  printf("TEST"
         " %ld us\n",
         ((end1.tv_sec - start1.tv_sec) * 1000000 + end1.tv_usec -
          start1.tv_usec));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    -0x28(%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>
mov    $0x1,%edi
call   1060 <sleep@plt>
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x28(%rbp),%eax
sub    -0x18(%rbp),%eax
imul   $0xf4240,%eax,%eax
movslq %eax,%rsi
add    -0x20(%rbp),%rsi
sub    -0x10(%rbp),%rsi
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movslq 0x8(%rsp),%rax
movslq 0x18(%rsp),%rcx
sub    %rcx,%rax
imul   $0xf4240,%rax,%rax
mov    0x10(%rsp),%rsi
sub    0x20(%rsp),%rsi
add    %rax,%rsi
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@.str = [13 x i8] c"TEST %ld us\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
store i32 0, i32* %1
%4 = call i32 @memset(%struct.timeval* %2, i32 0, i32 16)
%5 = call i32 @memset(%struct.timeval* %3, i32 0, i32 16)
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%7 = call i32 @sleep(i32 1)
%8 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%12 = load i32, i32* %11
%13 = sub nsw i32 %10, %12
%14 = mul nsw i32 %13, 1000000
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%17 = load i64, i64* %16
%18 = add nsw i64 %15, %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%20 = load i64, i64* %19
%21 = sub nsw i64 %18, %20
%22 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %21)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@.str = [13 x i8] c"TEST %ld us\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @memset(%struct.timeval* %1, i32 0, i32 16)
%6 = call i32 @memset(%struct.timeval* %2, i32 0, i32 16)
%7 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%8 = call i32 @sleep(i32 1)
%9 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%13 = load i32, i32* %12
%14 = sub nsw i32 %11, %13
%15 = mul nsw i32 %14, 1000000
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%18 = load i64, i64* %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%20 = load i64, i64* %19
%21 = sub i64 %18, %20
%22 = add i64 %21, %16
%23 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 %22)
ret i32 0
}