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

/* Variables and functions */
int errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int gettimeofday(struct timeval *, struct timezone *);
int handle_zng(int);
int /*<<< orphan*/ printf(char *, ...);
int gettimeofday_test(struct timeval *tv, struct timezone *tz) {
  int ret, save_errno;
  int passed;
  printf("gettimeofday(): tv=0x%p, tz=0x%p\n", tv, tz);
  fflush(NULL);
  passed = handle_zng(ret = gettimeofday(tv, tz));
  save_errno = errno;
  switch (passed) {
  case -1:
    printf("\t\tret = %d\n", ret);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case 0:
    printf("\t\ttv_sec = %ld\n", tv->tv_sec);
    printf("\t\ttv_usec = %ld\n", tv->tv_usec);
    printf("\t\ttz_minuteswest = %d\n", tz->tz_minuteswest);
    printf("\t\ttz_dsttime = %d\n", tz->tz_dsttime);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case -2:
    printf("\tFailed Phase 1: returned undefined value! "
           "ret = %d\n",
           ret);
    fflush(NULL);
    break;
  default:
    printf("Internal syscalltester error: passed = %d\n", passed);
    fflush(NULL);
    break;
  }
  errno = save_errno;
  return ret;
}


x86 assembly (clang, -O0):
<gettimeofday_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xea1(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x24(%rbp)
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,%edi
call   1060 <fflush@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <gettimeofday@plt>
mov    %eax,%edi
mov    %edi,-0x14(%rbp)
call   1030 <handle_zng@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0xfffffffe,%eax
je     1269 <gettimeofday_test+0x129>
jmp    11ad <gettimeofday_test+0x6d>
mov    -0x20(%rbp),%eax
sub    $0xffffffff,%eax
je     11ce <gettimeofday_test+0x8e>
jmp    11be <gettimeofday_test+0x7e>
mov    -0x20(%rbp),%eax
test   %eax,%eax
je     11fb <gettimeofday_test+0xbb>
jmp    1288 <gettimeofday_test+0x148>
mov    -0x14(%rbp),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fflush@plt>
jmp    12a2 <gettimeofday_test+0x162>
mov    -0x8(%rbp),%rax
mov    (%rax),%esi
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fflush@plt>
jmp    12a2 <gettimeofday_test+0x162>
mov    -0x14(%rbp),%esi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fflush@plt>
jmp    12a2 <gettimeofday_test+0x162>
mov    -0x1c(%rbp),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fflush@plt>
mov    -0x18(%rbp),%ecx
mov    0x2d34(%rip),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettimeofday_test>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe9b(%rip),%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <fflush@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <gettimeofday@plt>
mov    %eax,%r14d
mov    %eax,%edi
call   1040 <handle_zng@plt>
mov    0x2e4b(%rip),%r15
mov    (%r15),%r12d
cmp    $0xfffffffe,%eax
je     11b2 <gettimeofday_test+0x62>
test   %eax,%eax
je     11be <gettimeofday_test+0x6e>
cmp    $0xffffffff,%eax
jne    120f <gettimeofday_test+0xbf>
lea    0xe75(%rip),%rdi
mov    %r14d,%esi
jmp    11fa <gettimeofday_test+0xaa>
lea    0xec0(%rip),%rdi
mov    %r14d,%esi
jmp    1218 <gettimeofday_test+0xc8>
mov    0x0(%rbp),%esi
lea    0xe66(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbp),%esi
lea    0xe65(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%esi
lea    0xe66(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x4(%rbx),%esi
lea    0xe6c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
jmp    121f <gettimeofday_test+0xcf>
lea    0xe98(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1070 <fflush@plt>
mov    %r12d,(%r15)
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32, i32 }
@.str = [34 x i8] c"gettimeofday(): tv=0x%p, tz=0x%p\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.2 = [20 x i8] c"\09Succeeded Phase 1\0A\00"
@.str.3 = [16 x i8] c"\09\09tv_sec = %ld\0A\00"
@.str.4 = [17 x i8] c"\09\09tv_usec = %ld\0A\00"
@.str.5 = [23 x i8] c"\09\09tz_minuteswest = %d\0A\00"
@.str.6 = [19 x i8] c"\09\09tz_dsttime = %d\0A\00"
@.str.7 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.8 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
define i32 @gettimeofday_test(%struct.timeval* %0, %struct.timezone* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timezone*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timezone* %1, %struct.timezone** %4
%8 = load %struct.timeval*, %struct.timeval** %3
%9 = load %struct.timezone*, %struct.timezone** %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), %struct.timeval* %8, %struct.timezone* %9)
%11 = call i32 @fflush(i32* null)
%12 = load %struct.timeval*, %struct.timeval** %3
%13 = load %struct.timezone*, %struct.timezone** %4
%14 = call i32 @gettimeofday(%struct.timeval* %12, %struct.timezone* %13)
store i32 %14, i32* %5
%15 = call i32 @handle_zng(i32 %14)
store i32 %15, i32* %7
%16 = load i32, i32* @errno
store i32 %16, i32* %6
%17 = load i32, i32* %7
switch i32 %17, label %46 [
i32 -1, label %18
i32 0, label %23
i32 -2, label %42
]
18: ; preds = %2
%19 = load i32, i32* %5
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @fflush(i32* null)
br label %50
23: ; preds = %2
%24 = load %struct.timeval*, %struct.timeval** %3
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = load %struct.timeval*, %struct.timeval** %3
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %30)
%32 = load %struct.timezone*, %struct.timezone** %4
%33 = getelementptr inbounds %struct.timezone, %struct.timezone* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %34)
%36 = load %struct.timezone*, %struct.timezone** %4
%37 = getelementptr inbounds %struct.timezone, %struct.timezone* %36, i32 0, i32 1
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @fflush(i32* null)
br label %50
42: ; preds = %2
%43 = load i32, i32* %5
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), i32 %43)
%45 = call i32 @fflush(i32* null)
br label %50
46: ; preds = %2
%47 = load i32, i32* %7
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i32 %47)
%49 = call i32 @fflush(i32* null)
br label %50
50: ; preds = %46, %42, %23, %18
%51 = load i32, i32* %6
store i32 %51, i32* @errno
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32, i32 }
@.str = [34 x i8] c"gettimeofday(): tv=0x%p, tz=0x%p\0A\00"
@errno = global i32 0
@.str.1 = [12 x i8] c"\09\09ret = %d\0A\00"
@.str.3 = [16 x i8] c"\09\09tv_sec = %ld\0A\00"
@.str.4 = [17 x i8] c"\09\09tv_usec = %ld\0A\00"
@.str.5 = [23 x i8] c"\09\09tz_minuteswest = %d\0A\00"
@.str.6 = [19 x i8] c"\09\09tz_dsttime = %d\0A\00"
@.str.7 = [53 x i8] c"\09Failed Phase 1: returned undefined value! ret = %d\0A\00"
@.str.8 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
@str.9 = [19 x i8] c"\09Succeeded Phase 1\00"
define i32 @gettimeofday_test(%struct.timeval* %0, %struct.timezone* %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), %struct.timeval* %0, %struct.timezone* %1)
%4 = tail call i32 @fflush(i32* null)
%5 = tail call i32 @gettimeofday(%struct.timeval* %0, %struct.timezone* %1)
%6 = tail call i32 @handle_zng(i32 %5)
%7 = load i32, i32* @errno
switch i32 %6, label %27 [
i32 -1, label %8
i32 0, label %11
i32 -2, label %25
]
8: ; preds = %2
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.9, i64 0, i64 0))
br label %29
11: ; preds = %2
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%13 = load i32, i32* %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%16 = load i32, i32* %15
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds %struct.timezone, %struct.timezone* %1, i64 0, i32 0
%19 = load i32, i32* %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds %struct.timezone, %struct.timezone* %1, i64 0, i32 1
%22 = load i32, i32* %21
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %22)
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.9, i64 0, i64 0))
br label %29
25: ; preds = %2
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), i32 %5)
br label %29
27: ; preds = %2
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.8, i64 0, i64 0), i32 %6)
br label %29
29: ; preds = %27, %25, %11, %8
%30 = tail call i32 @fflush(i32* null)
store i32 %7, i32* @errno
ret i32 %5
}