#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 /*<<< orphan*/ tv_nsec;
};

/* Variables and functions */
int nanosleep(struct timespec const *, struct timespec *);
unsigned int sleep(unsigned int seconds) {
  const struct timespec req = {.tv_sec = seconds, .tv_nsec = 0};
  struct timespec rem = {.tv_sec = 0, .tv_nsec = 0};
  int rv;
  rv = nanosleep(&req, &rem);
  if (rv == 0) {
    return 0;
  } else {
    return (unsigned int)rem.tv_sec;
  }
}


x86 assembly (clang, -O0):
<sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <nanosleep@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    116e <sleep+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    1174 <sleep+0x54>
mov    -0x18(%rbp),%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,0x10(%rsp)
movl   $0x0,0x14(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <nanosleep@plt>
test   %eax,%eax
je     1140 <sleep+0x30>
mov    0x8(%rsp),%eax
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define i32 @sleep(i32 %0) {
%2 = alloca %struct.timespec
%3 = alloca i64
%4 = bitcast i64* %3 to %struct.timespec*
%5 = bitcast %struct.timespec* %2 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 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%9 = call i32 @nanosleep(%struct.timespec* %2, %struct.timespec* %4)
%10 = icmp eq i32 %9, 0
%11 = bitcast i64* %3 to i32*
%12 = load i32, i32* %11
%13 = select i1 %10, i32 0, i32 %12
ret i32 %13
}