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


x86 assembly (clang, -O0):
<tcp_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    114a <tcp_nonblock+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <tcp_nonblock+0x9a>
cmpl   $0x0,-0xc(%rbp)
je     1168 <tcp_nonblock+0x58>
mov    0x2e8d(%rip),%rax
mov    (%rax),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    117a <tcp_nonblock+0x6a>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11a3 <tcp_nonblock+0x93>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <tcp_nonblock+0x9a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp_nonblock>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2eb2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1160 <tcp_nonblock+0x50>
mov    0x2eb5(%rip),%rcx
mov    (%rcx),%edx
mov    %edx,%ecx
or     %eax,%ecx
not    %edx
and    %eax,%edx
test   %ebp,%ebp
cmovne %ecx,%edx
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <fcntl@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
sete   %al
neg    %eax
jmp    1165 <tcp_nonblock+0x55>
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 @tcp_nonblock(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 @fcntl(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %33
13: ; preds = %2
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* @O_NONBLOCK
%18 = load i32, i32* %6
%19 = or i32 %18, %17
store i32 %19, i32* %6
br label %25
20: ; preds = %13
%21 = load i32, i32* @O_NONBLOCK
%22 = xor i32 %21, -1
%23 = load i32, i32* %6
%24 = and i32 %23, %22
store i32 %24, i32* %6
br label %25
25: ; preds = %20, %16
%26 = load i32, i32* %4
%27 = load i32, i32* @F_SETFL
%28 = load i32, i32* %6
%29 = call i32 @fcntl(i32 %26, i32 %27, i32 %28)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %32
31: ; preds = %25
store i32 -1, i32* %3
br label %33
32: ; preds = %25
store i32 0, i32* %3
br label %33
33: ; preds = %32, %31, %12
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @tcp_nonblock(i32 %0, i32 %1) {
%3 = load i32, i32* @F_GETFL
%4 = tail call i32 @fcntl(i32 %0, i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %17, 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 = load i32, i32* @F_SETFL
%14 = tail call i32 @fcntl(i32 %0, i32 %13, i32 %12)
%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
}