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

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


x86 assembly (clang, -O0):
<delayMicroseconds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    115b <delayMicroseconds+0x3b>
jmp    1196 <delayMicroseconds+0x76>
cmpl   $0x64,-0x4(%rbp)
jae    1172 <delayMicroseconds+0x52>
mov    -0x4(%rbp),%edi
call   1040 <delayMicrosecondsHard@plt>
jmp    1191 <delayMicroseconds+0x71>
mov    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
imul   $0x3e8,-0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <nanosleep@plt>
jmp    1196 <delayMicroseconds+0x76>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delayMicroseconds>:
test   %edi,%edi
je     117f <delayMicroseconds+0x5f>
cmp    $0x63,%edi
ja     112e <delayMicroseconds+0xe>
jmp    1040 <delayMicrosecondsHard@plt>
sub    $0x18,%rsp
movslq %edi,%rax
imul   $0x431bde83,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
imul   $0xf4240,%ecx,%ecx
mov    %eax,%edx
sub    %ecx,%eax
imul   $0x431bde83,%rdx,%rcx
shr    $0x32,%rcx
mov    %ecx,0x8(%rsp)
imul   $0x3e8,%eax,%eax
cltq
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 i64
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = srem i32 %6, 1000000
%8 = sext i32 %7 to i64
store i64 %8, i64* %4
%9 = load i32, i32* %2
%10 = udiv i32 %9, 1000000
store i32 %10, i32* %5
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
br label %28
14: ; preds = %1
%15 = load i32, i32* %2
%16 = icmp ult i32 %15, 100
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %2
%19 = call i32 @delayMicrosecondsHard(i32 %18)
br label %27
20: ; preds = %14
%21 = load i32, i32* %5
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store i32 %21, i32* %22
%23 = load i64, i64* %4
%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 = %20, %17
br label %28
28: ; preds = %13, %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 = srem 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 nsw i32 %4, 1000
%14 = sext 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
}