#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*/ error(char *);
int fcntl(int, int /*<<< orphan*/, int);
void set_non_blocking(int sockfd) {
  int flags;
  if ((flags = fcntl(sockfd, F_GETFL, 0)) == -1)
    flags = 0;
  if (fcntl(sockfd, F_SETFL, flags | O_NONBLOCK) != 0)
    error("fcntl");
}


x86 assembly (clang, -O0):
<set_non_blocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1151 <set_non_blocking+0x31>
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e81(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%eax
je     1183 <set_non_blocking+0x63>
lea    0xe82(%rip),%rdi
call   1040 <error@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_non_blocking>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
cmovne %eax,%ebp
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
mov    0x2e9b(%rip),%rax
or     (%rax),%ebp
mov    %ebx,%edi
mov    %ebp,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
je     116e <set_non_blocking+0x4e>
lea    0xe9d(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <error@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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