#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 setblock(int fd, int block) {
  int f;
  if ((f = fcntl(fd, F_GETFL)) == -1 ||
      fcntl(fd, F_SETFL, block ? (f & ~O_NONBLOCK) : (f | O_NONBLOCK)) == -1)
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<setblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
je     119a <setblock+0x8a>
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1172 <setblock+0x62>
mov    -0x10(%rbp),%eax
mov    0x2e85(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    1181 <setblock+0x71>
mov    -0x10(%rbp),%eax
mov    0x2e6c(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11a6 <setblock+0x96>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ad <setblock+0x9d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setblock>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2eb2(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1162 <setblock+0x52>
mov    0x2ea5(%rip),%rcx
mov    (%rcx),%esi
mov    0x2eac(%rip),%rcx
mov    (%rcx),%edx
mov    %edx,%ecx
not    %ecx
and    %eax,%ecx
or     %eax,%edx
test   %ebp,%ebp
cmovne %ecx,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
sete   %al
neg    %eax
jmp    1167 <setblock+0x57>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @setblock(i32 %0, i32 %1) {
%3 = load i32, i32* @F_GETFL
%4 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %17, label %6
6: ; preds = %2
%7 = load i32, i32* @F_SETFL
%8 = icmp eq i32 %1, 0
%9 = load i32, i32* @O_NONBLOCK
%10 = xor i32 %9, -1
%11 = and i32 %4, %10
%12 = or i32 %9, %4
%13 = select i1 %8, i32 %12, i32 %11
%14 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %7, i32 %13)
%15 = icmp eq i32 %14, -1
%16 = sext i1 %15 to i32
br label %17
17: ; preds = %6, %2
%18 = phi i32 [ -1, %2 ], [ %16, %6 ]
ret i32 %18
}