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

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int nanosleep(struct timespec *, int /*<<< orphan*/ *);
int interruptible_sleep(unsigned seconds) {
  struct timespec ts;
  if (!seconds)
    return 0;
  ts.tv_sec = seconds;
  ts.tv_nsec = 0;
  return !(nanosleep(&ts, NULL) == -1 && errno == EINTR);
}


x86 assembly (clang, -O0):
<interruptible_sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1131 <interruptible_sleep+0x21>
movl   $0x0,-0x4(%rbp)
jmp    1183 <interruptible_sleep+0x73>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <nanosleep@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x19(%rbp)
jne    1176 <interruptible_sleep+0x66>
mov    0x2e7d(%rip),%rax
mov    (%rax),%rax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interruptible_sleep>:
test   %edi,%edi
je     1158 <interruptible_sleep+0x48>
sub    $0x18,%rsp
mov    %edi,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
cmp    $0xffffffff,%eax
setne  %al
mov    0x2ea2(%rip),%rcx
mov    (%rcx),%rcx
mov    0x2e90(%rip),%rdx
cmp    (%rdx),%rcx
setne  %cl
or     %al,%cl
movzbl %cl,%eax
add    $0x18,%rsp
ret
xor    %eax,%eax
ret

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

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