#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 /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int fcntl(int, int /*<<< orphan*/, int);
int os_set_nonblocking(int fd) {
  int res;
  int nonb = 0;
  if ((res = fcntl(fd, F_GETFL, 0)) == -1)
    return 0;
  else if (fcntl(fd, F_SETFL, res | nonb) == -1)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<os_set_nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    114d <os_set_nonblocking+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    1185 <os_set_nonblocking+0x75>
mov    -0x8(%rbp),%edi
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
or     -0x10(%rbp),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    1179 <os_set_nonblocking+0x69>
movl   $0x0,-0x4(%rbp)
jmp    1185 <os_set_nonblocking+0x75>
jmp    117e <os_set_nonblocking+0x6e>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_set_nonblocking>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ebc(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1147 <os_set_nonblocking+0x37>
mov    0x2ead(%rip),%rcx
mov    (%rcx),%esi
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
define i32 @os_set_nonblocking(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = load i32, i32* @F_GETFL
%8 = call i32 @fcntl(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %4
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %22
11: ; preds = %1
%12 = load i32, i32* %3
%13 = load i32, i32* @F_SETFL
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = or i32 %14, %15
%17 = call i32 @fcntl(i32 %12, i32 %13, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %11
store i32 0, i32* %2
br label %22
20: ; preds = %11
br label %21
21: ; preds = %20
store i32 1, i32* %2
br label %22
22: ; preds = %21, %19, %10
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
define i32 @os_set_nonblocking(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 @fcntl(i32 %0, i32 %2, i32 0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = load i32, i32* @F_SETFL
%7 = tail call i32 @fcntl(i32 %0, i32 %6, i32 %3)
%8 = icmp ne i32 %7, -1
%9 = zext i1 %8 to i32
br label %10
10: ; preds = %5, %1
%11 = phi i32 [ 0, %1 ], [ %9, %5 ]
ret i32 %11
}