#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 /*<<< orphan*/ anetSetError(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int fcntl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int anetSetBlock(char *err, int fd, int non_block) {
  int flags;
  if ((flags = fcntl(fd, F_GETFL)) == -1) {
    anetSetError(err, "fcntl(F_GETFL): %s", strerror(errno));
    return -1;
  }
  if (!!(flags & O_NONBLOCK) == !!non_block)
    return 0;
  if (non_block)
    flags |= O_NONBLOCK;
  else
    flags &= ~O_NONBLOCK;
  if (fcntl(fd, F_SETFL, flags) == -1) {
    anetSetError(err, "fcntl(F_SETFL,O_NONBLOCK): %s", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<anetSetBlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1195 <anetSetBlock+0x65>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
lea    0xe7c(%rip),%rsi
call   1040 <anetSetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1261 <anetSetBlock+0x131>
mov    -0x1c(%rbp),%eax
mov    0x2e49(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x0,-0x18(%rbp)
setne  %cl
xor    $0xff,%cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
cmp    %ecx,%eax
jne    11d7 <anetSetBlock+0xa7>
movl   $0x0,-0x4(%rbp)
jmp    1261 <anetSetBlock+0x131>
cmpl   $0x0,-0x18(%rbp)
je     11f5 <anetSetBlock+0xc5>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1207 <anetSetBlock+0xd7>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2dc7(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    125a <anetSetBlock+0x12a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xdca(%rip),%rsi
call   1040 <anetSetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1261 <anetSetBlock+0x131>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<anetSetBlock>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     11a2 <anetSetBlock+0x72>
mov    0x2e89(%rip),%rcx
mov    (%rcx),%edx
test   %eax,%edx
sete   %sil
test   %r15d,%r15d
setne  %cl
xor    %sil,%cl
jne    11c9 <anetSetBlock+0x99>
mov    %edx,%ecx
or     %eax,%ecx
not    %edx
and    %eax,%edx
test   %r15d,%r15d
cmovne %ecx,%edx
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11c9 <anetSetBlock+0x99>
lea    0xe73(%rip),%rbx
jmp    11a9 <anetSetBlock+0x79>
lea    0xe57(%rip),%rbx
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <anetSetError@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [19 x i8] c"fcntl(F_GETFL): %s\00"
@errno = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.1 = [30 x i8] c"fcntl(F_SETFL,O_NONBLOCK): %s\00"
define i32 @anetSetBlock(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 %18
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load i32, i32* @errno
%16 = call i32 @strerror(i32 %15)
%17 = call i32 @anetSetError(i8* %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 -1, i32* %4
br label %57
18: ; preds = %3
%19 = load i32, i32* %8
%20 = load i32, i32* @O_NONBLOCK
%21 = and i32 %19, %20
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
%24 = xor i1 %23, true
%25 = zext i1 %24 to i32
%26 = load i32, i32* %7
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
%29 = xor i1 %28, true
%30 = zext i1 %29 to i32
%31 = icmp eq i32 %25, %30
br i1 %31, label %32, label %33
32: ; preds = %18
store i32 0, i32* %4
br label %57
33: ; preds = %18
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i32, i32* @O_NONBLOCK
%38 = load i32, i32* %8
%39 = or i32 %38, %37
store i32 %39, i32* %8
br label %45
40: ; preds = %33
%41 = load i32, i32* @O_NONBLOCK
%42 = xor i32 %41, -1
%43 = load i32, i32* %8
%44 = and i32 %43, %42
store i32 %44, i32* %8
br label %45
45: ; preds = %40, %36
%46 = load i32, i32* %6
%47 = load i32, i32* @F_SETFL
%48 = load i32, i32* %8
%49 = call i32 (i32, i32, ...) @fcntl(i32 %46, i32 %47, i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %56
51: ; preds = %45
%52 = load i8*, i8** %5
%53 = load i32, i32* @errno
%54 = call i32 @strerror(i32 %53)
%55 = call i32 @anetSetError(i8* %52, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %54)
store i32 -1, i32* %4
br label %57
56: ; preds = %45
store i32 0, i32* %4
br label %57
57: ; preds = %56, %51, %32, %13
%58 = load i32, i32* %4
ret i32 %58
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [19 x i8] c"fcntl(F_GETFL): %s\00"
@errno = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
@.str.1 = [30 x i8] c"fcntl(F_SETFL,O_NONBLOCK): %s\00"
define i32 @anetSetBlock(i8* %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 %21, label %7
7: ; preds = %3
%8 = load i32, i32* @O_NONBLOCK
%9 = and i32 %8, %5
%10 = icmp eq i32 %9, 0
%11 = icmp ne i32 %2, 0
%12 = xor i1 %11, %10
br i1 %12, label %26, label %13
13: ; preds = %7
%14 = or i32 %8, %5
%15 = xor i32 %8, -1
%16 = and i32 %5, %15
%17 = select i1 %11, i32 %14, i32 %16
%18 = load i32, i32* @F_SETFL
%19 = tail call i32 (i32, i32, ...) @fcntl(i32 %1, i32 %18, i32 %17)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %26
21: ; preds = %13, %3
%22 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), %13 ]
%23 = load i32, i32* @errno
%24 = tail call i32 @strerror(i32 %23)
%25 = tail call i32 @anetSetError(i8* %0, i8* %22, i32 %24)
br label %26
26: ; preds = %21, %13, %7
%27 = phi i32 [ 0, %7 ], [ 0, %13 ], [ -1, %21 ]
ret i32 %27
}