#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 */
scalar_t__ EINTR;
int /*<<< orphan*/ FIONBIO;
int api_error_translate(scalar_t__);
scalar_t__ errno;
int ioctl(int, int /*<<< orphan*/, int *);
int api_socket_non_block(int fd, int on) {
  int r;
  do {
    r = ioctl(fd, FIONBIO, &on);
  } while (r == -1 && errno == EINTR);
  if (r)
    return api_error_translate(errno);
  return 0;
}


x86 assembly (clang, -O0):
<api_socket_non_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea0(%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    116f <api_socket_non_block+0x4f>
mov    0x2e84(%rip),%rax
mov    (%rax),%rax
mov    0x2e6a(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    112e <api_socket_non_block+0xe>
cmpl   $0x0,-0x10(%rbp)
je     119b <api_socket_non_block+0x7b>
mov    0x2e55(%rip),%rax
mov    (%rax),%rdi
call   1040 <api_error_translate@plt>
mov    %eax,-0x4(%rbp)
jmp    11a2 <api_socket_non_block+0x82>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<api_socket_non_block>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    %esi,0xc(%rsp)
mov    0x2e9e(%rip),%r15
lea    0xc(%rsp),%r14
mov    0x2e9a(%rip),%r12
mov    0x2e83(%rip),%r13
nopl   (%rax)
mov    (%r15),%esi
mov    %ebx,%edi
mov    %r14,%rdx
call   1030 <ioctl@plt>
mov    (%r12),%rdi
cmp    $0xffffffff,%eax
jne    116c <api_socket_non_block+0x4c>
cmp    0x0(%r13),%rdi
je     1150 <api_socket_non_block+0x30>
test   %eax,%eax
je     1177 <api_socket_non_block+0x57>
call   1040 <api_error_translate@plt>
jmp    1179 <api_socket_non_block+0x59>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@FIONBIO = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define i32 @api_socket_non_block(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 i64, i64* @errno
%16 = load i64, i64* @EINTR
%17 = icmp eq i64 %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 i64, i64* @errno
%25 = call i32 @api_error_translate(i64 %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 i64 0
@EINTR = global i64 0
define i32 @api_socket_non_block(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 i64, i64* @errno
%9 = load i64, i64* @EINTR
%10 = icmp eq i64 %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
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = call i32 @api_error_translate(i64 %8)
br label %16
16: ; preds = %12, %14
%17 = phi i32 [ %15, %14 ], [ 0, %12 ]
ret i32 %17
}