#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*/ errx(int, char *, int /*<<< orphan*/);
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void nonblocking(int fd) {
  int flags;
  flags = fcntl(fd, F_GETFL, 0);
  if (flags == -1)
    errx(1, "fcntl: %s", strerror(errno));
  flags |= O_NONBLOCK;
  if (fcntl(fd, F_SETFL, flags) == -1)
    errx(1, "fcntl: %s", strerror(errno));
}


x86 assembly (clang, -O0):
<nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    117c <nonblocking+0x4c>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%edx
mov    $0x1,%edi
lea    0xe89(%rip),%rsi
call   1040 <errx@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11c9 <nonblocking+0x99>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%edx
mov    $0x1,%edi
lea    0xe3c(%rip),%rsi
call   1040 <errx@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nonblocking>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    116d <nonblocking+0x3d>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe9f(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
call   1040 <errx@plt>
mov    0x2e74(%rip),%rax
mov    (%rax),%edx
or     %ebp,%edx
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1194 <nonblocking+0x64>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe57(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <errx@plt>

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

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