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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
void DELAY10US(unsigned int us) {
  struct timeval tv;
  long unsigned int sec;
  long unsigned int usec;
  long unsigned int norm_usec;
  gettimeofday(&tv, NULL);
  sec = tv.tv_sec;
  usec = tv.tv_usec;
  do {
    gettimeofday(&tv, NULL);
    norm_usec = (tv.tv_sec - sec) * 1000000 + (tv.tv_usec - usec);
  } while ((10 * us) > norm_usec);
}


x86 assembly (clang, -O0):
<DELAY10US>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
sub    -0x20(%rbp),%rax
imul   $0xf4240,%rax,%rax
mov    -0x10(%rbp),%rcx
sub    -0x28(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
imul   $0xa,-0x4(%rbp),%eax
mov    %eax,%eax
cmp    -0x30(%rbp),%rax
ja     1138 <DELAY10US+0x28>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DELAY10US>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rsp),%r12
mov    0x8(%rsp),%r13
add    %r14d,%r14d
lea    (%r14,%r14,4),%ebx
nopl   (%rax)
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rsp),%rax
sub    %r12,%rax
mov    0x8(%rsp),%rcx
sub    %r13,%rcx
imul   $0xf4240,%rax,%rax
add    %rcx,%rax
cmp    %rbx,%rax
jb     1140 <DELAY10US+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define void @DELAY10US(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32 %0, i32* %2
%7 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%9 = load i64, i64* %8
store i64 %9, i64* %4
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%11 = load i64, i64* %10
store i64 %11, i64* %5
br label %12
12: ; preds = %24, %1
%13 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%15 = load i64, i64* %14
%16 = load i64, i64* %4
%17 = sub i64 %15, %16
%18 = mul i64 %17, 1000000
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%20 = load i64, i64* %19
%21 = load i64, i64* %5
%22 = sub i64 %20, %21
%23 = add i64 %18, %22
store i64 %23, i64* %6
br label %24
24: ; preds = %12
%25 = load i32, i32* %2
%26 = mul i32 10, %25
%27 = zext i32 %26 to i64
%28 = load i64, i64* %6
%29 = icmp ugt i64 %27, %28
br i1 %29, label %12, label %30
30: ; preds = %24
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @DELAY10US(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 i64, i64* %7
%9 = mul i32 %0, 10
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %11, %1
%12 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%13 = load i64, i64* %5
%14 = sub i64 %13, %6
%15 = mul i64 %14, 1000000
%16 = load i64, i64* %7
%17 = sub i64 %16, %8
%18 = add i64 %17, %15
%19 = icmp ult i64 %18, %10
br i1 %19, label %11, label %20
20: ; preds = %11
ret void
}