#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*/, ...);
void set_blocking(int fd) {
  int val;
  if ((val = fcntl(fd, F_GETFL)) == -1)
    return;
  if (val & O_NONBLOCK) {
    val &= ~O_NONBLOCK;
    fcntl(fd, F_SETFL, val);
  }
}


x86 assembly (clang, -O0):
<set_blocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    113f <set_blocking+0x2f>
jmp    117c <set_blocking+0x6c>
mov    -0x8(%rbp),%eax
mov    0x2e9f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     117c <set_blocking+0x6c>
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_blocking>:
push   %rbx
mov    %edi,%ebx
mov    0x2eb6(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     114e <set_blocking+0x3e>
mov    0x2eb9(%rip),%rcx
mov    (%rcx),%ecx
test   %eax,%ecx
je     114e <set_blocking+0x3e>
not    %ecx
and    %ecx,%eax
mov    0x2e98(%rip),%rcx
mov    (%rcx),%esi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
pop    %rbx
jmp    1030 <fcntl@plt>
pop    %rbx
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define void @set_blocking(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 %9
8: ; preds = %1
br label %23
9: ; preds = %1
%10 = load i32, i32* %3
%11 = load i32, i32* @O_NONBLOCK
%12 = and i32 %10, %11
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = load i32, i32* @O_NONBLOCK
%16 = xor i32 %15, -1
%17 = load i32, i32* %3
%18 = and i32 %17, %16
store i32 %18, i32* %3
%19 = load i32, i32* %2
%20 = load i32, i32* @F_SETFL
%21 = load i32, i32* %3
%22 = call i32 (i32, i32, ...) @fcntl(i32 %19, i32 %20, i32 %21)
br label %23
23: ; preds = %8, %14, %9
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define void @set_blocking(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 %14, 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 %14, label %9
9: ; preds = %5
%10 = xor i32 %6, -1
%11 = and i32 %3, %10
%12 = load i32, i32* @F_SETFL
%13 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %12, i32 %11)
br label %14
14: ; preds = %5, %9, %1
ret void
}