#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__ EINVAL;
scalar_t__ clock_nanosleep(int, int /*<<< orphan*/, struct timespec *,
                           int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  struct timespec tssleep;
  tssleep.tv_sec = 4;
  tssleep.tv_nsec = 0;
  if (clock_nanosleep(99999, 0, &tssleep, NULL) == EINVAL) {
    printf("Test PASSED\n");
    return 0;
  }
  printf("errno != EINVAL\n");
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x1869f,%edi
xor    %esi,%esi
lea    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <clock_nanosleep@plt>
mov    0x2e87(%rip),%rcx
cmp    (%rcx),%rax
jne    117a <main+0x5a>
lea    0xe97(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    118d <main+0x6d>
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x4,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rdx
mov    $0x1869f,%edi
xor    %esi,%esi
xor    %ecx,%ecx
call   1040 <clock_nanosleep@plt>
mov    0x2e93(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%rax
setne  %bl
lea    0xeb4(%rip),%rax
lea    0xe9d(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@EINVAL = global i64 0
@.str = [13 x i8] c"Test PASSED\0A\00"
@.str.1 = [17 x i8] c"errno != EINVAL\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
store i32 0, i32* %1
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i32 4, i32* %3
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i64 0, i64* %4
%5 = call i64 @clock_nanosleep(i32 99999, i32 0, %struct.timespec* %2, i32* null)
%6 = load i64, i64* @EINVAL
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %12
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 1, 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 }
@EINVAL = global i64 0
@str = [16 x i8] c"errno != EINVAL\00"
@str.2 = [12 x i8] c"Test PASSED\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 4, i32* %3
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i64 0, i64* %4
%5 = call i64 @clock_nanosleep(i32 99999, i32 0, %struct.timespec* %1, i32* null)
%6 = load i64, i64* @EINVAL
%7 = icmp eq i64 %5, %6
%8 = select i1 %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0)
%9 = xor i1 %7, true
%10 = zext i1 %9 to i32
%11 = call i32 @puts(i8* dereferenceable(1) %8)
ret i32 %10
}