#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*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ svz_log(int, char *, int /*<<< orphan*/);
int svz_fd_block(int fd) {
  int flag;
  flag = fcntl(fd, F_GETFL);
  if (fcntl(fd, F_SETFL, flag & ~O_NONBLOCK) < 0) {
    svz_log(1, "fcntl: %s\n", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<svz_fd_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%eax
jge    11ab <svz_fd_block+0x7b>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    %eax,%edx
mov    $0x1,%edi
lea    0xe66(%rip),%rsi
call   1050 <svz_log@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <svz_fd_block+0x82>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<svz_fd_block>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <fcntl@plt>
mov    0x2e8a(%rip),%rcx
mov    (%rcx),%esi
mov    0x2e91(%rip),%rcx
mov    (%rcx),%edx
not    %edx
and    %eax,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
jns    1190 <svz_fd_block+0x60>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
lea    0xe81(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
call   1050 <svz_log@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str = [11 x i8] c"fcntl: %s\0A\00"
@errno = global i32 0
define i32 @svz_fd_block(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* %3
%9 = load i32, i32* @F_SETFL
%10 = load i32, i32* %4
%11 = load i32, i32* @O_NONBLOCK
%12 = xor i32 %11, -1
%13 = and i32 %10, %12
%14 = call i32 (i32, i32, ...) @fcntl(i32 %8, i32 %9, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %1
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @svz_log(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %18)
store i32 -1, i32* %2
br label %21
20: ; preds = %1
store i32 0, i32* %2
br label %21
21: ; preds = %20, %16
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str = [11 x i8] c"fcntl: %s\0A\00"
@errno = global i32 0
define i32 @svz_fd_block(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = load i32, i32* @F_SETFL
%5 = load i32, i32* @O_NONBLOCK
%6 = xor i32 %5, -1
%7 = and i32 %3, %6
%8 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %4, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i32, i32* @errno
%12 = tail call i32 @strerror(i32 %11)
%13 = tail call i32 @svz_log(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %1, %10
%15 = phi i32 [ -1, %10 ], [ 0, %1 ]
ret i32 %15
}