#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 member_1;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
#define EINTR 128
int nanosleep(struct timespec *, int /*<<< orphan*/ *);
int okn_time_wait_nsec(int nsec) {
  if (nsec < 0)
    return -5;
  struct timespec spec = {0, nsec};
  switch (nanosleep(&spec, NULL)) {
  case 0:
  case EINTR:
    break;
  default:
    return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<okn_time_wait_nsec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1131 <okn_time_wait_nsec+0x21>
movl   $0xfffffffb,-0x4(%rbp)
jmp    1173 <okn_time_wait_nsec+0x63>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%esi
lea    -0x10(%rbp),%rdi
call   1030 <nanosleep@plt>
test   $0xffffff7f,%eax
je     115b <okn_time_wait_nsec+0x4b>
jmp    1160 <okn_time_wait_nsec+0x50>
jmp    116c <okn_time_wait_nsec+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1173 <okn_time_wait_nsec+0x63>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<okn_time_wait_nsec>:
test   %edi,%edi
js     113b <okn_time_wait_nsec+0x2b>
push   %rax
movl   $0x0,(%rsp)
mov    %edi,0x4(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
and    $0xffffff7f,%eax
neg    %eax
sbb    %eax,%eax
or     $0x1,%eax
add    $0x8,%rsp
ret
mov    $0xfffffffb,%eax
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define i32 @okn_time_wait_nsec(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timespec
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 -5, i32* %2
br label %16
8: ; preds = %1
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store i32 0, i32* %9
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%11 = load i32, i32* %3
store i32 %11, i32* %10
%12 = call i32 @nanosleep(%struct.timespec* %4, i32* null)
switch i32 %12, label %14 [
i32 0, label %13
i32 128, label %13
]
13: ; preds = %8, %8
br label %15
14: ; preds = %8
store i32 -1, i32* %2
br label %16
15: ; preds = %13
store i32 1, i32* %2
br label %16
16: ; preds = %15, %14, %7
%17 = load i32, i32* %2
ret i32 %17
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define i32 @okn_time_wait_nsec(i32 %0) {
%2 = alloca %struct.timespec
%3 = icmp slt i32 %0, 0
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = bitcast %struct.timespec* %2 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 i32 %0, i32* %7
%8 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%9 = and i32 %8, -129
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i32 1, i32 -1
br label %12
12: ; preds = %1, %4
%13 = phi i32 [ %11, %4 ], [ -5, %1 ]
ret i32 %13
}