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

/* Variables and functions */
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_SETMASK;
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
unsigned int sleep(unsigned int);
void xsleep(unsigned int s) {
  sigset_t sigset;
  sigset_t old_sigset;
  sigfillset(&sigset);
  sigprocmask(SIG_BLOCK, &sigset, &old_sigset);
  while ((s = sleep(s)))
    ;
  sigprocmask(SIG_SETMASK, &old_sigset, NULL);
}


x86 assembly (clang, -O0):
<xsleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x8(%rbp),%rdi
call   1040 <sigfillset@plt>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1030 <sigprocmask@plt>
mov    -0x4(%rbp),%edi
call   1050 <sleep@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
je     1173 <xsleep+0x43>
jmp    115a <xsleep+0x2a>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xsleep>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <sigfillset@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rdx
mov    %r14,%rsi
call   1030 <sigprocmask@plt>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1050 <sleep@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1160 <xsleep+0x30>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@SIG_BLOCK = global i32 0
@SIG_SETMASK = global i32 0
define void @xsleep(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 @sigfillset(i32* %3)
%6 = load i32, i32* @SIG_BLOCK
%7 = call i32 @sigprocmask(i32 %6, i32* %3, i32* %4)
br label %8
8: ; preds = %12, %1
%9 = load i32, i32* %2
%10 = call i32 @sleep(i32 %9)
store i32 %10, i32* %2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
br label %8
13: ; preds = %8
%14 = load i32, i32* @SIG_SETMASK
%15 = call i32 @sigprocmask(i32 %14, i32* %4, i32* null)
ret void
}

LLVM IR (-O2):
@SIG_BLOCK = global i32 0
@SIG_SETMASK = global i32 0
define void @xsleep(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = call i32 @sigfillset(i32* %2)
%7 = load i32, i32* @SIG_BLOCK
%8 = call i32 @sigprocmask(i32 %7, i32* %2, i32* %3)
br label %9
9: ; preds = %9, %1
%10 = phi i32 [ %0, %1 ], [ %11, %9 ]
%11 = call i32 @sleep(i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %9
13: ; preds = %9
%14 = load i32, i32* @SIG_SETMASK
%15 = call i32 @sigprocmask(i32 %14, i32* %3, i32* null)
ret void
}