#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;
scalar_t__ fcntl(int, int /*<<< orphan*/, int);
int clr_fl(int fd, int flag) {
  int oflag;
  oflag = fcntl(fd, F_GETFL, 0);
  if (oflag < 0) {
    return -1;
  }
  oflag &= ~flag;
  if (fcntl(fd, F_SETFL, oflag) < 0) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<clr_fl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    114a <clr_fl+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1187 <clr_fl+0x77>
mov    -0xc(%rbp),%eax
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    1180 <clr_fl+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    1187 <clr_fl+0x77>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clr_fl>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2eba(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
js     1147 <clr_fl+0x37>
not    %ebp
and    %ebp,%eax
mov    0x2eaa(%rip),%rcx
mov    (%rcx),%esi
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
sar    $0x3f,%rax
jmp    114c <clr_fl+0x3c>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@F_SETFL = global i32 0
define i32 @clr_fl(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = load i32, i32* @F_GETFL
%9 = call i64 @fcntl(i32 %7, i32 %8, i32 0)
%10 = trunc i64 %9 to i32
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %26
14: ; preds = %2
%15 = load i32, i32* %5
%16 = xor i32 %15, -1
%17 = load i32, i32* %6
%18 = and i32 %17, %16
store i32 %18, i32* %6
%19 = load i32, i32* %4
%20 = load i32, i32* @F_SETFL
%21 = load i32, i32* %6
%22 = call i64 @fcntl(i32 %19, i32 %20, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %14
store i32 -1, i32* %3
br label %26
25: ; preds = %14
store i32 0, i32* %3
br label %26
26: ; preds = %25, %24, %13
%27 = load i32, i32* %3
ret i32 %27
}

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