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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, long, unsigned int, long, unsigned int, ...);
int main() {
  unsigned cErrors = 0;
  struct timeval aTv[2];
  struct timeval *pCur = &aTv[0];
  struct timeval *pPrev = &aTv[1];
  struct timeval *pTmp;
  gettimeofday(pPrev, NULL);
  for (;;) {
    gettimeofday(pCur, NULL);
    if (pCur->tv_sec == pPrev->tv_sec && pCur->tv_usec < pPrev->tv_usec) {
      printf("tv_usec in the past: %ld.%06u < %ld.%06u - %u usec\n",
             (long)pCur->tv_sec, (unsigned)pCur->tv_usec, (long)pPrev->tv_sec,
             (unsigned)pPrev->tv_usec,
             (unsigned)pPrev->tv_usec - (unsigned)pCur->tv_usec);
      cErrors++;
      if (cErrors > 1000)
        break;
    } else if (pCur->tv_sec < pPrev->tv_sec) {
      printf("tv_sec  in the past: %ld.%06u < %ld.%06u\n", (long)pCur->tv_sec,
             (unsigned)pCur->tv_usec, (long)pPrev->tv_sec,
             (unsigned)pPrev->tv_usec);
      cErrors++;
      if (cErrors > 1000)
        break;
    } else {
      pTmp = pPrev;
      pPrev = pCur;
      pCur = pTmp;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%rcx
cmp    (%rcx),%rax
jne    11f5 <main+0xd5>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x40(%rbp),%rcx
cmp    0x8(%rcx),%rax
jge    11f5 <main+0xd5>
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%edx
mov    -0x40(%rbp),%rax
mov    (%rax),%rcx
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%r8d
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%r9d
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
sub    %eax,%r9d
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jbe    11f0 <main+0xd0>
jmp    127c <main+0x15c>
jmp    1277 <main+0x157>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    -0x40(%rbp),%rcx
cmp    (%rcx),%rax
jge    125a <main+0x13a>
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%edx
mov    -0x40(%rbp),%rax
mov    (%rax),%rcx
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rax
mov    %eax,%r8d
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jbe    1255 <main+0x135>
jmp    127c <main+0x15c>
jmp    1272 <main+0x152>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1277 <main+0x157>
jmp    1157 <main+0x37>
mov    $0x1,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsp,%r13
lea    0x10(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0xeb9(%rip),%r14
lea    0xee6(%rip),%r15
xor    %ebp,%ebp
mov    %r13,%rbx
jmp    117e <main+0x5e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r8d,%r9d
sub    %edx,%r9d
mov    %r14,%rdi
mov    %rsi,%rcx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    $0x3e8,%ebp
ja     11db <main+0xbb>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    (%rbx),%rsi
mov    (%r12),%rcx
cmp    %rcx,%rsi
jne    11a2 <main+0x82>
mov    0x8(%rbx),%rdx
mov    0x8(%r12),%r8
cmp    %r8,%rdx
jl     1160 <main+0x40>
cmp    %rcx,%rsi
jge    11d0 <main+0xb0>
mov    0x8(%rbx),%edx
mov    0x8(%r12),%r8d
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%ebp
cmp    $0x3e9,%ebp
jb     117e <main+0x5e>
jmp    11db <main+0xbb>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%r13
mov    %rbx,%r12
jmp    1150 <main+0x30>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [52 x i8] c"tv_usec in the past: %ld.%06u < %ld.%06u - %u usec\0A\00"
@.str.1 = [42 x i8] c"tv_sec in the past: %ld.%06u < %ld.%06u\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [2 x %struct.timeval]
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval*
%6 = alloca %struct.timeval*
store i32 0, i32* %1
store i32 0, i32* %2
%7 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %3, i64 0, i64 0
store %struct.timeval* %7, %struct.timeval** %4
%8 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %3, i64 0, i64 1
store %struct.timeval* %8, %struct.timeval** %5
%9 = load %struct.timeval*, %struct.timeval** %5
%10 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
br label %11
11: ; preds = %95, %0
%12 = load %struct.timeval*, %struct.timeval** %4
%13 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%14 = load %struct.timeval*, %struct.timeval** %4
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load %struct.timeval*, %struct.timeval** %5
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = icmp eq i64 %16, %19
br i1 %20, label %21, label %60
21: ; preds = %11
%22 = load %struct.timeval*, %struct.timeval** %4
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 1
%24 = load i64, i64* %23
%25 = load %struct.timeval*, %struct.timeval** %5
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %25, i32 0, i32 1
%27 = load i64, i64* %26
%28 = icmp slt i64 %24, %27
br i1 %28, label %29, label %60
29: ; preds = %21
%30 = load %struct.timeval*, %struct.timeval** %4
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %30, i32 0, i32 0
%32 = load i64, i64* %31
%33 = load %struct.timeval*, %struct.timeval** %4
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %33, i32 0, i32 1
%35 = load i64, i64* %34
%36 = trunc i64 %35 to i32
%37 = load %struct.timeval*, %struct.timeval** %5
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %37, i32 0, i32 0
%39 = load i64, i64* %38
%40 = load %struct.timeval*, %struct.timeval** %5
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %40, i32 0, i32 1
%42 = load i64, i64* %41
%43 = trunc i64 %42 to i32
%44 = load %struct.timeval*, %struct.timeval** %5
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %44, i32 0, i32 1
%46 = load i64, i64* %45
%47 = trunc i64 %46 to i32
%48 = load %struct.timeval*, %struct.timeval** %4
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %48, i32 0, i32 1
%50 = load i64, i64* %49
%51 = trunc i64 %50 to i32
%52 = sub i32 %47, %51
%53 = call i32 (i8*, i64, i32, i64, i32, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i64 %32, i32 %36, i64 %39, i32 %43, i32 %52)
%54 = load i32, i32* %2
%55 = add i32 %54, 1
store i32 %55, i32* %2
%56 = load i32, i32* %2
%57 = icmp ugt i32 %56, 1000
br i1 %57, label %58, label %59
58: ; preds = %29
br label %96
59: ; preds = %29
br label %95
60: ; preds = %21, %11
%61 = load %struct.timeval*, %struct.timeval** %4
%62 = getelementptr inbounds %struct.timeval, %struct.timeval* %61, i32 0, i32 0
%63 = load i64, i64* %62
%64 = load %struct.timeval*, %struct.timeval** %5
%65 = getelementptr inbounds %struct.timeval, %struct.timeval* %64, i32 0, i32 0
%66 = load i64, i64* %65
%67 = icmp slt i64 %63, %66
br i1 %67, label %68, label %90
68: ; preds = %60
%69 = load %struct.timeval*, %struct.timeval** %4
%70 = getelementptr inbounds %struct.timeval, %struct.timeval* %69, i32 0, i32 0
%71 = load i64, i64* %70
%72 = load %struct.timeval*, %struct.timeval** %4
%73 = getelementptr inbounds %struct.timeval, %struct.timeval* %72, i32 0, i32 1
%74 = load i64, i64* %73
%75 = trunc i64 %74 to i32
%76 = load %struct.timeval*, %struct.timeval** %5
%77 = getelementptr inbounds %struct.timeval, %struct.timeval* %76, i32 0, i32 0
%78 = load i64, i64* %77
%79 = load %struct.timeval*, %struct.timeval** %5
%80 = getelementptr inbounds %struct.timeval, %struct.timeval* %79, i32 0, i32 1
%81 = load i64, i64* %80
%82 = trunc i64 %81 to i32
%83 = call i32 (i8*, i64, i32, i64, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 %71, i32 %75, i64 %78, i32 %82)
%84 = load i32, i32* %2
%85 = add i32 %84, 1
store i32 %85, i32* %2
%86 = load i32, i32* %2
%87 = icmp ugt i32 %86, 1000
br i1 %87, label %88, label %89
88: ; preds = %68
br label %96
89: ; preds = %68
br label %94
90: ; preds = %60
%91 = load %struct.timeval*, %struct.timeval** %5
store %struct.timeval* %91, %struct.timeval** %6
%92 = load %struct.timeval*, %struct.timeval** %4
store %struct.timeval* %92, %struct.timeval** %5
%93 = load %struct.timeval*, %struct.timeval** %6
store %struct.timeval* %93, %struct.timeval** %4
br label %94
94: ; preds = %90, %89
br label %95
95: ; preds = %94, %59
br label %11
96: ; preds = %88, %58
ret i32 1
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [52 x i8] c"tv_usec in the past: %ld.%06u < %ld.%06u - %u usec\0A\00"
@.str.1 = [42 x i8] c"tv_sec in the past: %ld.%06u < %ld.%06u\0A\00"
define i32 @main() {
%1 = alloca [2 x %struct.timeval]
%2 = bitcast [2 x %struct.timeval]* %1 to i8*
%3 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %1, i64 0, i64 0
%4 = getelementptr inbounds [2 x %struct.timeval], [2 x %struct.timeval]* %1, i64 0, i64 1
%5 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
br label %6
6: ; preds = %33, %0
%7 = phi %struct.timeval* [ %3, %0 ], [ %8, %33 ]
%8 = phi %struct.timeval* [ %4, %0 ], [ %7, %33 ]
%9 = phi i32 [ 0, %0 ], [ %17, %33 ]
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 0
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 1
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 1
br label %16
16: ; preds = %43, %6
%17 = phi i32 [ %9, %6 ], [ %44, %43 ]
%18 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%19 = load i64, i64* %10
%20 = load i64, i64* %11
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %33
22: ; preds = %16
%23 = load i64, i64* %12
%24 = load i64, i64* %13
%25 = icmp slt i64 %23, %24
br i1 %25, label %26, label %33
26: ; preds = %22
%27 = trunc i64 %23 to i32
%28 = trunc i64 %24 to i32
%29 = sub i32 %28, %27
%30 = tail call i32 (i8*, i64, i32, i64, i32, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0), i64 %19, i32 %27, i64 %19, i32 %28, i32 %29)
%31 = add i32 %17, 1
%32 = icmp ugt i32 %31, 1000
br i1 %32, label %45, label %43
33: ; preds = %22, %16
%34 = icmp slt i64 %19, %20
br i1 %34, label %35, label %6
35: ; preds = %33
%36 = load i64, i64* %14
%37 = trunc i64 %36 to i32
%38 = load i64, i64* %15
%39 = trunc i64 %38 to i32
%40 = tail call i32 (i8*, i64, i32, i64, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 %19, i32 %37, i64 %20, i32 %39)
%41 = add i32 %17, 1
%42 = icmp ugt i32 %41, 1000
br i1 %42, label %45, label %43
43: ; preds = %35, %26
%44 = phi i32 [ %31, %26 ], [ %41, %35 ]
br label %16
45: ; preds = %35, %26
ret i32 1
}