#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 /*<<< orphan*/ LOG_ERR;
int O_NONBLOCK;
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ fs_log(int /*<<< orphan*/, char *);
void setnonblocking(int fd) {
  int flag = 0;
  flag = fcntl(fd, F_GETFL, 0);
  if (flag == -1) {
    fs_log(LOG_ERR, "fcntl F_GETFL");
    return;
  }
  if (fcntl(fd, F_SETFL, flag | O_NONBLOCK) == -1) {
    fs_log(LOG_ERR, "fcntl F_SETFL: O_NONBLOCK");
    return;
  }
}


x86 assembly (clang, -O0):
<setnonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    116c <setnonblocking+0x4c>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
call   1040 <fs_log@plt>
jmp    11a7 <setnonblocking+0x87>
mov    -0x4(%rbp),%edi
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e66(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11a7 <setnonblocking+0x87>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1040 <fs_log@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setnonblocking>:
push   %rbx
mov    %edi,%ebx
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     115a <setnonblocking+0x3a>
mov    0x2e99(%rip),%rcx
mov    (%rcx),%esi
mov    0x2ea0(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1163 <setnonblocking+0x43>
pop    %rbx
ret
lea    0xe9f(%rip),%rsi
jmp    116a <setnonblocking+0x4a>
lea    0xea4(%rip),%rsi
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
pop    %rbx
jmp    1040 <fs_log@plt>

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

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