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

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


x86 assembly (clang, -O0):
<__sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x18(%rbp),%rsi
mov    %rsi,%rdi
call   1030 <__nanosleep@plt>
cmp    $0x0,%rax
jne    114b <__sleep+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    1164 <__sleep+0x54>
mov    -0x18(%rbp),%eax
cmpq   $0x1dcd6500,-0x10(%rbp)
1d
setge  %cl
and    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
define i32 @__sleep(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timespec
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store i32 %5, i32* %6
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
store i64 0, i64* %7
%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 %19
11: ; preds = %1
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%15 = load i64, i64* %14
%16 = icmp sge i64 %15, 500000000
%17 = zext i1 %16 to i32
%18 = add i32 %13, %17
store i32 %18, i32* %2
br label %19
19: ; preds = %11, %10
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
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 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 0, i64* %5
%6 = call i64 @__nanosleep(%struct.timespec* %2, %struct.timespec* %2)
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = load i32, i32* %4
%10 = load i64, i64* %5
%11 = icmp sgt i64 %10, 499999999
%12 = zext i1 %11 to i32
%13 = add i32 %9, %12
br label %14
14: ; preds = %1, %8
%15 = phi i32 [ %13, %8 ], [ 0, %1 ]
ret i32 %15
}