#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_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
int /*<<< orphan*/ errno;
scalar_t__ fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ log_message(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int set_nonblocking(int f) {
  if (fcntl(f, F_SETFL, O_NONBLOCK) != 0) {
    log_message("set_nonblocking: fcntl: %s", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_nonblocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    0x2e9a(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
je     1187 <set_nonblocking+0x57>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%esi
lea    0xe8a(%rip),%rdi
call   1040 <log_message@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118e <set_nonblocking+0x5e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_nonblocking>:
push   %rax
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
mov    0x2ea7(%rip),%rax
mov    (%rax),%edx
call   1030 <fcntl@plt>
test   %rax,%rax
je     1170 <set_nonblocking+0x40>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe9e(%rip),%rdi
mov    %eax,%esi
call   1040 <log_message@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str = [27 x i8] c"set_nonblocking: fcntl: %s\00"
@errno = global i32 0
define i32 @set_nonblocking(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = load i32, i32* @F_SETFL
%6 = load i32, i32* @O_NONBLOCK
%7 = call i64 @fcntl(i32 %4, i32 %5, i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @errno
%11 = call i32 @strerror(i32 %10)
%12 = call i32 @log_message(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 -1, i32* %2
br label %14
13: ; preds = %1
store i32 0, i32* %2
br label %14
14: ; preds = %13, %9
%15 = load i32, i32* %2
ret i32 %15
}

LLVM IR (-O2):
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str = [27 x i8] c"set_nonblocking: fcntl: %s\00"
@errno = global i32 0
define i32 @set_nonblocking(i32 %0) {
%2 = load i32, i32* @F_SETFL
%3 = load i32, i32* @O_NONBLOCK
%4 = tail call i64 @fcntl(i32 %0, i32 %2, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = load i32, i32* @errno
%8 = tail call i32 @strerror(i32 %7)
%9 = tail call i32 @log_message(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %1, %6
%11 = phi i32 [ -1, %6 ], [ 0, %1 ]
ret i32 %11
}