#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 fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int make_fd_block(int fd) {
  int ret = 0;
  ret = fcntl(fd, F_GETFL, 0);
  if (ret == -1) {
    perror("fcntl(F_GETFL)");
    return (ret);
  }
  ret = fcntl(fd, F_SETFL, ret & (~O_NONBLOCK));
  if (ret == -1) {
    perror("fcntl(F_SETFL)");
    return (ret);
  }
  return (ret);
}


x86 assembly (clang, -O0):
<make_fd_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e94(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1169 <make_fd_block+0x49>
lea    0xea7(%rip),%rdi
call   1040 <perror@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b5 <make_fd_block+0x95>
mov    -0x8(%rbp),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11af <make_fd_block+0x8f>
lea    0xe70(%rip),%rdi
call   1040 <perror@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b5 <make_fd_block+0x95>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_fd_block>:
push   %rbx
mov    %edi,%ebx
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     115e <make_fd_block+0x3e>
mov    0x2e99(%rip),%rcx
mov    (%rcx),%esi
mov    0x2ea0(%rip),%rcx
mov    (%rcx),%ecx
not    %ecx
and    %ecx,%eax
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1167 <make_fd_block+0x47>
pop    %rbx
ret
lea    0xe9b(%rip),%rdi
jmp    116e <make_fd_block+0x4e>
lea    0xea1(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [15 x i8] c"fcntl(F_GETFL)\00"
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [15 x i8] c"fcntl(F_SETFL)\00"
define i32 @make_fd_block(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %4
%5 = load i32, i32* %3
%6 = load i32, i32* @F_GETFL
%7 = call i32 @fcntl(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %4
store i32 %12, i32* %2
br label %28
13: ; preds = %1
%14 = load i32, i32* %3
%15 = load i32, i32* @F_SETFL
%16 = load i32, i32* %4
%17 = load i32, i32* @O_NONBLOCK
%18 = xor i32 %17, -1
%19 = and i32 %16, %18
%20 = call i32 @fcntl(i32 %14, i32 %15, i32 %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %13
%24 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* %4
store i32 %25, i32* %2
br label %28
26: ; preds = %13
%27 = load i32, i32* %4
store i32 %27, i32* %2
br label %28
28: ; preds = %26, %23, %10
%29 = load i32, i32* %2
ret i32 %29
}

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