#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 /*<<< orphan*/ perror(char *);
int set_socket_to_non_block(int socket_fd) {
  int flag_for_fd = 0;
  if ((flag_for_fd = fcntl(socket_fd, F_GETFL, 0)) == -1) {
    perror("Server: Unable to get socket flags.");
    return -1;
  }
  if (fcntl(socket_fd, F_SETFL, flag_for_fd | O_NONBLOCK) == -1) {
    perror("Server: Unable to set socket to non-blocking.");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_socket_to_non_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    1169 <set_socket_to_non_block+0x49>
lea    0xea8(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <set_socket_to_non_block+0x8e>
mov    -0x8(%rbp),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e69(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11a7 <set_socket_to_non_block+0x87>
lea    0xe8e(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <set_socket_to_non_block+0x8e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_socket_to_non_block>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1165 <set_socket_to_non_block+0x45>
mov    0x2e95(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e9c(%rip),%rcx
or     (%rcx),%eax
mov    %ebp,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     116e <set_socket_to_non_block+0x4e>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe94(%rip),%rdi
jmp    1175 <set_socket_to_non_block+0x55>
lea    0xeaf(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebx
jmp    115c <set_socket_to_non_block+0x3c>

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [36 x i8] c"Server: Unable to get socket flags.\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [46 x i8] c"Server: Unable to set socket to non-blocking.\00"
define i32 @set_socket_to_non_block(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
%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 eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %22
11: ; preds = %1
%12 = load i32, i32* %3
%13 = load i32, i32* @F_SETFL
%14 = load i32, i32* %4
%15 = load i32, i32* @O_NONBLOCK
%16 = or i32 %14, %15
%17 = call i32 @fcntl(i32 %12, i32 %13, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %22
21: ; preds = %11
store i32 0, i32* %2
br label %22
22: ; preds = %21, %19, %9
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [36 x i8] c"Server: Unable to get socket flags.\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [46 x i8] c"Server: Unable to set socket to non-blocking.\00"
define i32 @set_socket_to_non_block(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* @F_SETFL
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %7, %3
%9 = tail call i32 @fcntl(i32 %0, i32 %6, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %5, %1
%12 = phi i8* [ getelementptr inbounds ([36 x i8], [36 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 @perror(i8* %12)
br label %14
14: ; preds = %11, %5
%15 = phi i32 [ 0, %5 ], [ -1, %11 ]
ret i32 %15
}