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


x86 assembly (clang, -O0):
<setnonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1163 <setnonblocking+0x43>
lea    0xeae(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b1 <setnonblocking+0x91>
mov    -0xc(%rbp),%eax
mov    0x2e7b(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    11aa <setnonblocking+0x8a>
lea    0xe77(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b1 <setnonblocking+0x91>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setnonblocking>:
push   %rbx
mov    %edi,%ebx
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     1163 <setnonblocking+0x43>
mov    0x2eaa(%rip),%rcx
or     (%rcx),%eax
mov    0x2e91(%rip),%rcx
mov    (%rcx),%esi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
js     116c <setnonblocking+0x4c>
pop    %rbx
ret
lea    0xe96(%rip),%rdi
jmp    1173 <setnonblocking+0x53>
lea    0xe9d(%rip),%rdi
call   1040 <perror@plt>
xor    %eax,%eax
pop    %rbx
ret

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 i32 @setnonblocking(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = load i32, i32* @F_GETFL
%7 = call i64 (i32, i32, ...) @fcntl(i32 %5, i32 %6)
%8 = trunc i64 %7 to i32
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %25
13: ; preds = %1
%14 = load i32, i32* %4
%15 = load i32, i32* @O_NONBLOCK
%16 = or i32 %14, %15
store i32 %16, i32* %4
%17 = load i32, i32* %3
%18 = load i32, i32* @F_SETFL
%19 = load i32, i32* %4
%20 = call i64 (i32, i32, ...) @fcntl(i32 %17, i32 %18, i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %13
%23 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %2
br label %25
24: ; preds = %13
store i32 1, i32* %2
br label %25
25: ; preds = %24, %22, %11
%26 = load i32, i32* %2
ret i32 %26
}

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 i32 @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 %12, label %6
6: ; preds = %1
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %7, %4
%9 = load i32, i32* @F_SETFL
%10 = tail call i64 (i32, i32, ...) @fcntl(i32 %0, i32 %9, i32 %8)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %6, %1
%13 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), %6 ]
%14 = tail call i32 @perror(i8* %13)
br label %15
15: ; preds = %12, %6
%16 = phi i32 [ 1, %6 ], [ 0, %12 ]
ret i32 %16
}