#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 O_ACCMODE;
int O_APPEND;
int O_NONBLOCK;
#define O_RDONLY 130
#define O_RDWR 129
#define O_WRONLY 128
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ err_dump(char *);
int /*<<< orphan*/ err_sys(char *, int /*<<< orphan*/);
int fcntl(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
void get_fl(char *filename[]) {
  int val;
  if ((val = fcntl(atoi(*filename), F_GETFL, 0)) < 0) {
    err_sys("fcntl error for fd %d", atoi(*filename));
  }
  switch (val & O_ACCMODE) {
  case O_RDONLY:
    printf("read only");
    break;
  case O_WRONLY:
    printf("write only");
    break;
  case O_RDWR:
    printf("read write");
    break;
  default:
    err_dump("unknown access mode");
  }
  if (val & O_APPEND) {
    printf(", append");
  }
  if (val & O_NONBLOCK) {
    printf(", nonblocking");
  }
  putchar('\n');
}


x86 assembly (clang, -O0):
<get_fl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11b0 <get_fl+0x50>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,%esi
lea    0xe55(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0xc(%rbp),%eax
mov    0x2e36(%rip),%rcx
mov    (%rcx),%ecx
and    %ecx,%eax
mov    %eax,-0x10(%rbp)
sub    $0x80,%eax
je     1208 <get_fl+0xa8>
jmp    11d1 <get_fl+0x71>
mov    -0x10(%rbp),%eax
sub    $0x81,%eax
je     1219 <get_fl+0xb9>
jmp    11e4 <get_fl+0x84>
mov    -0x10(%rbp),%eax
sub    $0x82,%eax
jne    122a <get_fl+0xca>
jmp    11f7 <get_fl+0x97>
lea    0xe18(%rip),%rdi
call   1060 <printf@plt>
jmp    1236 <get_fl+0xd6>
lea    0xe11(%rip),%rdi
call   1060 <printf@plt>
jmp    1236 <get_fl+0xd6>
lea    0xe0b(%rip),%rdi
call   1060 <printf@plt>
jmp    1236 <get_fl+0xd6>
lea    0xe05(%rip),%rdi
call   1070 <err_dump@plt>
mov    -0xc(%rbp),%eax
mov    0x2d80(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1257 <get_fl+0xf7>
lea    0xdf8(%rip),%rdi
call   1060 <printf@plt>
mov    -0xc(%rbp),%eax
mov    0x2d7f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1278 <get_fl+0x118>
lea    0xde0(%rip),%rdi
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_fl>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%rdi
call   1080 <atoi@plt>
mov    0x2e5b(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
xor    %edx,%edx
call   1050 <fcntl@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    119c <get_fl+0x3c>
mov    (%rbx),%rdi
call   1080 <atoi@plt>
lea    0xe6b(%rip),%rdi
mov    %eax,%esi
call   1040 <err_sys@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
and    %ebp,%eax
cmp    $0x80,%eax
je     11ca <get_fl+0x6a>
cmp    $0x81,%eax
je     11d8 <get_fl+0x78>
cmp    $0x82,%eax
jne    11e6 <get_fl+0x86>
lea    0xe53(%rip),%rdi
call   1060 <printf@plt>
jmp    11f2 <get_fl+0x92>
lea    0xe4f(%rip),%rdi
call   1060 <printf@plt>
jmp    11f2 <get_fl+0x92>
lea    0xe4c(%rip),%rdi
call   1060 <printf@plt>
jmp    11f2 <get_fl+0x92>
lea    0xe49(%rip),%rdi
call   1070 <err_dump@plt>
mov    0x2dc7(%rip),%rax
test   %ebp,(%rax)
je     1209 <get_fl+0xa9>
lea    0xe46(%rip),%rdi
call   1060 <printf@plt>
mov    0x2dd0(%rip),%rax
test   %ebp,(%rax)
je     1220 <get_fl+0xc0>
lea    0xe38(%rip),%rdi
call   1060 <printf@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [22 x i8] c"fcntl error for fd %d\00"
@O_ACCMODE = global i32 0
@.str.1 = [10 x i8] c"read only\00"
@.str.2 = [11 x i8] c"write only\00"
@.str.3 = [11 x i8] c"read write\00"
@.str.4 = [20 x i8] c"unknown access mode\00"
@O_APPEND = global i32 0
@.str.5 = [9 x i8] c", append\00"
@O_NONBLOCK = global i32 0
@.str.6 = [14 x i8] c", nonblocking\00"
define void @get_fl(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
store i8** %0, i8*** %2
%4 = load i8**, i8*** %2
%5 = load i8*, i8** %4
%6 = call i32 @atoi(i8* %5)
%7 = load i32, i32* @F_GETFL
%8 = call i32 @fcntl(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i8**, i8*** %2
%12 = load i8*, i8** %11
%13 = call i32 @atoi(i8* %12)
%14 = call i32 @err_sys(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %10, %1
%16 = load i32, i32* %3
%17 = load i32, i32* @O_ACCMODE
%18 = and i32 %16, %17
switch i32 %18, label %25 [
i32 130, label %19
i32 128, label %21
i32 129, label %23
]
19: ; preds = %15
%20 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %27
21: ; preds = %15
%22 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %27
23: ; preds = %15
%24 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %27
25: ; preds = %15
%26 = call i32 @err_dump(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %25, %23, %21, %19
%28 = load i32, i32* %3
%29 = load i32, i32* @O_APPEND
%30 = and i32 %28, %29
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
%35 = load i32, i32* %3
%36 = load i32, i32* @O_NONBLOCK
%37 = and i32 %35, %36
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %41
41: ; preds = %39, %34
%42 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [22 x i8] c"fcntl error for fd %d\00"
@O_ACCMODE = global i32 0
@.str.1 = [10 x i8] c"read only\00"
@.str.2 = [11 x i8] c"write only\00"
@.str.3 = [11 x i8] c"read write\00"
@.str.4 = [20 x i8] c"unknown access mode\00"
@O_APPEND = global i32 0
@.str.5 = [9 x i8] c", append\00"
@O_NONBLOCK = global i32 0
@.str.6 = [14 x i8] c", nonblocking\00"
define void @get_fl(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = tail call i32 @atoi(i8* %2)
%4 = load i32, i32* @F_GETFL
%5 = tail call i32 @fcntl(i32 %3, i32 %4, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i8*, i8** %0
%9 = tail call i32 @atoi(i8* %8)
%10 = tail call i32 @err_sys(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %7, %1
%12 = load i32, i32* @O_ACCMODE
%13 = and i32 %12, %5
switch i32 %13, label %20 [
i32 130, label %14
i32 128, label %16
i32 129, label %18
]
14: ; preds = %11
%15 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %22
16: ; preds = %11
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %22
18: ; preds = %11
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %22
20: ; preds = %11
%21 = tail call i32 @err_dump(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %20, %18, %16, %14
%23 = load i32, i32* @O_APPEND
%24 = and i32 %23, %5
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
%29 = load i32, i32* @O_NONBLOCK
%30 = and i32 %29, %5
%31 = icmp eq i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %28
%33 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
%35 = tail call i32 @putchar(i8 signext 10)
ret void
}