#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;
int O_RDONLY;
int O_WRONLY;
int fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
void print_flags(int filedescriptor) {
  int accessMode, fileFlags;
  fileFlags = fcntl(filedescriptor, F_GETFL, 0);
  accessMode = fileFlags & O_ACCMODE;
  if (accessMode == O_RDONLY)
    printf("Access mode: Read Only\n");
  else if (accessMode == O_WRONLY)
    printf("Access mode: Write Only\n");
  else
    printf("Access mode: Read/Write\n");
  if (fileFlags & O_NONBLOCK)
    printf("O_NONBLOCK: ON\n");
  else
    printf("O_NONBLOCK: OFF\n");
  if (fileFlags & O_APPEND)
    printf("O_APPEND: ON\n");
  else
    printf("O_APPEND: OFF\n");
}


x86 assembly (clang, -O0):
<print_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2ea5(%rip),%rcx
and    (%rcx),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%eax
jne    1173 <print_flags+0x53>
lea    0xe97(%rip),%rdi
call   1040 <printf@plt>
jmp    11a7 <print_flags+0x87>
mov    -0x8(%rbp),%eax
mov    0x2e3b(%rip),%rcx
cmp    (%rcx),%eax
jne    1196 <print_flags+0x76>
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
jmp    11a2 <print_flags+0x82>
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
jmp    11a7 <print_flags+0x87>
mov    -0xc(%rbp),%eax
mov    0x2e2f(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11cd <print_flags+0xad>
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
jmp    11d9 <print_flags+0xb9>
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    0x2dcd(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11ff <print_flags+0xdf>
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
jmp    120b <print_flags+0xeb>
lea    0xe73(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_flags>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <fcntl@plt>
mov    %eax,%ebx
mov    0x2eb6(%rip),%rax
mov    (%rax),%eax
and    %ebx,%eax
mov    0x2e93(%rip),%rcx
mov    0x2e6c(%rip),%rdx
cmp    (%rdx),%eax
lea    0xefd(%rip),%rdx
lea    0xea4(%rip),%rsi
cmove  %rdx,%rsi
cmp    (%rcx),%eax
lea    0xf01(%rip),%rdi
cmovne %rsi,%rdi
call   1030 <puts@plt>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
and    %ebx,%eax
lea    0xe94(%rip),%rax
lea    0xeb8(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    0x2e15(%rip),%rax
and    (%rax),%ebx
lea    0xe84(%rip),%rax
lea    0xe8b(%rip),%rdi
cmove  %rax,%rdi
pop    %rbx
jmp    1030 <puts@plt>

LLVM IR (-O0):
@F_GETFL = global i32 0
@O_ACCMODE = global i32 0
@O_RDONLY = global i32 0
@.str = [24 x i8] c"Access mode: Read Only\0A\00"
@O_WRONLY = global i32 0
@.str.1 = [25 x i8] c"Access mode: Write Only\0A\00"
@.str.2 = [25 x i8] c"Access mode: Read/Write\0A\00"
@O_NONBLOCK = global i32 0
@.str.3 = [16 x i8] c"O_NONBLOCK: ON\0A\00"
@.str.4 = [17 x i8] c"O_NONBLOCK: OFF\0A\00"
@O_APPEND = global i32 0
@.str.5 = [14 x i8] c"O_APPEND: ON\0A\00"
@.str.6 = [15 x i8] c"O_APPEND: OFF\0A\00"
define void @print_flags(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* @F_GETFL
%7 = call i32 @fcntl(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = load i32, i32* @O_ACCMODE
%10 = and i32 %8, %9
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = load i32, i32* @O_RDONLY
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %25
16: ; preds = %1
%17 = load i32, i32* %3
%18 = load i32, i32* @O_WRONLY
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
br label %24
22: ; preds = %16
%23 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %20
br label %25
25: ; preds = %24, %14
%26 = load i32, i32* %4
%27 = load i32, i32* @O_NONBLOCK
%28 = and i32 %26, %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %34
32: ; preds = %25
%33 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %30
%35 = load i32, i32* %4
%36 = load i32, i32* @O_APPEND
%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.5, i64 0, i64 0))
br label %43
41: ; preds = %34
%42 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %43
43: ; preds = %41, %39
ret void
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@O_ACCMODE = global i32 0
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@O_APPEND = global i32 0
@str = [24 x i8] c"Access mode: Read/Write\00"
@str.7 = [16 x i8] c"O_NONBLOCK: OFF\00"
@str.8 = [14 x i8] c"O_APPEND: OFF\00"
@str.9 = [13 x i8] c"O_APPEND: ON\00"
@str.10 = [15 x i8] c"O_NONBLOCK: ON\00"
@str.11 = [24 x i8] c"Access mode: Write Only\00"
@str.12 = [23 x i8] c"Access mode: Read Only\00"
define void @print_flags(i32 %0) {
%2 = load i32, i32* @F_GETFL
%3 = tail call i32 @fcntl(i32 %0, i32 %2, i32 0)
%4 = load i32, i32* @O_ACCMODE
%5 = and i32 %4, %3
%6 = load i32, i32* @O_RDONLY
%7 = icmp eq i32 %5, %6
%8 = load i32, i32* @O_WRONLY
%9 = icmp eq i32 %5, %8
%10 = select i1 %9, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @str.11, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0)
%11 = select i1 %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @str.12, i64 0, i64 0), i8* %10
%12 = tail call i32 @puts(i8* dereferenceable(1) %11)
%13 = load i32, i32* @O_NONBLOCK
%14 = and i32 %13, %3
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str.7, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @str.10, i64 0, i64 0)
%17 = tail call i32 @puts(i8* dereferenceable(1) %16)
%18 = load i32, i32* @O_APPEND
%19 = and i32 %18, %3
%20 = icmp eq i32 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str.9, i64 0, i64 0)
%22 = tail call i32 @puts(i8* dereferenceable(1) %21)
ret void
}