#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*/ errno;
int fcntl(int, int /*<<< orphan*/, ...);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int setnonblock(const char *name, int fd) {
  int val;
  if ((val = fcntl(fd, F_GETFL)) == -1) {
    fprintf(stderr, "Couldn't get file descriptor flags for %s : %s", name,
            strerror(errno));
    return -1;
  }
  if (fcntl(fd, F_SETFL, val | O_NONBLOCK)) {
    fprintf(stderr, "Couldn't set %s to non-blocking mode : %s", name,
            strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<setnonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    11a2 <setnonblock+0x72>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe6f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1215 <setnonblock+0xe5>
mov    -0x14(%rbp),%edi
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%edx
mov    0x2e30(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%eax
je     120e <setnonblock+0xde>
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xe32(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1215 <setnonblock+0xe5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setnonblock>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     117c <setnonblock+0x4c>
mov    0x2e77(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e86(%rip),%rcx
or     (%rcx),%eax
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
je     11af <setnonblock+0x7f>
lea    0xeb5(%rip),%rbx
jmp    1183 <setnonblock+0x53>
lea    0xe7d(%rip),%rbx
mov    0x2e4e(%rip),%rax
mov    (%rax),%ebp
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@stderr = global i32 0
@.str = [47 x i8] c"Couldn't get file descriptor flags for %s : %s\00"
@errno = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [42 x i8] c"Couldn't set %s to non-blocking mode : %s\00"
define i32 @setnonblock(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = load i32, i32* @F_GETFL
%9 = call i32 (i32, i32, ...) @fcntl(i32 %7, i32 %8)
store i32 %9, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %4
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %13, i8* %15)
store i32 -1, i32* %3
br label %32
17: ; preds = %2
%18 = load i32, i32* %5
%19 = load i32, i32* @F_SETFL
%20 = load i32, i32* %6
%21 = load i32, i32* @O_NONBLOCK
%22 = or i32 %20, %21
%23 = call i32 (i32, i32, ...) @fcntl(i32 %18, i32 %19, i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %17
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %4
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %29)
store i32 -1, i32* %3
br label %32
31: ; preds = %17
store i32 0, i32* %3
br label %32
32: ; preds = %31, %25, %11
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@stderr = global i32 0
@.str = [47 x i8] c"Couldn't get file descriptor flags for %s : %s\00"
@errno = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [42 x i8] c"Couldn't set %s to non-blocking mode : %s\00"
define i32 @setnonblock(i8* %0, i32 %1) {
%3 = load i32, i32* @F_GETFL
%4 = tail call i32 (i32, i32, ...) @fcntl(i32 %1, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = load i32, i32* @F_SETFL
%8 = load i32, i32* @O_NONBLOCK
%9 = or i32 %8, %4
%10 = tail call i32 (i32, i32, ...) @fcntl(i32 %1, i32 %7, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %6, %2
%13 = phi i8* [ getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), %6 ]
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 @fprintf(i32 %14, i8* %13, i8* %0, i8* %16)
br label %18
18: ; preds = %12, %6
%19 = phi i32 [ 0, %6 ], [ -1, %12 ]
ret i32 %19
}