#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
void setnonblocking(int fd) {
  int opts;
  opts = fcntl(fd, F_GETFL);
  if (opts < 0) {
    fprintf(stderr, "fcntl failed\n");
    return;
  }
  opts = opts | O_NONBLOCK;
  if (fcntl(fd, F_SETFL, opts) < 0) {
    fprintf(stderr, "fcntl failed\n");
    return;
  }
  return;
}


x86 assembly (clang, -O0):
<setnonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1165 <setnonblocking+0x45>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11b3 <setnonblocking+0x93>
mov    -0x8(%rbp),%eax
mov    0x2e79(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    11ae <setnonblocking+0x8e>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11b3 <setnonblocking+0x93>
jmp    11b3 <setnonblocking+0x93>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setnonblocking>:
push   %rbx
mov    %edi,%ebx
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     115b <setnonblocking+0x3b>
mov    0x2eaa(%rip),%rcx
or     (%rcx),%eax
mov    0x2e89(%rip),%rcx
mov    (%rcx),%esi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %rax,%rax
js     115b <setnonblocking+0x3b>
pop    %rbx
ret
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
pop    %rbx
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"fcntl failed\0A\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
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 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %26
13: ; preds = %1
%14 = load i32, i32* %3
%15 = load i32, i32* @O_NONBLOCK
%16 = or i32 %14, %15
store i32 %16, i32* %3
%17 = load i32, i32* %2
%18 = load i32, i32* @F_SETFL
%19 = load i32, i32* %3
%20 = call i64 (i32, i32, ...) @fcntl(i32 %17, i32 %18, i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %13
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %26
25: ; preds = %13
br label %26
26: ; preds = %25, %22, %10
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@stderr = global i32 0
@.str = [14 x i8] c"fcntl failed\0A\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
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 %12, label %6
6: ; preds = %1
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %7, %4
%9 = load i32, i32* @F_SETFL
%10 = tail call i64 (i32, i32, ...) @fcntl(i32 %0, i32 %9, i32 %8)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %6, %1
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %12, %6
ret void
}