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

/* Variables and functions */
scalar_t__ ceil(int);
int /*<<< orphan*/ nanosleep(struct timespec *, struct timespec *);
int /*<<< orphan*/ printf_verbose(char *, unsigned int, unsigned int);
unsigned int sleep(unsigned int seconds) {
  struct timespec req;
  struct timespec rem;
  unsigned int res;
  req.tv_sec = seconds;
  req.tv_nsec = 0;
  nanosleep(&req, &rem);
  res = rem.tv_sec + (unsigned int)ceil(rem.tv_nsec / 1000000000);
  printf_verbose("sleep(%u) = %u;\n", seconds, res);
  return res;
}


x86 assembly (clang, -O0):
<sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <nanosleep@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <ceil@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    0xe7b(%rip),%rdi
call   1030 <printf_verbose@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sleep>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
mov    %edi,0x8(%rsp)
movl   $0x0,0xc(%rsp)
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1050 <nanosleep@plt>
mov    (%rsp),%r14d
movslq 0x4(%rsp),%rax
imul   $0x44b82fa1,%rax,%rdi
mov    %rdi,%rax
shr    $0x3f,%rax
sar    $0x3c,%rdi
add    %eax,%edi
call   1040 <ceil@plt>
mov    %rax,%rbx
add    %r14d,%ebx
lea    0xe7e(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <printf_verbose@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@.str = [17 x i8] c"sleep(%u) = %u;\0A\00"
define i32 @sleep(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca i32
store i32 %0, i32* %2
%6 = load i32, i32* %2
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i32 0, i32* %8
%9 = call i32 @nanosleep(%struct.timespec* %3, %struct.timespec* %4)
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%13 = load i32, i32* %12
%14 = sdiv i32 %13, 1000000000
%15 = call i64 @ceil(i32 %14)
%16 = trunc i64 %15 to i32
%17 = add i32 %11, %16
store i32 %17, i32* %5
%18 = load i32, i32* %2
%19 = load i32, i32* %5
%20 = call i32 @printf_verbose(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19)
%21 = load i32, i32* %5
ret i32 %21
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@.str = [17 x i8] c"sleep(%u) = %u;\0A\00"
define i32 @sleep(i32 %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %2 to i8*
%5 = bitcast %struct.timespec* %3 to i8*
%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 i32 0, i32* %7
%8 = call i32 @nanosleep(%struct.timespec* %2, %struct.timespec* %3)
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%12 = load i32, i32* %11
%13 = sdiv i32 %12, 1000000000
%14 = call i64 @ceil(i32 %13)
%15 = trunc i64 %14 to i32
%16 = add i32 %10, %15
%17 = call i32 @printf_verbose(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %16)
ret i32 %16
}