#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;
  scalar_t__ tv_nsec;
};

/* Variables and functions */
int EINTR;
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int nanosleep(struct timespec *, struct timespec *);
int /*<<< orphan*/ stderr;
char *strerror(int);
void sleepNoSig(int sec) {
  int ret;
  struct timespec req, rem;
  rem.tv_sec = sec;
  rem.tv_nsec = 0;
  do {
    req = rem;
    ret = nanosleep(&req, &rem);
  } while ((ret == -1) && (errno == EINTR));
  if (ret == -1) {
    ret = errno;
    fprintf(stderr, "nanosleep error %d (%s)\n", ret, strerror(ret));
  }
}


x86 assembly (clang, -O0):
<sleepNoSig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <nanosleep@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x8(%rbp)
mov    %al,-0x29(%rbp)
jne    1190 <sleepNoSig+0x60>
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1149 <sleepNoSig+0x19>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11e0 <sleepNoSig+0xb0>
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%edx
mov    %rax,%rcx
lea    0xe25(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sleepNoSig>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edi,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%r14
mov    %rsp,%r15
mov    0x2e81(%rip),%r12
mov    0x2e72(%rip),%rbx
xchg   %ax,%ax
mov    (%rsp),%eax
mov    %eax,0x10(%rsp)
mov    0x4(%rsp),%eax
mov    %eax,0x14(%rsp)
mov    0x8(%rsp),%rax
mov    %rax,0x18(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <nanosleep@plt>
mov    (%r12),%ebp
cmp    $0xffffffff,%eax
jne    1191 <sleepNoSig+0x61>
cmp    (%rbx),%ebp
je     1160 <sleepNoSig+0x30>
cmp    $0xffffffff,%eax
jne    11b9 <sleepNoSig+0x89>
mov    0x2e43(%rip),%rax
mov    (%rax),%ebx
mov    %ebp,%edi
call   1050 <strerror@plt>
lea    0xe53(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@errno = global i32 0
@EINTR = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"nanosleep error %d (%s)\0A\00"
define void @sleepNoSig(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
store i64 0, i64* %8
br label %9
9: ; preds = %20, %1
%10 = bitcast %struct.timespec* %4 to i8*
%11 = bitcast %struct.timespec* %5 to i8*
%12 = call i32 @nanosleep(%struct.timespec* %4, %struct.timespec* %5)
store i32 %12, i32* %3
br label %13
13: ; preds = %9
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* @errno
%18 = load i32, i32* @EINTR
%19 = icmp eq i32 %17, %18
br label %20
20: ; preds = %16, %13
%21 = phi i1 [ false, %13 ], [ %19, %16 ]
br i1 %21, label %9, label %22
22: ; preds = %20
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %32
25: ; preds = %22
%26 = load i32, i32* @errno
store i32 %26, i32* %3
%27 = load i32, i32* @stderr
%28 = load i32, i32* %3
%29 = load i32, i32* %3
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %28, i8* %30)
br label %32
32: ; preds = %25, %22
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@errno = global i32 0
@EINTR = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"nanosleep error %d (%s)\0A\00"
define void @sleepNoSig(i32 %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %2 to i8*
%5 = bitcast %struct.timespec* %3 to i8*
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
store i32 %0, i32* %6
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
store i64 0, i64* %7
br label %8
8: ; preds = %8, %1
%9 = call i32 @nanosleep(%struct.timespec* %2, %struct.timespec* %3)
%10 = icmp eq i32 %9, -1
%11 = load i32, i32* @errno
%12 = load i32, i32* @EINTR
%13 = icmp eq i32 %11, %12
%14 = select i1 %10, i1 %13, i1 false
br i1 %14, label %8, label %15
15: ; preds = %8
br i1 %10, label %16, label %20
16: ; preds = %15
%17 = load i32, i32* @stderr
%18 = call i8* @strerror(i32 %11)
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %18)
br label %20
20: ; preds = %16, %15
ret void
}