#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_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int nanosleep(struct timespec *, struct timespec *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  struct timespec tssleepfor, tsstorage;
  int sleepnsec = -1;
  tssleepfor.tv_sec = 0;
  tssleepfor.tv_nsec = sleepnsec;
  if (nanosleep(&tssleepfor, &tsstorage) == -1) {
    printf("Test PASSED\n");
    return 0;
  }
  printf("nanosleep() did not return -1 on failure\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1040 <nanosleep@plt>
cmp    $0xffffffff,%eax
jne    1172 <main+0x52>
lea    0xe9f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1185 <main+0x65>
lea    0xe94(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movq   $0x0,0x8(%rsp)
movl   $0xffffffff,(%rsp)
mov    %rsp,%rdi
lea    0x10(%rsp),%rsi
call   1040 <nanosleep@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
setne  %bl
lea    0xed8(%rip),%rax
lea    0xea8(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@.str = [13 x i8] c"Test PASSED\0A\00"
@.str.1 = [42 x i8] c"nanosleep() did not return -1 on failure\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = alloca i32
store i32 0, i32* %1
store i32 -1, i32* %4
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i64 0, i64* %5
%6 = load i32, i32* %4
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i32 %6, i32* %7
%8 = call i32 @nanosleep(%struct.timespec* %2, %struct.timespec* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %14
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %14
14: ; preds = %12, %10
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@str = [41 x i8] c"nanosleep() did not return -1 on failure\00"
@str.2 = [12 x i8] c"Test PASSED\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 1
store i64 0, i64* %5
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i32 -1, i32* %6
%7 = call i32 @nanosleep(%struct.timespec* %1, %struct.timespec* %2)
%8 = icmp eq i32 %7, -1
%9 = select i1 %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.2, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0)
%10 = xor i1 %8, true
%11 = zext i1 %10 to i32
%12 = call i32 @puts(i8* dereferenceable(1) %9)
ret i32 %11
}