#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 /*<<< orphan*/ die(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int fcntl(int, int /*<<< orphan*/, int);
void set_noblock(int sock_fd) {
  int flags;
  if ((flags = fcntl(sock_fd, F_GETFL, 0)) < 0) {
    die("get flags", errno);
  }
  if (fcntl(sock_fd, F_SETFL, flags & ~O_NONBLOCK) < 0) {
    die("set blocking", errno);
  }
}


x86 assembly (clang, -O0):
<set_noblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    115f <set_noblock+0x3f>
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    0xea6(%rip),%rdi
call   1040 <die@plt>
mov    -0x4(%rbp),%edi
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
call   1030 <fcntl@plt>
cmp    $0x0,%eax
jge    119f <set_noblock+0x7f>
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1040 <die@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_noblock>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1150 <set_noblock+0x30>
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
lea    0xeb5(%rip),%rdi
call   1040 <die@plt>
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,%ebp
mov    %ebx,%edi
mov    %ebp,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
js     117a <set_noblock+0x5a>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    0xe80(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <die@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [10 x i8] c"get flags\00"
@errno = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [13 x i8] c"set blocking\00"
define void @set_noblock(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 @fcntl(i32 %4, i32 %5, i32 0)
store i32 %6, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = call i32 @die(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %8, %1
%12 = load i32, i32* %2
%13 = load i32, i32* @F_SETFL
%14 = load i32, i32* %3
%15 = load i32, i32* @O_NONBLOCK
%16 = xor i32 %15, -1
%17 = and i32 %14, %16
%18 = call i32 @fcntl(i32 %12, i32 %13, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %11
%21 = load i32, i32* @errno
%22 = call i32 @die(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %20, %11
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [10 x i8] c"get flags\00"
@errno = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [13 x i8] c"set blocking\00"
define void @set_noblock(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 %5, label %8
5: ; preds = %1
%6 = load i32, i32* @errno
%7 = tail call i32 @die(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %8
8: ; preds = %5, %1
%9 = load i32, i32* @F_SETFL
%10 = load i32, i32* @O_NONBLOCK
%11 = xor i32 %10, -1
%12 = and i32 %3, %11
%13 = tail call i32 @fcntl(i32 %0, i32 %9, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = load i32, i32* @errno
%17 = tail call i32 @die(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %8
ret void
}