#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 /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int setnonblock(int fd) {
  int flags;
  flags = fcntl(fd, F_GETFL);
  if (flags == -1) {
    fputs("Can't get flags\n", stderr);
    return -1;
  }
  if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
    fputs("Can't set O_NONBLOCK\n", stderr);
    return -1;
  }
  return fd;
}


x86 assembly (clang, -O0):
<setnonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    116c <setnonblock+0x4c>
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
call   1040 <fputs@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <setnonblock+0x9b>
mov    -0x8(%rbp),%edi
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e66(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11b5 <setnonblock+0x95>
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
lea    0xe6d(%rip),%rdi
call   1040 <fputs@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <setnonblock+0x9b>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setnonblock>:
push   %rbx
mov    %edi,%ebx
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1163 <setnonblock+0x43>
mov    0x2e91(%rip),%rcx
mov    (%rcx),%esi
mov    0x2ea0(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    117d <setnonblock+0x5d>
lea    0xeb0(%rip),%rdi
jmp    116a <setnonblock+0x4a>
lea    0xe96(%rip),%rdi
mov    0x2e67(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [17 x i8] c"Can't get flags\0A\00"
@stderr = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [22 x i8] c"Can't set O_NONBLOCK\0A\00"
define i32 @setnonblock(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 i32 (i32, i32, ...) @fcntl(i32 %5, i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fputs(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 -1, i32* %2
br label %26
13: ; preds = %1
%14 = load i32, i32* %3
%15 = load i32, i32* @F_SETFL
%16 = load i32, i32* %4
%17 = load i32, i32* @O_NONBLOCK
%18 = or i32 %16, %17
%19 = call i32 (i32, i32, ...) @fcntl(i32 %14, i32 %15, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %22)
store i32 -1, i32* %2
br label %26
24: ; preds = %13
%25 = load i32, i32* %3
store i32 %25, i32* %2
br label %26
26: ; preds = %24, %21, %10
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [17 x i8] c"Can't get flags\0A\00"
@stderr = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [22 x i8] c"Can't set O_NONBLOCK\0A\00"
define i32 @setnonblock(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = load i32, i32* @F_SETFL
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %7, %3
%9 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %6, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %5, %1
%12 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), %5 ]
%13 = load i32, i32* @stderr
%14 = tail call i32 @fputs(i8* %12, i32 %13)
br label %15
15: ; preds = %11, %5
%16 = phi i32 [ %0, %5 ], [ -1, %11 ]
ret i32 %16
}