#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*/ _exit(int);
int /*<<< orphan*/ errno;
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void set_nonblock(int sockfd) {
  int fl;
  if ((fl = fcntl(sockfd, F_GETFL, 0)) < 0) {
    fprintf(stderr, "Error getting filestatus flags: %s\n", strerror(errno));
    _exit(1);
  }
  if (fcntl(sockfd, F_SETFL, fl | O_NONBLOCK) < 0) {
    fprintf(stderr, "Error setting filestatus flags: %s\n", strerror(errno));
    _exit(1);
  }
}


x86 assembly (clang, -O0):
<set_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11a0 <set_nonblock+0x60>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%rdx
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    -0x4(%rbp),%edi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e32(%rip),%rax
or     (%rax),%edx
call   1040 <fcntl@plt>
cmp    $0x0,%eax
jge    11fc <set_nonblock+0xbc>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe37(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_nonblock>:
push   %rbx
mov    %edi,%ebx
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <fcntl@plt>
test   %eax,%eax
js     1178 <set_nonblock+0x38>
mov    0x2e72(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e81(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %eax,%edx
call   1040 <fcntl@plt>
test   %eax,%eax
js     1198 <set_nonblock+0x58>
pop    %rbx
ret
mov    0x2e59(%rip),%rax
mov    (%rax),%ebx
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe6a(%rip),%rsi
jmp    11b6 <set_nonblock+0x76>
mov    0x2e39(%rip),%rax
mov    (%rax),%ebx
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe6e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

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

LLVM IR (-O2):
@F_GETFL = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"Error getting filestatus flags: %s\0A\00"
@errno = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [36 x i8] c"Error setting filestatus flags: %s\0A\00"
define void @set_nonblock(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 @fcntl(i32 %0, i32 %2, i32 0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @_exit(i32 1)
unreachable
11: ; preds = %1
%12 = load i32, i32* @F_SETFL
%13 = load i32, i32* @O_NONBLOCK
%14 = or i32 %13, %3
%15 = tail call i32 @fcntl(i32 %0, i32 %12, i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = tail call i32 @_exit(i32 1)
unreachable
23: ; preds = %11
ret void
}