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

/* Variables and functions */
scalar_t__ nanosleep(struct timespec *, struct timespec *);
int /*<<< orphan*/ printf(char *);
int main() {
  struct timespec tim, tim2;
  tim.tv_sec = 1;
  tim.tv_nsec = 500;
  if (nanosleep(&tim, &tim2) < 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    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x1f4,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <nanosleep@plt>
cmp    $0x0,%rax
jge    116c <main+0x4c>
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    117f <main+0x5f>
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movabs $0x1f400000001,%rax
mov    %rax,(%rsp)
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1040 <nanosleep@plt>
mov    %rax,%rbx
test   %rax,%rax
lea    0xecb(%rip),%rax
lea    0xeac(%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, i32 }
@.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 i32 500, i32* %5
%6 = call i64 @nanosleep(%struct.timespec* %2, %struct.timespec* %3)
%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, i32 }
@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 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %1 to i8*
%4 = bitcast %struct.timespec* %2 to i8*
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i32 1, i32* %5
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i32 500, i32* %6
%7 = call i64 @nanosleep(%struct.timespec* %1, %struct.timespec* %2)
%8 = icmp slt i64 %7, 0
%9 = select i1 %8, 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)
%10 = ashr i64 %7, 63
%11 = trunc i64 %10 to i32
%12 = call i32 @puts(i8* dereferenceable(1) %9)
ret i32 %11
}