#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;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int fcntl(int, int /*<<< orphan*/, ...);
void file_set_nonblock(int fd) {
  int val;
  val = fcntl(fd, F_GETFL);
  if (val == -1)
    error(1, errno, "fctnl get");
  val |= O_NONBLOCK;
  if (fcntl(fd, F_SETFL, val) == -1)
    error(1, errno, "fcntl set");
}


x86 assembly (clang, -O0):
<file_set_nonblock>:
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   $0xffffffff,-0x8(%rbp)
jne    1165 <file_set_nonblock+0x45>
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xea0(%rip),%rdx
call   1040 <error@plt>
mov    0x2e7c(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11ad <file_set_nonblock+0x8d>
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe62(%rip),%rdx
call   1040 <error@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_set_nonblock>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1156 <file_set_nonblock+0x36>
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    0xeb4(%rip),%rdx
mov    $0x1,%edi
call   1040 <error@plt>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edx
or     %ebp,%edx
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     117f <file_set_nonblock+0x5f>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e4a(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdx
mov    $0x1,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <error@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@errno = global i32 0
@.str = [10 x i8] c"fctnl get\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.1 = [10 x i8] c"fcntl set\00"
define void @file_set_nonblock(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 i32 (i32, i32, ...) @fcntl(i32 %4, i32 %5)
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* @errno
%11 = call i32 @error(i32 1, i32 %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %9, %1
%13 = load i32, i32* @O_NONBLOCK
%14 = load i32, i32* %3
%15 = or i32 %14, %13
store i32 %15, i32* %3
%16 = load i32, i32* %2
%17 = load i32, i32* @F_SETFL
%18 = load i32, i32* %3
%19 = call i32 (i32, i32, ...) @fcntl(i32 %16, i32 %17, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = load i32, i32* @errno
%23 = call i32 @error(i32 1, i32 %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %21, %12
ret void
}

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