#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;
};

/* Variables and functions */
int /*<<< orphan*/ getenv(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int main() {
  while (1) {
    struct timeval tv;
    if (!getenv("NO_GETTIMEOFDAY")) {
      gettimeofday(&tv, NULL);
    }
    printf("TIME (gettimeofday): %d\n", (int)tv.tv_sec);
    sleep(2);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%eax
jne    1171 <main+0x31>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1060 <sleep@plt>
jmp    114f <main+0xf>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb0(%rip),%r15
lea    0x8(%rsp),%r14
lea    0xeb4(%rip),%rbx
jmp    1172 <main+0x32>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   1060 <sleep@plt>
mov    %r15,%rdi
call   1030 <getenv@plt>
test   %eax,%eax
jne    1160 <main+0x20>
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x8(%rsp),%rsi
jmp    1160 <main+0x20>

LLVM IR (-O0):
%struct.timeval = type { i64 }
@.str = [16 x i8] c"NO_GETTIMEOFDAY\00"
@.str.1 = [25 x i8] c"TIME (gettimeofday): %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timeval
store i32 0, i32* %1
br label %3
3: ; preds = %0, %8
%4 = call i32 @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%5 = icmp ne i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
br label %8
8: ; preds = %6, %3
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%10 = load i64, i64* %9
%11 = trunc i64 %10 to i32
%12 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = call i32 @sleep(i32 2)
br label %3
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
@.str = [16 x i8] c"NO_GETTIMEOFDAY\00"
@.str.1 = [25 x i8] c"TIME (gettimeofday): %d\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
br label %4
4: ; preds = %0, %10
%5 = tail call i32 @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%9 = load i64, i64* %3
br label %10
10: ; preds = %7, %4
%11 = phi i64 [ %9, %7 ], [ undef, %4 ]
%12 = trunc i64 %11 to i32
%13 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = tail call i32 @sleep(i32 2)
br label %4
}