#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 {
  unsigned long tv_sec;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sleep(int);
unsigned long timeUp(unsigned long maxTimeOut) {
  struct timeval tNow = {0};
  struct timeval tStart = {0};
  unsigned long timeSpan = 0;
  gettimeofday(&tStart, NULL);
  while (timeSpan < maxTimeOut) {
    sleep(1);
    gettimeofday(&tNow, NULL);
    timeSpan = tNow.tv_sec - tStart.tv_sec;
  }
  return 0;
}


x86 assembly (clang, -O0):
<timeUp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
movq   $0x0,-0x30(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x30(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11a7 <timeUp+0x77>
mov    $0x1,%edi
call   1050 <sleep@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1171 <timeUp+0x41>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeUp>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r15
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %r15,%r15
je     1171 <timeUp+0x51>
mov    (%rsp),%rbx
lea    0x10(%rsp),%r14
mov    $0x1,%edi
call   1040 <sleep@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x10(%rsp),%rax
sub    %rbx,%rax
cmp    %r15,%rax
jb     1150 <timeUp+0x30>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
define i64 @timeUp(i64 %0) {
%2 = alloca i64
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca i64
store i64 %0, i64* %2
%6 = bitcast %struct.timeval* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
store i64 0, i64* %5
%8 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
br label %9
9: ; preds = %13, %1
%10 = load i64, i64* %5
%11 = load i64, i64* %2
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = call i32 @sleep(i32 1)
%15 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%17 = load i64, i64* %16
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%19 = load i64, i64* %18
%20 = sub i64 %17, %19
store i64 %20, i64* %5
br label %9
21: ; preds = %9
ret i64 0
}

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