#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 tcpSetBlock(char *err, int fd, int non_block) {
  int flags;
  if ((flags = fcntl(fd, F_GETFL)) == -1) {
    return -1;
  }
  if (non_block)
    flags |= O_NONBLOCK;
  else
    flags &= ~O_NONBLOCK;
  if (fcntl(fd, F_SETFL, flags) == -1) {
    return -1;
  }
  return 1;
}


x86 assembly (clang, -O0):
<tcpSetBlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    114d <tcpSetBlock+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <tcpSetBlock+0x9f>
cmpl   $0x0,-0x18(%rbp)
je     116b <tcpSetBlock+0x5b>
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    117d <tcpSetBlock+0x6d>
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11a8 <tcpSetBlock+0x98>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <tcpSetBlock+0x9f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcpSetBlock>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %esi,%ebx
mov    0x2eb2(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1166 <tcpSetBlock+0x56>
mov    0x2eb3(%rip),%rcx
mov    (%rcx),%edx
mov    %edx,%ecx
or     %eax,%ecx
not    %edx
and    %eax,%edx
test   %ebp,%ebp
cmovne %ecx,%edx
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
setne  %cl
lea    (%rcx,%rcx,1),%eax
add    $0xffffffff,%eax
jmp    116b <tcpSetBlock+0x5b>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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