#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 O_ACCMODE;
int O_APPEND;
int O_RDONLY;
int O_RDWR;
int O_WRONLY;
char *print_as_shell_redir(int oflags) {
  if ((oflags & O_ACCMODE) == O_RDWR)
    return "<>";
  if ((oflags & O_ACCMODE) == O_RDONLY)
    return "<";
  if ((oflags & O_ACCMODE) == O_WRONLY) {
    if ((oflags & O_APPEND))
      return ">>";
    return ">";
  }
  return "?";
}


x86 assembly (clang, -O0):
<print_as_shell_redir>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2edf(%rip),%rcx
and    (%rcx),%eax
mov    0x2ec6(%rip),%rcx
cmp    (%rcx),%eax
jne    1132 <print_as_shell_redir+0x32>
lea    0xed7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <print_as_shell_redir+0xb8>
mov    -0xc(%rbp),%eax
mov    0x2eb4(%rip),%rcx
and    (%rcx),%eax
mov    0x2e93(%rip),%rcx
cmp    (%rcx),%eax
jne    115d <print_as_shell_redir+0x5d>
lea    0xeaf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <print_as_shell_redir+0xb8>
mov    -0xc(%rbp),%eax
mov    0x2e89(%rip),%rcx
and    (%rcx),%eax
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%eax
jne    11ad <print_as_shell_redir+0xad>
mov    -0xc(%rbp),%eax
mov    0x2e36(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     119d <print_as_shell_redir+0x9d>
lea    0xe71(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <print_as_shell_redir+0xb8>
lea    0xe5d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b8 <print_as_shell_redir+0xb8>
lea    0xe54(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_as_shell_redir>:
mov    0x2ee9(%rip),%rax
mov    (%rax),%eax
and    %edi,%eax
mov    0x2ece(%rip),%rcx
cmp    (%rcx),%eax
jne    111e <print_as_shell_redir+0x1e>
lea    0xee3(%rip),%rax
ret
mov    0x2eb3(%rip),%rcx
cmp    (%rcx),%eax
jne    1131 <print_as_shell_redir+0x31>
lea    0xed3(%rip),%rax
ret
mov    0x2e88(%rip),%rcx
cmp    (%rcx),%eax
jne    1158 <print_as_shell_redir+0x58>
mov    0x2e75(%rip),%rax
test   %edi,(%rax)
lea    0xeb5(%rip),%rcx
lea    0xeb2(%rip),%rax
cmove  %rcx,%rax
ret
lea    0xea9(%rip),%rax
ret

LLVM IR (-O0):
@O_ACCMODE = global i32 0
@O_RDWR = global i32 0
@.str = [3 x i8] c"<>\00"
@O_RDONLY = global i32 0
@.str.1 = [2 x i8] c"<\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str.2 = [3 x i8] c">>\00"
@.str.3 = [2 x i8] c">\00"
@.str.4 = [2 x i8] c"?\00"
define i8* @print_as_shell_redir(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = load i32, i32* @O_ACCMODE
%6 = and i32 %4, %5
%7 = load i32, i32* @O_RDWR
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %2
br label %31
10: ; preds = %1
%11 = load i32, i32* %3
%12 = load i32, i32* @O_ACCMODE
%13 = and i32 %11, %12
%14 = load i32, i32* @O_RDONLY
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %10
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %31
17: ; preds = %10
%18 = load i32, i32* %3
%19 = load i32, i32* @O_ACCMODE
%20 = and i32 %18, %19
%21 = load i32, i32* @O_WRONLY
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %30
23: ; preds = %17
%24 = load i32, i32* %3
%25 = load i32, i32* @O_APPEND
%26 = and i32 %24, %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %31
29: ; preds = %23
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %31
30: ; preds = %17
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %31
31: ; preds = %30, %29, %28, %16, %9
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
@O_ACCMODE = global i32 0
@O_RDWR = global i32 0
@.str = [3 x i8] c"<>\00"
@O_RDONLY = global i32 0
@.str.1 = [2 x i8] c"<\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str.2 = [3 x i8] c">>\00"
@.str.3 = [2 x i8] c">\00"
@.str.4 = [2 x i8] c"?\00"
define i8* @print_as_shell_redir(i32 %0) {
%2 = load i32, i32* @O_ACCMODE
%3 = and i32 %2, %0
%4 = load i32, i32* @O_RDWR
%5 = icmp eq i32 %3, %4
br i1 %5, label %17, label %6
6: ; preds = %1
%7 = load i32, i32* @O_RDONLY
%8 = icmp eq i32 %3, %7
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = load i32, i32* @O_WRONLY
%11 = icmp eq i32 %3, %10
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32, i32* @O_APPEND
%14 = and i32 %13, %0
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
br label %17
17: ; preds = %9, %12, %6, %1
%18 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %6 ], [ %16, %12 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), %9 ]
ret i8* %18
}