#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 /*<<< orphan*/ exit(int);
scalar_t__ fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
void clr_fl(int fd, int flags) {
  int val;
  if ((val = fcntl(fd, F_GETFL, 0)) < 0) {
    fprintf(stderr, "fcntl F_GETFL error");
    exit(1);
  }
  val &= ~flags;
  if (fcntl(fd, F_SETFL, val) < 0) {
    fprintf(stderr, "fcntl F_SETFL error");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<clr_fl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    117c <clr_fl+0x4c>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    11c5 <clr_fl+0x95>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
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    0x2e92(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
test   %eax,%eax
js     116d <clr_fl+0x3d>
not    %ebp
and    %ebp,%eax
mov    0x2e82(%rip),%rcx
mov    (%rcx),%esi
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <fcntl@plt>
test   %rax,%rax
js     117f <clr_fl+0x4f>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
jmp    118f <clr_fl+0x5f>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@F_GETFL = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"fcntl F_GETFL error\00"
@F_SETFL = global i32 0
@.str.1 = [20 x i8] c"fcntl F_SETFL error\00"
define void @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 %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = xor i32 %1, -1
%13 = and i32 %5, %12
%14 = load i32, i32* @F_SETFL
%15 = tail call i64 @fcntl(i32 %0, i32 %14, i32 %13)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %11
ret void
}