#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 fcntl(int, int /*<<< orphan*/, int);
int make_socket_nonblocking(int fd) {
  int flags;
  if ((flags = fcntl(fd, F_GETFL, NULL)) < 0) {
    return -1;
  }
  if (!(flags & O_NONBLOCK)) {
    if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<make_socket_nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1146 <make_socket_nonblocking+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <make_socket_nonblocking+0x89>
mov    -0xc(%rbp),%eax
mov    0x2e98(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1192 <make_socket_nonblocking+0x82>
mov    -0x8(%rbp),%edi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e77(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    118d <make_socket_nonblocking+0x7d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1199 <make_socket_nonblocking+0x89>
jmp    1192 <make_socket_nonblocking+0x82>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_socket_nonblocking>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2eb4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     1154 <make_socket_nonblocking+0x44>
mov    0x2eb3(%rip),%rcx
mov    (%rcx),%edx
test   %eax,%edx
jne    1152 <make_socket_nonblocking+0x42>
mov    0x2e96(%rip),%rcx
mov    (%rcx),%esi
or     %eax,%edx
mov    %ebp,%edi
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1154 <make_socket_nonblocking+0x44>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @make_socket_nonblocking(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 %15, label %5
5: ; preds = %1
%6 = load i32, i32* @O_NONBLOCK
%7 = and i32 %6, %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %5
%10 = load i32, i32* @F_SETFL
%11 = or i32 %6, %3
%12 = tail call i32 @fcntl(i32 %0, i32 %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %15, label %14
14: ; preds = %9, %5
br label %15
15: ; preds = %9, %1, %14
%16 = phi i32 [ 0, %14 ], [ -1, %1 ], [ -1, %9 ]
ret i32 %16
}