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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
long timeval_to_usec(struct timeval);
void udelay(long us) {
  struct timeval current;
  struct timeval start;
  gettimeofday(&start, NULL);
  do {
    gettimeofday(&current, NULL);
  } while (timeval_to_usec(current) - timeval_to_usec(start) < us);
}


x86 assembly (clang, -O0):
<udelay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%edi
call   1040 <timeval_to_usec@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <timeval_to_usec@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
cmp    -0x8(%rbp),%rax
jl     1139 <udelay+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udelay>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%ebp
lea    0x10(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x10(%rsp),%edi
call   1040 <timeval_to_usec@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1040 <timeval_to_usec@plt>
sub    %rax,%rbx
cmp    %r15,%rbx
jl     1150 <udelay+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32 }
define void @udelay(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 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%9 = load i32, i32* %8
br label %10
10: ; preds = %10, %1
%11 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%12 = load i32, i32* %7
%13 = tail call i64 @timeval_to_usec(i32 %12)
%14 = tail call i64 @timeval_to_usec(i32 %9)
%15 = sub nsw i64 %13, %14
%16 = icmp slt i64 %15, %0
br i1 %16, label %10, label %17
17: ; preds = %10
ret void
}