#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
int fcntl(int, int /*<<< orphan*/, int);
int fileno(int /*<<< orphan*/ *);
void slave_set_blocking_io(FILE *f, int enable) {
  int fd = fileno(f);
  int flags = fcntl(fd, F_GETFL, 0);
  if (enable) {
    flags &= ~O_NONBLOCK;
  } else {
    flags |= O_NONBLOCK;
  }
  fcntl(fd, F_SETFL, flags);
}


x86 assembly (clang, -O0):
<slave_set_blocking_io>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fileno@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1172 <slave_set_blocking_io+0x52>
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1181 <slave_set_blocking_io+0x61>
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
call   1030 <fcntl@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slave_set_blocking_io>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
call   1040 <fileno@plt>
mov    %eax,%ebp
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    0x2ea3(%rip),%rcx
mov    (%rcx),%edx
mov    %edx,%ecx
not    %ecx
and    %eax,%ecx
or     %eax,%edx
test   %ebx,%ebx
cmovne %ecx,%edx
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fcntl@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define void @slave_set_blocking_io(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32*, i32** %3
%8 = call i32 @fileno(i32* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = load i32, i32* @F_GETFL
%11 = call i32 @fcntl(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %6
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @O_NONBLOCK
%16 = xor i32 %15, -1
%17 = load i32, i32* %6
%18 = and i32 %17, %16
store i32 %18, i32* %6
br label %23
19: ; preds = %2
%20 = load i32, i32* @O_NONBLOCK
%21 = load i32, i32* %6
%22 = or i32 %21, %20
store i32 %22, i32* %6
br label %23
23: ; preds = %19, %14
%24 = load i32, i32* %5
%25 = load i32, i32* @F_SETFL
%26 = load i32, i32* %6
%27 = call i32 @fcntl(i32 %24, i32 %25, i32 %26)
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define void @slave_set_blocking_io(i32* nocapture %0, i32 %1) {
%3 = tail call i32 @fileno(i32* %0)
%4 = load i32, i32* @F_GETFL
%5 = tail call i32 @fcntl(i32 %3, i32 %4, i32 0)
%6 = icmp eq i32 %1, 0
%7 = load i32, i32* @O_NONBLOCK
%8 = xor i32 %7, -1
%9 = and i32 %5, %8
%10 = or i32 %7, %5
%11 = select i1 %6, i32 %10, i32 %9
%12 = load i32, i32* @F_SETFL
%13 = tail call i32 @fcntl(i32 %3, i32 %12, i32 %11)
ret void
}