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


x86 assembly (clang, -O0):
<clear_nonblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1030 <fcntl@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    114f <clear_nonblock+0x3f>
movl   $0x0,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
mov    $0x0,%al
call   1030 <fcntl@plt>
cmp    $0x0,%eax
je     1183 <clear_nonblock+0x73>
movl   $0xffffffff,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clear_nonblock>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2eb4(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
sete   %bpl
mov    $0x0,%ecx
cmovne %eax,%ecx
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
mov    0x2ea4(%rip),%rax
mov    (%rax),%edx
not    %edx
and    %ecx,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <fcntl@plt>
test   %eax,%eax
setne  %al
or     %bpl,%al
movzbl %al,%eax
neg    %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
define i32 @clear_nonblock(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
%5 = load i32, i32* %2
%6 = load i32, i32* @F_GETFL
%7 = call i32 (i32, i32, ...) @fcntl(i32 %5, i32 %6)
store i32 %7, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %3
store i32 -1, i32* %4
br label %10
10: ; preds = %9, %1
%11 = load i32, i32* %2
%12 = load i32, i32* @F_SETFL
%13 = load i32, i32* %3
%14 = load i32, i32* @O_NONBLOCK
%15 = xor i32 %14, -1
%16 = and i32 %13, %15
%17 = call i32 (i32, i32, ...) @fcntl(i32 %11, i32 %12, i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %10
store i32 -1, i32* %4
br label %20
20: ; preds = %19, %10
%21 = load i32, i32* %4
ret i32 %21
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
define i32 @clear_nonblock(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %2)
%4 = icmp eq i32 %3, -1
%5 = select i1 %4, i32 0, i32 %3
%6 = load i32, i32* @F_SETFL
%7 = load i32, i32* @O_NONBLOCK
%8 = xor i32 %7, -1
%9 = and i32 %5, %8
%10 = tail call i32 (i32, i32, ...) @fcntl(i32 %0, i32 %6, i32 %9)
%11 = icmp ne i32 %10, 0
%12 = select i1 %11, i1 true, i1 %4
%13 = sext i1 %12 to i32
ret i32 %13
}