#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 timespec {
  unsigned int tv_sec;
  long tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ delayMicrosecondsHard(unsigned int);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
void delayMicroseconds(unsigned int howLong) {
  struct timespec sleeper;
  unsigned int uSecs = howLong % 1000000;
  unsigned int wSecs = howLong / 1000000;
  if (howLong == 0)
    return;
  else if (howLong < 100)
    delayMicrosecondsHard(howLong);
  else {
    sleeper.tv_sec = wSecs;
    sleeper.tv_nsec = (long)(uSecs * 1000L);
    nanosleep(&sleeper, NULL);
  }
}


x86 assembly (clang, -O0):
<delayMicroseconds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1158 <delayMicroseconds+0x38>
jmp    1195 <delayMicroseconds+0x75>
cmpl   $0x64,-0x4(%rbp)
jae    116f <delayMicroseconds+0x4f>
mov    -0x4(%rbp),%edi
call   1040 <delayMicrosecondsHard@plt>
jmp    1190 <delayMicroseconds+0x70>
mov    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
imul   $0x3e8,%rax,%rax
mov    %rax,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <nanosleep@plt>
jmp    1195 <delayMicroseconds+0x75>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delayMicroseconds>:
test   %edi,%edi
je     1166 <delayMicroseconds+0x46>
cmp    $0x63,%edi
ja     112e <delayMicroseconds+0xe>
jmp    1040 <delayMicrosecondsHard@plt>
sub    $0x18,%rsp
mov    %edi,%eax
imul   $0x431bde83,%rax,%rax
shr    $0x32,%rax
imul   $0xf4240,%eax,%ecx
sub    %ecx,%edi
mov    %eax,0x8(%rsp)
imul   $0x3e8,%edi,%eax
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
define void @delayMicroseconds(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timespec
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = urem i32 %6, 1000000
store i32 %7, i32* %4
%8 = load i32, i32* %2
%9 = udiv i32 %8, 1000000
store i32 %9, i32* %5
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
br label %28
13: ; preds = %1
%14 = load i32, i32* %2
%15 = icmp ult i32 %14, 100
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* %2
%18 = call i32 @delayMicrosecondsHard(i32 %17)
br label %27
19: ; preds = %13
%20 = load i32, i32* %5
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store i32 %20, i32* %21
%22 = load i32, i32* %4
%23 = zext i32 %22 to i64
%24 = mul nsw i64 %23, 1000
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i64 %24, i64* %25
%26 = call i32 @nanosleep(%struct.timespec* %3, i32* null)
br label %27
27: ; preds = %19, %16
br label %28
28: ; preds = %12, %27
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
define void @delayMicroseconds(i32 %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = urem i32 %0, 1000000
%5 = udiv i32 %0, 1000000
%6 = icmp eq i32 %0, 0
br i1 %6, label %17, label %7
7: ; preds = %1
%8 = icmp ult i32 %0, 100
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @delayMicrosecondsHard(i32 %0)
br label %17
11: ; preds = %7
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 %5, i32* %12
%13 = mul nuw nsw i32 %4, 1000
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 %14, i64* %15
%16 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
br label %17
17: ; preds = %11, %9, %1
ret void
}