#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 {
  scalar_t__ tz_minuteswest;
  scalar_t__ tz_dsttime;
};
struct timeval {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char const *, ...);
double tv_diff(struct timeval const *, struct timeval const *);
int check_gtod(const struct timeval *tv_sys1, const struct timeval *tv_sys2,
               const struct timezone *tz_sys, const char *which,
               const struct timeval *tv_other,
               const struct timezone *tz_other) {
  int nerrs = 0;
  double d1, d2;
  if (tz_other && (tz_sys->tz_minuteswest != tz_other->tz_minuteswest ||
                   tz_sys->tz_dsttime != tz_other->tz_dsttime)) {
    printf("[FAIL] %s tz mismatch\n", which);
    nerrs++;
  }
  d1 = tv_diff(tv_other, tv_sys1);
  d2 = tv_diff(tv_sys2, tv_other);
  printf("\t%s time offsets: %lf %lf\n", which, d1, d2);
  if (d1 < 0 || d2 < 0) {
    printf("[FAIL]\t%s time was inconsistent with the syscall\n", which);
    nerrs++;
  } else {
    printf("[OK]\t%s gettimeofday()'s timeval was okay\n", which);
  }
  return nerrs;
}


x86 assembly (clang, -O0):
<check_gtod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1197 <check_gtod+0x77>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x30(%rbp),%rcx
cmp    (%rcx),%rax
jne    117c <check_gtod+0x5c>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x30(%rbp),%rcx
cmp    0x8(%rcx),%rax
je     1197 <check_gtod+0x77>
mov    -0x20(%rbp),%rsi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <tv_diff@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <tv_diff@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x20(%rbp),%rsi
movsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
lea    0xe47(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
ucomisd -0x40(%rbp),%xmm0
ja     11f3 <check_gtod+0xd3>
xorps  %xmm0,%xmm0
ucomisd -0x48(%rbp),%xmm0
jbe    1213 <check_gtod+0xf3>
mov    -0x20(%rbp),%rsi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1225 <check_gtod+0x105>
mov    -0x20(%rbp),%rsi
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_gtod>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%rbp
mov    %rcx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %r14d,%r14d
test   %r9,%r9
je     1169 <check_gtod+0x49>
mov    (%rdx),%rax
cmp    (%r9),%rax
jne    1152 <check_gtod+0x32>
mov    0x8(%rdx),%rax
cmp    0x8(%r9),%rax
je     1169 <check_gtod+0x49>
lea    0xea7(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <tv_diff@plt>
movsd  %xmm0,(%rsp)
mov    %r15,%rdi
mov    %rbp,%rsi
call   1030 <tv_diff@plt>
movaps %xmm0,%xmm1
lea    0xe89(%rip),%rdi
mov    %r12,%rsi
movsd  (%rsp),%xmm0
movsd  %xmm1,0x8(%rsp)
mov    $0x2,%al
call   1040 <printf@plt>
xorpd  %xmm0,%xmm0
ucomisd (%rsp),%xmm0
ja     11c9 <check_gtod+0xa9>
ucomisd 0x8(%rsp),%xmm0
ja     11c9 <check_gtod+0xa9>
lea    0xea7(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11de <check_gtod+0xbe>
lea    0xe62(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.timezone = type { i64, i64 }
@.str = [23 x i8] c"[FAIL] %s tz mismatch\0A\00"
@.str.1 = [27 x i8] c"\09%s time offsets: %lf %lf\0A\00"
@.str.2 = [50 x i8] c"[FAIL]\09%s time was inconsistent with the syscall\0A\00"
@.str.3 = [43 x i8] c"[OK]\09%s gettimeofday()'s timeval was okay\0A\00"
define i32 @check_gtod(%struct.timeval* %0, %struct.timeval* %1, %struct.timezone* %2, i8* %3, %struct.timeval* %4, %struct.timezone* %5) {
%7 = alloca %struct.timeval*
%8 = alloca %struct.timeval*
%9 = alloca %struct.timezone*
%10 = alloca i8*
%11 = alloca %struct.timeval*
%12 = alloca %struct.timezone*
%13 = alloca i32
%14 = alloca double
%15 = alloca double
store %struct.timeval* %0, %struct.timeval** %7
store %struct.timeval* %1, %struct.timeval** %8
store %struct.timezone* %2, %struct.timezone** %9
store i8* %3, i8** %10
store %struct.timeval* %4, %struct.timeval** %11
store %struct.timezone* %5, %struct.timezone** %12
store i32 0, i32* %13
%16 = load %struct.timezone*, %struct.timezone** %12
%17 = icmp ne %struct.timezone* %16, null
br i1 %17, label %18, label %39
18: ; preds = %6
%19 = load %struct.timezone*, %struct.timezone** %9
%20 = getelementptr inbounds %struct.timezone, %struct.timezone* %19, i32 0, i32 0
%21 = load i64, i64* %20
%22 = load %struct.timezone*, %struct.timezone** %12
%23 = getelementptr inbounds %struct.timezone, %struct.timezone* %22, i32 0, i32 0
%24 = load i64, i64* %23
%25 = icmp ne i64 %21, %24
br i1 %25, label %34, label %26
26: ; preds = %18
%27 = load %struct.timezone*, %struct.timezone** %9
%28 = getelementptr inbounds %struct.timezone, %struct.timezone* %27, i32 0, i32 1
%29 = load i64, i64* %28
%30 = load %struct.timezone*, %struct.timezone** %12
%31 = getelementptr inbounds %struct.timezone, %struct.timezone* %30, i32 0, i32 1
%32 = load i64, i64* %31
%33 = icmp ne i64 %29, %32
br i1 %33, label %34, label %39
34: ; preds = %26, %18
%35 = load i8*, i8** %10
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %35)
%37 = load i32, i32* %13
%38 = add nsw i32 %37, 1
store i32 %38, i32* %13
br label %39
39: ; preds = %34, %26, %6
%40 = load %struct.timeval*, %struct.timeval** %11
%41 = load %struct.timeval*, %struct.timeval** %7
%42 = call double @tv_diff(%struct.timeval* %40, %struct.timeval* %41)
store double %42, double* %14
%43 = load %struct.timeval*, %struct.timeval** %8
%44 = load %struct.timeval*, %struct.timeval** %11
%45 = call double @tv_diff(%struct.timeval* %43, %struct.timeval* %44)
store double %45, double* %15
%46 = load i8*, i8** %10
%47 = load double, double* %14
%48 = load double, double* %15
%49 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %46, double %47, double %48)
%50 = load double, double* %14
%51 = fcmp olt double %50, 0.000000e+00
br i1 %51, label %55, label %52
52: ; preds = %39
%53 = load double, double* %15
%54 = fcmp olt double %53, 0.000000e+00
br i1 %54, label %55, label %60
55: ; preds = %52, %39
%56 = load i8*, i8** %10
%57 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* %56)
%58 = load i32, i32* %13
%59 = add nsw i32 %58, 1
store i32 %59, i32* %13
br label %63
60: ; preds = %52
%61 = load i8*, i8** %10
%62 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %60, %55
%64 = load i32, i32* %13
ret i32 %64
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.timezone = type { i64, i64 }
@.str = [23 x i8] c"[FAIL] %s tz mismatch\0A\00"
@.str.1 = [27 x i8] c"\09%s time offsets: %lf %lf\0A\00"
@.str.2 = [50 x i8] c"[FAIL]\09%s time was inconsistent with the syscall\0A\00"
@.str.3 = [43 x i8] c"[OK]\09%s gettimeofday()'s timeval was okay\0A\00"
define i32 @check_gtod(%struct.timeval* %0, %struct.timeval* %1, %struct.timezone* nocapture %2, i8* %3, %struct.timeval* %4, %struct.timezone* %5) {
%7 = icmp eq %struct.timezone* %5, null
br i1 %7, label %22, label %8
8: ; preds = %6
%9 = getelementptr inbounds %struct.timezone, %struct.timezone* %2, i64 0, i32 0
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.timezone, %struct.timezone* %5, i64 0, i32 0
%12 = load i64, i64* %11
%13 = icmp eq i64 %10, %12
br i1 %13, label %14, label %20
14: ; preds = %8
%15 = getelementptr inbounds %struct.timezone, %struct.timezone* %2, i64 0, i32 1
%16 = load i64, i64* %15
%17 = getelementptr inbounds %struct.timezone, %struct.timezone* %5, i64 0, i32 1
%18 = load i64, i64* %17
%19 = icmp eq i64 %16, %18
br i1 %19, label %22, label %20
20: ; preds = %14, %8
%21 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %22
22: ; preds = %20, %14, %6
%23 = phi i32 [ 1, %20 ], [ 0, %14 ], [ 0, %6 ]
%24 = tail call double @tv_diff(%struct.timeval* %4, %struct.timeval* %0)
%25 = tail call double @tv_diff(%struct.timeval* %1, %struct.timeval* %4)
%26 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %3, double %24, double %25)
%27 = fcmp olt double %24, 0.000000e+00
%28 = fcmp olt double %25, 0.000000e+00
%29 = or i1 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%32 = add nuw nsw i32 %23, 1
br label %35
33: ; preds = %22
%34 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i8* %3)
br label %35
35: ; preds = %33, %30
%36 = phi i32 [ %32, %30 ], [ %23, %33 ]
ret i32 %36
}