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


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    0x2ea0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1159 <clr_fl+0x39>
lea    0xeac(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
xor    $0xffffffff,%eax
and    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
call   1030 <fcntl@plt>
cmp    $0x0,%rax
jge    118f <clr_fl+0x6f>
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clr_fl>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %edi,%r14d
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    %rax,%rbx
test   %ebx,%ebx
jns    114c <clr_fl+0x2c>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
not    %ebp
and    %ebp,%ebx
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %ebx,%edx
call   1040 <fcntl@plt>
test   %rax,%rax
js     116d <clr_fl+0x4d>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe8c(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [22 x i8] c"fcntl F_GETFL error \0A\00"
@F_SETFL = global i32 0
@.str.1 = [22 x i8] c"fcntl F_SETFL error \0A\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 %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i32, i32* %4
%15 = xor i32 %14, -1
%16 = load i32, i32* %5
%17 = and i32 %16, %15
store i32 %17, i32* %5
%18 = load i32, i32* %3
%19 = load i32, i32* @F_SETFL
%20 = load i32, i32* %5
%21 = call i64 @fcntl(i32 %18, i32 %19, i32 %20)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %13
ret void
}

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