#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_NDELAY;
int O_NONBLOCK;
scalar_t__ fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int ce_set_nonblock(int fd) {
  int flags;
  flags = fcntl(fd, F_GETFL, 0);
  flags |= O_NONBLOCK;
  flags |= O_NDELAY;
  if (fcntl(fd, F_SETFL, flags) != 0) {
    printf("ERROR: Failed to set fd %d to nonblock\n", fd);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ce_set_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
mov    0x2ea0(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
je     1198 <ce_set_nonblock+0x78>
mov    -0x8(%rbp),%esi
lea    0xe79(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    119f <ce_set_nonblock+0x7f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ce_set_nonblock>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    0x2eaa(%rip),%rcx
or     (%rcx),%eax
mov    0x2e89(%rip),%rcx
or     (%rcx),%eax
mov    0x2e88(%rip),%rcx
mov    (%rcx),%esi
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
test   %rax,%rax
je     1173 <ce_set_nonblock+0x53>
lea    0xe99(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@O_NDELAY = global i32 0
@F_SETFL = global i32 0
@.str = [40 x i8] c"ERROR: Failed to set fd %d to nonblock\0A\00"
define i32 @ce_set_nonblock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = load i32, i32* @F_GETFL
%7 = call i64 @fcntl(i32 %5, i32 %6, i32 0)
%8 = trunc i64 %7 to i32
store i32 %8, i32* %4
%9 = load i32, i32* @O_NONBLOCK
%10 = load i32, i32* %4
%11 = or i32 %10, %9
store i32 %11, i32* %4
%12 = load i32, i32* @O_NDELAY
%13 = load i32, i32* %4
%14 = or i32 %13, %12
store i32 %14, i32* %4
%15 = load i32, i32* %3
%16 = load i32, i32* @F_SETFL
%17 = load i32, i32* %4
%18 = call i64 @fcntl(i32 %15, i32 %16, i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %1
%21 = load i32, i32* %3
%22 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 -1, i32* %2
br label %24
23: ; preds = %1
store i32 0, i32* %2
br label %24
24: ; preds = %23, %20
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@O_NDELAY = global i32 0
@F_SETFL = global i32 0
@.str = [40 x i8] c"ERROR: Failed to set fd %d to nonblock\0A\00"
define i32 @ce_set_nonblock(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i64 @fcntl(i32 %0, i32 %2, i32 0)
%4 = trunc i64 %3 to i32
%5 = load i32, i32* @O_NONBLOCK
%6 = or i32 %5, %4
%7 = load i32, i32* @O_NDELAY
%8 = or i32 %6, %7
%9 = load i32, i32* @F_SETFL
%10 = tail call i64 @fcntl(i32 %0, i32 %9, i32 %8)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %14
14: ; preds = %1, %12
%15 = phi i32 [ -1, %12 ], [ 0, %1 ]
ret i32 %15
}