#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 O_NONBLOCK;
scalar_t__ fcntl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ pr_exit(char *);
void setnonblocking(int fd) {
  int opts;
  if ((opts = fcntl(fd, F_GETFL)) < 0) {
    pr_exit("fcntl F_GETFL");
  }
  opts = opts | O_NONBLOCK;
  if (fcntl(fd, F_SETFL, opts) < 0) {
    pr_exit("fcntl F_SETFL");
  }
}


x86 assembly (clang, -O0):
<setnonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1156 <setnonblocking+0x36>
lea    0xeaf(%rip),%rdi
call   1040 <pr_exit@plt>
mov    -0x8(%rbp),%eax
mov    0x2e88(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    1191 <setnonblocking+0x71>
lea    0xe82(%rip),%rdi
call   1040 <pr_exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setnonblocking>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    %rax,%rbx
test   %ebx,%ebx
jns    1148 <setnonblocking+0x28>
lea    0xebd(%rip),%rdi
call   1040 <pr_exit@plt>
mov    0x2e99(%rip),%rax
or     (%rax),%ebx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %rax,%rax
js     1171 <setnonblocking+0x51>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe96(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <pr_exit@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [14 x i8] c"fcntl F_GETFL\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.1 = [14 x i8] c"fcntl F_SETFL\00"
define void @setnonblocking(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = load i32, i32* @F_GETFL
%6 = call i64 (i32, i32, ...) @fcntl(i32 %4, i32 %5)
%7 = trunc i64 %6 to i32
store i32 %7, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @pr_exit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = load i32, i32* %3
%13 = load i32, i32* @O_NONBLOCK
%14 = or i32 %12, %13
store i32 %14, i32* %3
%15 = load i32, i32* %2
%16 = load i32, i32* @F_SETFL
%17 = load i32, i32* %3
%18 = call i64 (i32, i32, ...) @fcntl(i32 %15, i32 %16, i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = call i32 @pr_exit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %11
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [14 x i8] c"fcntl F_GETFL\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.1 = [14 x i8] c"fcntl F_SETFL\00"
define void @setnonblocking(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i64 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = trunc i64 %3 to i32
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @pr_exit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = load i32, i32* @O_NONBLOCK
%10 = or i32 %9, %4
%11 = load i32, i32* @F_SETFL
%12 = tail call i64 (i32, i32, ...) @fcntl(i32 %0, i32 %11, i32 %10)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 @pr_exit(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %8
ret void
}