#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 member_0;
  long tv_nsec;
  scalar_t__ tv_sec;
  int /*<<< orphan*/ member_1;
};

/* Variables and functions */
scalar_t__ __nanosleep(struct timespec *, struct timespec *);
unsigned int __sleep(unsigned int seconds) {
  struct timespec ts = {seconds, 0};
  if (__nanosleep(&ts, &ts) == 0)
    return 0;
  return (unsigned int)ts.tv_sec + (ts.tv_nsec >= 500000000L);
}


x86 assembly (clang, -O0):
<__sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x28(%rbp),%rsi
mov    %rsi,%rdi
call   1030 <__nanosleep@plt>
cmp    $0x0,%rax
jne    1163 <__sleep+0x43>
movl   $0x0,-0x4(%rbp)
jmp    117d <__sleep+0x5d>
mov    -0x18(%rbp),%rax
cmpq   $0x1dcd6500,-0x20(%rbp)
1d
setge  %cl
and    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__sleep>:
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
mov    %edi,(%rsp)
mov    %rsp,%rdi
mov    %rdi,%rsi
call   1030 <__nanosleep@plt>
test   %rax,%rax
je     114a <__sleep+0x3a>
xor    %eax,%eax
cmpq   $0x1dcd6500,0x8(%rsp)
cd 1d
setge  %al
add    0x10(%rsp),%eax
add    $0x28,%rsp
ret
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64, i64, i32 }
define i32 @__sleep(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timespec
store i32 %0, i32* %3
%5 = bitcast %struct.timespec* %4 to i8*
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%7 = load i32, i32* %3
store i32 %7, i32* %6
%8 = call i64 @__nanosleep(%struct.timespec* %4, %struct.timespec* %4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %20
11: ; preds = %1
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 2
%13 = load i64, i64* %12
%14 = trunc i64 %13 to i32
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%16 = load i64, i64* %15
%17 = icmp sge i64 %16, 500000000
%18 = zext i1 %17 to i32
%19 = add i32 %14, %18
store i32 %19, i32* %2
br label %20
20: ; preds = %11, %10
%21 = load i32, i32* %2
ret i32 %21
}

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