#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 /*<<< orphan*/ throw(char *);
void set_nonblocking(int socket_fd) {
  int flags;
  if ((flags = fcntl(socket_fd, F_GETFL)) == -1) {
    throw("Error getting socket flags to unblock\n");
  }
  flags |= O_NONBLOCK;
  if (fcntl(socket_fd, F_SETFL, flags) == -1) {
    throw("Error setting socket flags to unblock\n");
  }
}


x86 assembly (clang, -O0):
<set_nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1156 <set_nonblocking+0x36>
lea    0xeaf(%rip),%rdi
call   1040 <throw@plt>
mov    0x2e8b(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    1190 <set_nonblocking+0x70>
lea    0xe9c(%rip),%rdi
call   1040 <throw@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_nonblocking>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1148 <set_nonblocking+0x28>
lea    0xebd(%rip),%rdi
call   1040 <throw@plt>
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
or     %ebp,%edx
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1171 <set_nonblocking+0x51>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xeaf(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <throw@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [39 x i8] c"Error getting socket flags to unblock\0A\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.1 = [39 x i8] c"Error setting socket flags to unblock\0A\00"
define void @set_nonblocking(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 (i32, i32, ...) @fcntl(i32 %4, i32 %5)
store i32 %6, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @throw(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = load i32, i32* @O_NONBLOCK
%12 = load i32, i32* %3
%13 = or i32 %12, %11
store i32 %13, i32* %3
%14 = load i32, i32* %2
%15 = load i32, i32* @F_SETFL
%16 = load i32, i32* %3
%17 = call i32 (i32, i32, ...) @fcntl(i32 %14, i32 %15, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %10
%20 = call i32 @throw(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %10
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [39 x i8] c"Error getting socket flags to unblock\0A\00"
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.1 = [39 x i8] c"Error setting socket flags to unblock\0A\00"
define void @set_nonblocking(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @throw(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %1
%8 = load i32, i32* @O_NONBLOCK
%9 = or i32 %8, %3
%10 = load i32, i32* @F_SETFL
%11 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %10, i32 %9)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %7
%14 = tail call i32 @throw(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %7
ret void
}