#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 {
  long long tv_sec;
  long long tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int main() {
  struct timeval tv1;
  gettimeofday(&tv1, NULL);
  for (int i = 0; i < 1000; i++) {
  }
  struct timeval tv2;
  gettimeofday(&tv2, NULL);
  long long s1 = tv1.tv_sec;
  long long us1 = tv1.tv_usec;
  long long s2 = tv2.tv_sec;
  long long us2 = tv2.tv_usec;
  assert(s1 <= s2);
  if (s1 == s2) {
    assert(us1 < us2);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3e8,-0x1c(%rbp)
jge    1163 <main+0x43>
jmp    1155 <main+0x35>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1143 <main+0x23>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x48(%rbp),%rax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x38(%rbp),%rax
cmp    -0x48(%rbp),%rax
jne    11c8 <main+0xa8>
mov    -0x40(%rbp),%rax
cmp    -0x50(%rbp),%rax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x18(%rsp),%r12
mov    0x20(%rsp),%r14
mov    0x10(%rsp),%r15
mov    0x8(%rsp),%rbx
xor    %edi,%edi
cmp    %rbx,%r12
setle  %dil
call   1040 <assert@plt>
cmp    %rbx,%r12
jne    1178 <main+0x58>
xor    %edi,%edi
cmp    %r15,%r14
setl   %dil
call   1040 <assert@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %1
%9 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
store i32 0, i32* %3
br label %10
10: ; preds = %14, %0
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 1000
br i1 %12, label %13, label %17
13: ; preds = %10
br label %14
14: ; preds = %13
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %10
17: ; preds = %10
%18 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%20 = load i64, i64* %19
store i64 %20, i64* %5
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%22 = load i64, i64* %21
store i64 %22, i64* %6
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%24 = load i64, i64* %23
store i64 %24, i64* %7
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%26 = load i64, i64* %25
store i64 %26, i64* %8
%27 = load i64, i64* %5
%28 = load i64, i64* %7
%29 = icmp sle i64 %27, %28
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i64, i64* %5
%33 = load i64, i64* %7
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %41
35: ; preds = %17
%36 = load i64, i64* %6
%37 = load i64, i64* %8
%38 = icmp slt i64 %36, %37
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
br label %41
41: ; preds = %35, %17
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%5 = bitcast %struct.timeval* %2 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%8 = load i64, i64* %7
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%12 = load i64, i64* %11
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%14 = load i64, i64* %13
%15 = icmp sle i64 %8, %12
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = icmp eq i64 %8, %12
br i1 %18, label %19, label %23
19: ; preds = %0
%20 = icmp slt i64 %10, %14
%21 = zext i1 %20 to i32
%22 = tail call i32 @assert(i32 %21)
br label %23
23: ; preds = %19, %0
ret i32 0
}