#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int const O_NONBLOCK;
int fcntl(int, int /*<<< orphan*/, ...);
int SetNonBlocking(int socket) {
  const int flags = fcntl(socket, F_GETFL);
  if (flags < 0)
    return -EXIT_FAILURE;
  if (-1 == fcntl(socket, F_SETFL, flags | O_NONBLOCK))
    return -EXIT_FAILURE;
  return -EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<SetNonBlocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    114e <SetNonBlocking+0x3e>
xor    %eax,%eax
mov    0x2e84(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    119d <SetNonBlocking+0x8d>
mov    -0x8(%rbp),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e84(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    118f <SetNonBlocking+0x7f>
xor    %eax,%eax
mov    0x2e43(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    119d <SetNonBlocking+0x8d>
xor    %eax,%eax
mov    0x2e28(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetNonBlocking>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2ebc(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     1144 <SetNonBlocking+0x34>
mov    0x2eae(%rip),%rcx
mov    (%rcx),%esi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    114d <SetNonBlocking+0x3d>
mov    0x2e85(%rip),%rax
jmp    1154 <SetNonBlocking+0x44>
mov    0x2e74(%rip),%rax
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@EXIT_FAILURE = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = constant i32 0
@EXIT_SUCCESS = global i32 0
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 i32 (i32, i32, ...) @fcntl(i32 %5, i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @EXIT_FAILURE
%12 = sub nsw i32 0, %11
store i32 %12, i32* %2
br label %27
13: ; preds = %1
%14 = load i32, i32* %3
%15 = load i32, i32* @F_SETFL
%16 = load i32, i32* %4
%17 = load i32, i32* @O_NONBLOCK
%18 = or i32 %16, %17
%19 = call i32 (i32, i32, ...) @fcntl(i32 %14, i32 %15, i32 %18)
%20 = icmp eq i32 -1, %19
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = load i32, i32* @EXIT_FAILURE
%23 = sub nsw i32 0, %22
store i32 %23, i32* %2
br label %27
24: ; preds = %13
%25 = load i32, i32* @EXIT_SUCCESS
%26 = sub nsw i32 0, %25
store i32 %26, i32* %2
br label %27
27: ; preds = %24, %21, %10
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@EXIT_FAILURE = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = constant i32 0
@EXIT_SUCCESS = global i32 0
define i32 @SetNonBlocking(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %1
%6 = load i32, i32* @F_SETFL
%7 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %6, i32 %3)
%8 = icmp eq i32 %7, -1
%9 = select i1 %8, i32* @EXIT_FAILURE, i32* @EXIT_SUCCESS
br label %10
10: ; preds = %5, %1
%11 = phi i32* [ @EXIT_FAILURE, %1 ], [ %9, %5 ]
%12 = load i32, i32* %11
%13 = sub nsw i32 0, %12
ret i32 %13
}