#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 blocking_mode(int fd, int blocking) {
  int flag = O_NONBLOCK;
  int new_mode, old_mode = fcntl(fd, F_GETFL, flag);
  if (blocking)
    new_mode = (old_mode & ~flag);
  else
    new_mode = (old_mode | flag);
  fcntl(fd, F_SETFL, new_mode);
  return (old_mode & flag) == 0;
}


x86 assembly (clang, -O0):
<blocking_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2ec3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
call   1030 <fcntl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     115e <blocking_mode+0x4e>
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    1167 <blocking_mode+0x57>
mov    -0x14(%rbp),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
call   1030 <fcntl@plt>
mov    -0x14(%rbp),%eax
and    -0xc(%rbp),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blocking_mode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
mov    0x2ec4(%rip),%rax
mov    (%rax),%ebx
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edx
call   1030 <fcntl@plt>
mov    %eax,%ebp
mov    %ebx,%eax
not    %eax
and    %ebp,%eax
mov    %ebp,%edx
or     %ebx,%edx
test   %r14d,%r14d
cmovne %eax,%edx
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1030 <fcntl@plt>
xor    %eax,%eax
test   %ebx,%ebp
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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