#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 */

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sleep(long);
int usleep(long);
void longSleep(long sleepTime) {
  if (sleepTime <= 0) {
    return;
  }
  if (sleepTime < 1000000) {
    if (usleep(sleepTime) == -1) {
      if (errno != EINTR) {
        perror("usleep failed");
        exit(-1);
      }
    }
  } else {
    sleep(sleepTime / 1000000);
    if (usleep(sleepTime % 1000000) == -1) {
      if (errno != EINTR) {
        perror("usleep failed");
        exit(-1);
      }
    }
  }
  return;
}


x86 assembly (clang, -O0):
<longSleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jg     115c <longSleep+0x1c>
jmp    122a <longSleep+0xea>
cmpq   $0xf4240,-0x8(%rbp)
jge    11b6 <longSleep+0x76>
mov    -0x8(%rbp),%rdi
call   1060 <usleep@plt>
cmp    $0xffffffff,%eax
jne    11b1 <longSleep+0x71>
mov    0x2e5d(%rip),%rax
mov    (%rax),%rax
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%rax
je     11ac <longSleep+0x6c>
lea    0xe63(%rip),%rdi
call   1030 <perror@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
jmp    11b1 <longSleep+0x71>
jmp    1225 <longSleep+0xe5>
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rdi
call   1050 <sleep@plt>
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rdx,%rdi
call   1060 <usleep@plt>
cmp    $0xffffffff,%eax
jne    1220 <longSleep+0xe0>
mov    0x2dee(%rip),%rax
mov    (%rax),%rax
mov    0x2ddc(%rip),%rcx
cmp    (%rcx),%rax
je     121b <longSleep+0xdb>
lea    0xdf4(%rip),%rdi
call   1030 <perror@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>
jmp    1220 <longSleep+0xe0>
jmp    1225 <longSleep+0xe5>
jmp    122a <longSleep+0xea>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<longSleep>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
jle    11a1 <longSleep+0x61>
mov    %rdi,%rbx
cmp    $0xf423f,%rdi
jbe    117e <longSleep+0x3e>
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mov    %rbx,%rax
mul    %rcx
mov    %rdx,%r14
shr    $0x12,%r14
mov    %r14,%rdi
call   1050 <sleep@plt>
imul   $0xf4240,%r14,%rax
sub    %rax,%rbx
mov    %rbx,%rdi
call   1060 <usleep@plt>
cmp    $0xffffffff,%eax
jne    11a1 <longSleep+0x61>
mov    0x2e4e(%rip),%rax
mov    (%rax),%rax
mov    0x2e3c(%rip),%rcx
cmp    (%rcx),%rax
jne    11a9 <longSleep+0x69>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe50(%rip),%rdi
call   1030 <perror@plt>
mov    $0xffffffff,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [14 x i8] c"usleep failed\00"
define void @longSleep(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = icmp sle i64 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %1
br label %40
6: ; preds = %1
%7 = load i64, i64* %2
%8 = icmp slt i64 %7, 1000000
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = load i64, i64* %2
%11 = call i32 @usleep(i64 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %13
br label %21
21: ; preds = %20, %9
br label %39
22: ; preds = %6
%23 = load i64, i64* %2
%24 = sdiv i64 %23, 1000000
%25 = call i32 @sleep(i64 %24)
%26 = load i64, i64* %2
%27 = srem i64 %26, 1000000
%28 = call i32 @usleep(i64 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %38
30: ; preds = %22
%31 = load i64, i64* @errno
%32 = load i64, i64* @EINTR
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @exit(i32 -1)
unreachable
37: ; preds = %30
br label %38
38: ; preds = %37, %22
br label %39
39: ; preds = %38, %21
br label %40
40: ; preds = %39, %5
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [14 x i8] c"usleep failed\00"
define void @longSleep(i64 %0) {
%2 = icmp slt i64 %0, 1
br i1 %2, label %28, label %3
3: ; preds = %1
%4 = icmp ult i64 %0, 1000000
br i1 %4, label %5, label %15
5: ; preds = %3
%6 = tail call i32 @usleep(i64 %0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %28
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
br i1 %11, label %28, label %12
12: ; preds = %8
%13 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %3
%16 = udiv i64 %0, 1000000
%17 = tail call i32 @sleep(i64 %16)
%18 = urem i64 %0, 1000000
%19 = tail call i32 @usleep(i64 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %28
21: ; preds = %15
%22 = load i64, i64* @errno
%23 = load i64, i64* @EINTR
%24 = icmp eq i64 %22, %23
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%27 = tail call i32 @exit(i32 -1)
unreachable
28: ; preds = %8, %5, %21, %15, %1
ret void
}