#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 cras_make_fd_blocking(int fd) {
  int fl;
  fl = fcntl(fd, F_GETFL);
  if (fl < 0)
    return fl;
  if ((~fl) & O_NONBLOCK)
    return 0;
  return fcntl(fd, F_SETFL, fl & ~O_NONBLOCK);
}


x86 assembly (clang, -O0):
<cras_make_fd_blocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1146 <cras_make_fd_blocking+0x36>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1191 <cras_make_fd_blocking+0x81>
mov    -0xc(%rbp),%eax
xor    $0xffffffff,%eax
mov    0x2e95(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     116a <cras_make_fd_blocking+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    1191 <cras_make_fd_blocking+0x81>
mov    -0x8(%rbp),%edi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cras_make_fd_blocking>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2eb4(%rip),%rax
mov    (%rax),%esi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
js     115a <cras_make_fd_blocking+0x4a>
mov    %eax,%edx
not    %edx
mov    0x2eb2(%rip),%rcx
mov    (%rcx),%ecx
test   %edx,%ecx
jne    115c <cras_make_fd_blocking+0x4c>
mov    0x2e95(%rip),%rdx
mov    (%rdx),%esi
not    %ecx
and    %ecx,%eax
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fcntl@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @cras_make_fd_blocking(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* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = load i32, i32* %4
store i32 %11, i32* %2
br label %27
12: ; preds = %1
%13 = load i32, i32* %4
%14 = xor i32 %13, -1
%15 = load i32, i32* @O_NONBLOCK
%16 = and i32 %14, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %12
store i32 0, i32* %2
br label %27
19: ; preds = %12
%20 = load i32, i32* %3
%21 = load i32, i32* @F_SETFL
%22 = load i32, i32* %4
%23 = load i32, i32* @O_NONBLOCK
%24 = xor i32 %23, -1
%25 = and i32 %22, %24
%26 = call i32 (i32, i32, ...) @fcntl(i32 %20, i32 %21, i32 %25)
store i32 %26, i32* %2
br label %27
27: ; preds = %19, %18, %10
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_NONBLOCK = global i32 0
@F_SETFL = global i32 0
define i32 @cras_make_fd_blocking(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = xor i32 %3, -1
%7 = load i32, i32* @O_NONBLOCK
%8 = and i32 %7, %6
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %5
%11 = load i32, i32* @F_SETFL
%12 = xor i32 %7, -1
%13 = and i32 %3, %12
%14 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %11, i32 %13)
br label %15
15: ; preds = %5, %1, %10
%16 = phi i32 [ %14, %10 ], [ %3, %1 ], [ 0, %5 ]
ret i32 %16
}