#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 */
typedef int /*<<< orphan*/ time_t;
struct timespec {
  long tv_nsec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int nanosleep(struct timespec *, struct timespec *);
int r_sleep(time_t sec, long nsec) {
  struct timespec req, rem;
  req.tv_sec = sec;
  req.tv_nsec = nsec;
  while (nanosleep(&req, &rem) == -1) {
    if (errno != EINTR)
      return -1;
    req = rem;
  }
  return 0;
}


x86 assembly (clang, -O0):
<r_sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <nanosleep@plt>
cmp    $0xffffffff,%eax
jne    117e <r_sleep+0x6e>
mov    0x2e96(%rip),%rax
mov    (%rax),%rax
mov    0x2e84(%rip),%rcx
cmp    (%rcx),%rax
je     1169 <r_sleep+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    1185 <r_sleep+0x75>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    112d <r_sleep+0x1d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<r_sleep>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edi,0x8(%rsp)
mov    %rsi,(%rsp)
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
call   1030 <nanosleep@plt>
xor    %r14d,%r14d
cmp    $0xffffffff,%eax
jne    117a <r_sleep+0x6a>
mov    0x2ea0(%rip),%r15
mov    0x2e91(%rip),%r12
mov    %rsp,%rbx
lea    0x10(%rsp),%rbp
nop
mov    (%r15),%rax
cmp    (%r12),%rax
jne    1174 <r_sleep+0x64>
movups 0x10(%rsp),%xmm0
movaps %xmm0,(%rsp)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <nanosleep@plt>
cmp    $0xffffffff,%eax
je     1150 <r_sleep+0x40>
jmp    117a <r_sleep+0x6a>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @r_sleep(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca %struct.timespec
%7 = alloca %struct.timespec
store i32 %0, i32* %4
store i64 %1, i64* %5
%8 = load i32, i32* %4
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
store i32 %8, i32* %9
%10 = load i64, i64* %5
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
store i64 %10, i64* %11
br label %12
12: ; preds = %20, %2
%13 = call i32 @nanosleep(%struct.timespec* %6, %struct.timespec* %7)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp ne i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 -1, i32* %3
br label %24
20: ; preds = %15
%21 = bitcast %struct.timespec* %6 to i8*
%22 = bitcast %struct.timespec* %7 to i8*
br label %12
23: ; preds = %12
store i32 0, i32* %3
br label %24
24: ; preds = %23, %19
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.timespec = type { i64, i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @r_sleep(i32 %0, i64 %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = bitcast %struct.timespec* %3 to i8*
%6 = bitcast %struct.timespec* %4 to i8*
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
store i32 %0, i32* %7
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
store i64 %1, i64* %8
%9 = call i32 @nanosleep(%struct.timespec* %3, %struct.timespec* %4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %18
11: ; preds = %2, %15
%12 = load i64, i64* @errno
%13 = load i64, i64* @EINTR
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @nanosleep(%struct.timespec* %3, %struct.timespec* %4)
%17 = icmp eq i32 %16, -1
br i1 %17, label %11, label %18
18: ; preds = %11, %15, %2
%19 = phi i32 [ 0, %2 ], [ 0, %15 ], [ -1, %11 ]
ret i32 %19
}