#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 /*<<< orphan*/ LOG_print(char *, int);
int O_NONBLOCK;
int fcntl(int, int /*<<< orphan*/, int);
int _SOCKET_set_nonblock(int socket_fd) {
  int ret;
  int flags = 0;
  flags = fcntl(socket_fd, F_GETFL, 0);
  if (flags == (-1)) {
    LOG_print("Error: unable to get flags from socket %d.\n", socket_fd);
    return -1;
  }
  flags |= O_NONBLOCK;
  ret = fcntl(socket_fd, F_SETFL, flags);
  if (ret == -1) {
    LOG_print("Error: unable to set non-bocking socket: %d.\n", socket_fd);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_SOCKET_set_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    116d <_SOCKET_set_nonblock+0x4d>
mov    -0x8(%rbp),%esi
lea    0xea4(%rip),%rdi
call   1040 <LOG_print@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <_SOCKET_set_nonblock+0x9f>
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11b8 <_SOCKET_set_nonblock+0x98>
mov    -0x8(%rbp),%esi
lea    0xe85(%rip),%rdi
call   1040 <LOG_print@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bf <_SOCKET_set_nonblock+0x9f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_SOCKET_set_nonblock>:
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
je     1165 <_SOCKET_set_nonblock+0x45>
mov    0x2ea5(%rip),%rcx
or     (%rcx),%eax
mov    0x2e8c(%rip),%rcx
mov    (%rcx),%esi
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    1178 <_SOCKET_set_nonblock+0x58>
lea    0xec9(%rip),%rdi
jmp    116c <_SOCKET_set_nonblock+0x4c>
lea    0xe94(%rip),%rdi
mov    %ebx,%esi
call   1040 <LOG_print@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [44 x i8] c"Error: unable to get flags from socket %d.\0A\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.1 = [46 x i8] c"Error: unable to set non-bocking socket: %d.\0A\00"
define i32 @_SOCKET_set_nonblock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = load i32, i32* @F_GETFL
%8 = call i32 @fcntl(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* %3
%13 = call i32 @LOG_print(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 -1, i32* %2
br label %28
14: ; preds = %1
%15 = load i32, i32* @O_NONBLOCK
%16 = load i32, i32* %5
%17 = or i32 %16, %15
store i32 %17, i32* %5
%18 = load i32, i32* %3
%19 = load i32, i32* @F_SETFL
%20 = load i32, i32* %5
%21 = call i32 @fcntl(i32 %18, i32 %19, i32 %20)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %14
%25 = load i32, i32* %3
%26 = call i32 @LOG_print(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %25)
store i32 -1, i32* %2
br label %28
27: ; preds = %14
store i32 0, i32* %2
br label %28
28: ; preds = %27, %24, %11
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [44 x i8] c"Error: unable to get flags from socket %d.\0A\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.1 = [46 x i8] c"Error: unable to set non-bocking socket: %d.\0A\00"
define i32 @_SOCKET_set_nonblock(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
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = load i32, i32* @O_NONBLOCK
%7 = or i32 %6, %3
%8 = load i32, i32* @F_SETFL
%9 = tail call i32 @fcntl(i32 %0, i32 %8, i32 %7)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %5, %1
%12 = phi i8* [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), %5 ]
%13 = tail call i32 @LOG_print(i8* %12, i32 %0)
br label %14
14: ; preds = %11, %5
%15 = phi i32 [ 0, %5 ], [ -1, %11 ]
ret i32 %15
}