#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*/ errno;
int fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *gettext(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int set_fd_blocking(int fd) {
  if (fcntl(fd, F_SETFL, 0) == -1) {
    fprintf(stderr, gettext("set_fd_blocking failed! (%s)\n"), strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_fd_blocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    11ac <set_fd_blocking+0x6c>
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    0xe86(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    %rax,%rdx
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <set_fd_blocking+0x73>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_fd_blocking>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    1192 <set_fd_blocking+0x52>
mov    0x2e7f(%rip),%rax
mov    (%rax),%ebp
lea    0xe96(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rbx
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_SETFL = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"set_fd_blocking failed! (%s)\0A\00"
@errno = global i32 0
define i32 @set_fd_blocking(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 = call i32 @fcntl(i32 %4, i32 %5, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i8* @gettext(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %9, i8* %10, i8* %12)
store i32 -1, i32* %2
br label %15
14: ; preds = %1
store i32 0, i32* %2
br label %15
15: ; preds = %14, %8
%16 = load i32, i32* %2
ret i32 %16
}

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