#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 F_GETFL;
int O_NONBLOCK;
int fcntl(int, int);
int ez_setsockblock(int _fd, int _blocking) {
  int flags = 0;
  if ((flags = fcntl(_fd, F_GETFL)) == -1)
    return 0;
  if (_blocking)
    flags |= O_NONBLOCK;
  else
    flags &= ~O_NONBLOCK;
  if (fcntl(_fd, flags) == -1)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<ez_setsockblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    114e <ez_setsockblock+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <ez_setsockblock+0x95>
cmpl   $0x0,-0xc(%rbp)
je     116c <ez_setsockblock+0x5c>
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    117e <ez_setsockblock+0x6e>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    119e <ez_setsockblock+0x8e>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <ez_setsockblock+0x95>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ez_setsockblock>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2eba(%rip),%rax
mov    (%rax),%esi
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1153 <ez_setsockblock+0x43>
mov    0x2eb7(%rip),%rcx
mov    (%rcx),%esi
mov    %esi,%ecx
or     %eax,%ecx
not    %esi
and    %eax,%esi
test   %ebp,%ebp
cmovne %ecx,%esi
mov    %ebx,%edi
call   1030 <fcntl@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
setne  %al
jmp    1155 <ez_setsockblock+0x45>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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