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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
void timing_uPause(int usecs) {
  struct timeval current_time, delay_time, wait_time;
  gettimeofday(&current_time, NULL);
  delay_time.tv_sec = 0;
  delay_time.tv_usec = usecs;
  do {
    (&wait_time)->tv_sec = (&current_time)->tv_sec + (&delay_time)->tv_sec;
    (&wait_time)->tv_usec = (&current_time)->tv_usec + (&delay_time)->tv_usec;
    if ((&wait_time)->tv_usec >= 1000000) {
      ++(&wait_time)->tv_sec;
      (&wait_time)->tv_usec -= 1000000;
    }
  } while (0);
  do {
    gettimeofday(&current_time, NULL);
  } while ((((&current_time)->tv_sec == (&wait_time)->tv_sec)
                ? ((&current_time)->tv_usec < (&wait_time)->tv_usec)
                : ((&current_time)->tv_sec < (&wait_time)->tv_sec)));
}


x86 assembly (clang, -O0):
<timing_uPause>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
cmpl   $0xf4240,-0x30(%rbp)
jl     116f <timing_uPause+0x5f>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%eax
sub    $0xf4240,%eax
mov    %eax,-0x30(%rbp)
jmp    1174 <timing_uPause+0x64>
jmp    1179 <timing_uPause+0x69>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    11aa <timing_uPause+0x9a>
mov    -0x10(%rbp),%eax
cmp    -0x30(%rbp),%eax
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
jmp    11bd <timing_uPause+0xad>
mov    -0x18(%rbp),%rax
cmp    -0x38(%rbp),%rax
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    $0x0,%eax
jne    1179 <timing_uPause+0x69>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timing_uPause>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r14d
lea    0x8(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x10(%rsp),%eax
lea    (%rax,%r14,1),%ecx
xor    %ebx,%ebx
cmp    $0xf4240,%ecx
setge  %bl
lea    -0xf4240(%rax,%r14,1),%ebp
ff
cmovl  %ecx,%ebp
add    0x8(%rsp),%rbx
nop
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
xor    %eax,%eax
cmp    %ebp,0x10(%rsp)
setl   %al
xor    %ecx,%ecx
cmp    %rbx,0x8(%rsp)
setl   %cl
cmove  %eax,%ecx
test   %cl,%cl
jne    1150 <timing_uPause+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
define void @timing_uPause(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
store i32 %0, i32* %2
%6 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
store i64 0, i64* %7
%8 = load i32, i32* %2
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
store i32 %8, i32* %9
br label %10
10: ; preds = %1
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%12 = load i64, i64* %11
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%14 = load i64, i64* %13
%15 = add nsw i64 %12, %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i64 %15, i64* %16
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%20 = load i32, i32* %19
%21 = add nsw i32 %18, %20
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%24 = load i32, i32* %23
%25 = icmp sge i32 %24, 1000000
br i1 %25, label %26, label %33
26: ; preds = %10
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%28 = load i64, i64* %27
%29 = add nsw i64 %28, 1
store i64 %29, i64* %27
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%31 = load i32, i32* %30
%32 = sub nsw i32 %31, 1000000
store i32 %32, i32* %30
br label %33
33: ; preds = %26, %10
br label %34
34: ; preds = %33
br label %35
35: ; preds = %57, %34
%36 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
br label %37
37: ; preds = %35
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%39 = load i64, i64* %38
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%41 = load i64, i64* %40
%42 = icmp eq i64 %39, %41
br i1 %42, label %43, label %50
43: ; preds = %37
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%47 = load i32, i32* %46
%48 = icmp slt i32 %45, %47
%49 = zext i1 %48 to i32
br label %57
50: ; preds = %37
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%52 = load i64, i64* %51
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%54 = load i64, i64* %53
%55 = icmp slt i64 %52, %54
%56 = zext i1 %55 to i32
br label %57
57: ; preds = %50, %43
%58 = phi i32 [ %49, %43 ], [ %56, %50 ]
%59 = icmp ne i32 %58, 0
br i1 %59, label %35, label %60
60: ; preds = %57
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
define void @timing_uPause(i32 %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%6 = load i64, i64* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%8 = load i32, i32* %7
%9 = add nsw i32 %8, %0
%10 = icmp sgt i32 %9, 999999
%11 = add nsw i32 %9, -1000000
%12 = select i1 %10, i32 %11, i32 %9
%13 = zext i1 %10 to i64
%14 = add nsw i64 %6, %13
br label %15
15: ; preds = %15, %1
%16 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%17 = load i64, i64* %5
%18 = icmp eq i64 %17, %14
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, %12
%21 = icmp slt i64 %17, %14
%22 = select i1 %18, i1 %20, i1 %21
br i1 %22, label %15, label %23
23: ; preds = %15
ret void
}