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

/* Variables and functions */
scalar_t__ nanosleep(struct timespec *, struct timespec *);
int /*<<< orphan*/ printf(char *);
int my_sleep(int seconds) {
  struct timespec t_req, t_rem;
  t_req.tv_sec = seconds;
  t_req.tv_nsec = 0;
  if (nanosleep(&t_req, &t_rem) < 0) {
    printf("Nano sleep system call failed \n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<my_sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <nanosleep@plt>
cmp    $0x0,%rax
jge    1168 <my_sleep+0x48>
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    116f <my_sleep+0x4f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_sleep>:
sub    $0x28,%rsp
mov    %edi,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x18(%rsp),%rsi
call   1040 <nanosleep@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     114f <my_sleep+0x2f>
add    $0x28,%rsp
ret
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@.str = [32 x i8] c"Nano sleep system call failed \0A\00"
define i32 @my_sleep(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
store i64 0, i64* %8
%9 = call i64 @nanosleep(%struct.timespec* %4, %struct.timespec* %5)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %14
13: ; preds = %1
store i32 0, i32* %2
br label %14
14: ; preds = %13, %11
%15 = load i32, i32* %2
ret i32 %15
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@str = [31 x i8] c"Nano sleep system call failed \00"
define i32 @my_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 i64 0, i64* %7
%8 = call i64 @nanosleep(%struct.timespec* %2, %struct.timespec* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %1, %10
%13 = phi i32 [ -1, %10 ], [ 0, %1 ]
ret i32 %13
}