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


x86 assembly (clang, -O0):
<setnonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    117e <setnonblock+0x4e>
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%edi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e54(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11c9 <setnonblock+0x99>
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
lea    0xe5b(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setnonblock>:
push   %rbx
mov    %edi,%ebx
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     116e <setnonblock+0x3e>
mov    0x2e81(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e90(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1180 <setnonblock+0x50>
mov    %ebx,%eax
pop    %rbx
ret
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    0xe82(%rip),%rdi
jmp    1190 <setnonblock+0x60>
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

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

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