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

/* Variables and functions */
scalar_t__ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main() {
  struct timespec tim, tim2;
  tim.tv_sec = 1;
  tim.tv_nsec = 500000000L;
  if (nanosleep(&tim, NULL) < 0) {
    printf("Nano sleep system call failed \n");
    return -1;
  }
  printf("Nano sleep successfull \n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x18(%rbp)
movq   $0x1dcd6500,-0x10(%rbp)
1d
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <nanosleep@plt>
cmp    $0x0,%rax
jge    116d <main+0x4d>
lea    0xea4(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1180 <main+0x60>
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x1,(%rsp)
movq   $0x1dcd6500,0x8(%rsp)
cd 1d
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    %rax,%rbx
test   %rax,%rax
lea    0xecc(%rip),%rax
lea    0xead(%rip),%rdi
cmovs  %rax,%rdi
sar    $0x3f,%rbx
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@str = [24 x i8] c"Nano sleep successfull \00"
@str.2 = [31 x i8] c"Nano sleep system call failed \00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i32 1, i32* %3
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i64 500000000, i64* %4
%5 = call i64 @nanosleep(%struct.timespec* %1, i32* null)
%6 = icmp slt i64 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @str.2, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0)
%8 = ashr i64 %5, 63
%9 = trunc i64 %8 to i32
%10 = call i32 @puts(i8* dereferenceable(1) %7)
ret i32 %9
}