#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);
scalar_t__ fcntl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ perror(char *);
void setnonblocking(int sockfd) {
  int opts;
  opts = fcntl(sockfd, F_GETFL);
  if (opts < 0) {
    perror("fcntl(F_GETFL)\n");
    exit(1);
  }
  opts = (opts | O_NONBLOCK);
  if (fcntl(sockfd, F_SETFL, opts) < 0) {
    perror("fcntl(F_SETFL)\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<setnonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1171 <setnonblocking+0x41>
lea    0xe9e(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%eax
mov    0x2e6d(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    11b6 <setnonblocking+0x86>
lea    0xe69(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setnonblocking>:
push   %rbx
mov    %edi,%ebx
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     116b <setnonblocking+0x3b>
mov    0x2e9a(%rip),%rcx
or     (%rcx),%eax
mov    0x2e81(%rip),%rcx
mov    (%rcx),%esi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %rax,%rax
js     1174 <setnonblocking+0x44>
pop    %rbx
ret
lea    0xe8e(%rip),%rdi
jmp    117b <setnonblocking+0x4b>
lea    0xe95(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [16 x i8] c"fcntl(F_GETFL)\0A\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.1 = [16 x i8] c"fcntl(F_SETFL)\0A\00"
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 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
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 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %13
ret void
}

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