#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 (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    121f <anetSetBlock+0xef>
cmpl   $0x0,-0x18(%rbp)
je     11b3 <anetSetBlock+0x83>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11c5 <anetSetBlock+0x95>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    1218 <anetSetBlock+0xe8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
lea    0xe0c(%rip),%rsi
call   1040 <anetSetError@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121f <anetSetBlock+0xef>
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,%ebx
mov    %rdi,%r14
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     118f <anetSetBlock+0x5f>
mov    0x2e89(%rip),%rcx
mov    (%rcx),%edx
mov    %edx,%ecx
or     %eax,%ecx
not    %edx
and    %eax,%edx
test   %r15d,%r15d
cmovne %ecx,%edx
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11b6 <anetSetBlock+0x86>
lea    0xe86(%rip),%rbx
jmp    1196 <anetSetBlock+0x66>
lea    0xe6a(%rip),%rbx
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <anetSetError@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%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 %42
18: ; preds = %3
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i32, i32* @O_NONBLOCK
%23 = load i32, i32* %8
%24 = or i32 %23, %22
store i32 %24, i32* %8
br label %30
25: ; preds = %18
%26 = load i32, i32* @O_NONBLOCK
%27 = xor i32 %26, -1
%28 = load i32, i32* %8
%29 = and i32 %28, %27
store i32 %29, i32* %8
br label %30
30: ; preds = %25, %21
%31 = load i32, i32* %6
%32 = load i32, i32* @F_SETFL
%33 = load i32, i32* %8
%34 = call i32 (i32, i32, ...) @fcntl(i32 %31, i32 %32, i32 %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %41
36: ; preds = %30
%37 = load i8*, i8** %5
%38 = load i32, i32* @errno
%39 = call i32 @strerror(i32 %38)
%40 = call i32 @anetSetError(i8* %37, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %39)
store i32 -1, i32* %4
br label %42
41: ; preds = %30
store i32 0, i32* %4
br label %42
42: ; preds = %41, %36, %13
%43 = load i32, i32* %4
ret i32 %43
}

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 %17, 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
br i1 %16, label %17, label %22
17: ; preds = %7, %3
%18 = 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), %7 ]
%19 = load i32, i32* @errno
%20 = tail call i32 @strerror(i32 %19)
%21 = tail call i32 @anetSetError(i8* %0, i8* %18, i32 %20)
br label %22
22: ; preds = %17, %7
%23 = phi i32 [ 0, %7 ], [ -1, %17 ]
ret i32 %23
}