#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 */

/* Variables and functions */
int EINTR;
int /*<<< orphan*/ FIONBIO;
int errno;
int ioctl(int, int /*<<< orphan*/, int *);
int sjs__nonblock(int fd, int set) {
  int r;
  do
    r = ioctl(fd, FIONBIO, &set);
  while (r == -1 && errno == EINTR);
  if (r)
    return -errno;
  return 0;
}


x86 assembly (clang, -O0):
<sjs__nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jne    115d <sjs__nonblock+0x4d>
mov    0x2e94(%rip),%rax
mov    (%rax),%eax
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    111e <sjs__nonblock+0xe>
cmpl   $0x0,-0x10(%rbp)
je     1185 <sjs__nonblock+0x75>
xor    %eax,%eax
mov    0x2e65(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    118c <sjs__nonblock+0x7c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sjs__nonblock>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %esi,0xc(%rsp)
mov    0x2eae(%rip),%r15
lea    0xc(%rsp),%r14
mov    0x2eaa(%rip),%r12
mov    0x2e93(%rip),%r13
nopl   (%rax)
mov    (%r15),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    (%r12),%ecx
cmp    $0xffffffff,%eax
jne    115c <sjs__nonblock+0x4c>
cmp    0x0(%r13),%ecx
je     1140 <sjs__nonblock+0x30>
neg    %ecx
test   %eax,%eax
cmove  %eax,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@FIONBIO = global i32 0
@errno = global i32 0
@EINTR = global i32 0
define i32 @sjs__nonblock(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
br label %7
7: ; preds = %18, %2
%8 = load i32, i32* %4
%9 = load i32, i32* @FIONBIO
%10 = call i32 @ioctl(i32 %8, i32 %9, i32* %5)
store i32 %10, i32* %6
br label %11
11: ; preds = %7
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @errno
%16 = load i32, i32* @EINTR
%17 = icmp eq i32 %15, %16
br label %18
18: ; preds = %14, %11
%19 = phi i1 [ false, %11 ], [ %17, %14 ]
br i1 %19, label %7, label %20
20: ; preds = %18
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @errno
%25 = sub nsw i32 0, %24
store i32 %25, i32* %3
br label %27
26: ; preds = %20
store i32 0, i32* %3
br label %27
27: ; preds = %26, %23
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@FIONBIO = global i32 0
@errno = global i32 0
@EINTR = global i32 0
define i32 @sjs__nonblock(i32 %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
br label %4
4: ; preds = %4, %2
%5 = load i32, i32* @FIONBIO
%6 = call i32 @ioctl(i32 %0, i32 %5, i32* %3)
%7 = icmp eq i32 %6, -1
%8 = load i32, i32* @errno
%9 = load i32, i32* @EINTR
%10 = icmp eq i32 %8, %9
%11 = select i1 %7, i1 %10, i1 false
br i1 %11, label %4, label %12
12: ; preds = %4
%13 = icmp eq i32 %6, 0
%14 = sub nsw i32 0, %8
%15 = select i1 %13, i32 0, i32 %14
ret i32 %15
}