#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 timezone {
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ err(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ gettimeofday(struct timeval *, struct timezone *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int time(int /*<<< orphan*/ *);
int main(void) {
  struct timeval t_m = {0, 0};
  struct timezone t_z = {0, 0};
  struct timeval t_m1 = {0, 0};
  int i;
  if (gettimeofday(&t_m, &t_z) != 0)
    err("gettimeofday");
  for (i = 1; i < 10000; i++)
    if (gettimeofday(&t_m1, NULL) != 0)
      err("gettimeofday 1");
    else if (t_m1.tv_sec * 1000000 + t_m1.tv_usec !=
             (t_m.tv_sec * 1000000 + t_m.tv_usec + i * 1000)) {
      fprintf(stderr, "t0 (%ld, %ld), i %d, t1 (%ld, %ld)\n", t_m.tv_sec,
              t_m.tv_usec, i, t_m1.tv_sec, t_m1.tv_usec);
      abort();
    }
  if (time(NULL) != t_m1.tv_sec) {
    fprintf(stderr, "time != gettod\n");
    abort();
  }
  printf("pass\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <gettimeofday@plt>
cmp    $0x0,%rax
je     11e2 <main+0x62>
lea    0xe23(%rip),%rdi
call   1090 <err@plt>
movl   $0x1,-0x44(%rbp)
cmpl   $0x2710,-0x44(%rbp)
jge    129c <main+0x11c>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
cmp    $0x0,%rax
je     121e <main+0x9e>
lea    0xdf9(%rip),%rdi
call   1090 <err@plt>
jmp    1289 <main+0x109>
imul   $0xf4240,-0x40(%rbp),%eax
cltq
add    -0x38(%rbp),%rax
imul   $0xf4240,-0x20(%rbp),%ecx
movslq %ecx,%rcx
add    -0x18(%rbp),%rcx
imul   $0x3e8,-0x44(%rbp),%edx
movslq %edx,%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
je     1284 <main+0x104>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x44(%rbp),%r8d
mov    -0x40(%rbp),%r9d
mov    -0x38(%rbp),%rax
lea    0xdaa(%rip),%rsi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1289 <main+0x109>
jmp    128e <main+0x10e>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11e9 <main+0x69>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
cmp    -0x40(%rbp),%eax
je     12cc <main+0x14c>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    0xd82(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
lea    0xd7d(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movq   $0x0,0x40(%rsp)
movq   $0x0,0x28(%rsp)
movaps %xmm0,0x10(%rsp)
movq   $0x0,0x20(%rsp)
lea    0x30(%rsp),%rdi
lea    0x28(%rsp),%rsi
call   1050 <gettimeofday@plt>
test   %rax,%rax
je     11c6 <main+0x56>
lea    0xe3f(%rip),%rdi
call   1080 <err@plt>
movslq 0x30(%rsp),%r14
imul   $0xf4240,%r14,%rax
mov    0x38(%rsp),%r15
lea    (%r15,%rax,1),%rbp
add    $0x3e8,%rbp
mov    $0xffffffffffffd8f1,%rbx
lea    0x10(%rsp),%r12
lea    0xe18(%rip),%r13
jmp    1214 <main+0xa4>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1080 <err@plt>
add    $0x3e8,%rbp
inc    %rbx
je     126d <main+0xfd>
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
test   %rax,%rax
jne    1200 <main+0x90>
movslq 0x10(%rsp),%r9
imul   $0xf4240,%r9,%rcx
mov    0x18(%rsp),%rax
add    %rax,%rcx
cmp    %rcx,%rbp
je     1208 <main+0x98>
add    $0x2710,%ebx
mov    0x2d97(%rip),%rcx
mov    (%rcx),%edi
mov    %rax,(%rsp)
lea    0xdc6(%rip),%rsi
mov    %r14d,%edx
mov    %r15,%rcx
mov    %ebx,%r8d
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>
xor    %edi,%edi
call   1070 <time@plt>
cmp    0x10(%rsp),%eax
jne    128d <main+0x11d>
lea    0xdcf(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.timeval = type { i32, i64, i32, i32 }
%struct.timezone = type { i32, i32 }
@.str = [13 x i8] c"gettimeofday\00"
@.str.1 = [15 x i8] c"gettimeofday 1\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"t0 (%ld, %ld), i %d, t1 (%ld, %ld)\0A\00"
@.str.3 = [16 x i8] c"time != gettod\0A\00"
@.str.4 = [6 x i8] c"pass\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca %struct.timezone
%4 = alloca %struct.timeval
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast %struct.timeval* %2 to i8*
%7 = bitcast %struct.timezone* %3 to i8*
%8 = bitcast %struct.timeval* %4 to i8*
%9 = call i64 @gettimeofday(%struct.timeval* %2, %struct.timezone* %3)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @err(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
store i32 1, i32* %5
br label %14
14: ; preds = %57, %13
%15 = load i32, i32* %5
%16 = icmp slt i32 %15, 10000
br i1 %16, label %17, label %60
17: ; preds = %14
%18 = call i64 @gettimeofday(%struct.timeval* %4, %struct.timezone* null)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @err(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %56
22: ; preds = %17
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%24 = load i32, i32* %23
%25 = mul nsw i32 %24, 1000000
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%28 = load i64, i64* %27
%29 = add nsw i64 %26, %28
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%31 = load i32, i32* %30
%32 = mul nsw i32 %31, 1000000
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%35 = load i64, i64* %34
%36 = add nsw i64 %33, %35
%37 = load i32, i32* %5
%38 = mul nsw i32 %37, 1000
%39 = sext i32 %38 to i64
%40 = add nsw i64 %36, %39
%41 = icmp ne i64 %29, %40
br i1 %41, label %42, label %55
42: ; preds = %22
%43 = load i32, i32* @stderr
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%47 = load i64, i64* %46
%48 = load i32, i32* %5
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%50 = load i32, i32* %49
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%52 = load i64, i64* %51
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %45, i64 %47, i32 %48, i32 %50, i64 %52)
%54 = call i32 (...) @abort()
unreachable
55: ; preds = %22
br label %56
56: ; preds = %55, %20
br label %57
57: ; preds = %56
%58 = load i32, i32* %5
%59 = add nsw i32 %58, 1
store i32 %59, i32* %5
br label %14
60: ; preds = %14
%61 = call i32 @time(i32* null)
%62 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%63 = load i32, i32* %62
%64 = icmp ne i32 %61, %63
br i1 %64, label %65, label %69
65: ; preds = %60
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%68 = call i32 (...) @abort()
unreachable
69: ; preds = %60
%70 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%71 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64, i32, i32 }
%struct.timezone = type { i32, i32 }
@.str = [13 x i8] c"gettimeofday\00"
@.str.1 = [15 x i8] c"gettimeofday 1\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"t0 (%ld, %ld), i %d, t1 (%ld, %ld)\0A\00"
@.str.3 = [16 x i8] c"time != gettod\0A\00"
@str = [5 x i8] c"pass\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.timezone*
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %1 to i8*
%6 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%7 = bitcast %struct.timeval* %4 to i8*
%8 = call i64 @gettimeofday(%struct.timeval* %1, %struct.timezone* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = tail call i32 @err(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%16 = load i32, i32* %15
%17 = mul nsw i32 %16, 1000000
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%20 = load i64, i64* %19
br label %21
21: ; preds = %12, %42
%22 = phi i64 [ 1, %12 ], [ %43, %42 ]
%23 = call i64 @gettimeofday(%struct.timeval* %4, %struct.timezone* null)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = tail call i32 @err(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %42
27: ; preds = %21
%28 = load i32, i32* %13
%29 = mul nsw i32 %28, 1000000
%30 = sext i32 %29 to i64
%31 = load i64, i64* %14
%32 = add nsw i64 %31, %30
%33 = mul nuw nsw i64 %22, 1000
%34 = add i64 %20, %33
%35 = add i64 %34, %18
%36 = icmp eq i64 %32, %35
br i1 %36, label %42, label %37
37: ; preds = %27
%38 = trunc i64 %22 to i32
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %16, i64 %20, i32 %38, i32 %28, i64 %31)
%41 = tail call i32 (...) @abort()
unreachable
42: ; preds = %25, %27
%43 = add nuw nsw i64 %22, 1
%44 = icmp eq i64 %43, 10000
br i1 %44, label %45, label %21
45: ; preds = %42
%46 = tail call i32 @time(i32* null)
%47 = load i32, i32* %13
%48 = icmp eq i32 %46, %47
br i1 %48, label %53, label %49
49: ; preds = %45
%50 = load i32, i32* @stderr
%51 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%52 = tail call i32 (...) @abort()
unreachable
53: ; preds = %45
%54 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%55 = tail call i32 @exit(i32 0)
unreachable
}