#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_APPEND;
int O_CREAT;
int O_RDONLY;
int O_RDWR;
int O_TRUNC;
int O_WRONLY;
scalar_t__ strcmp(char const *, char *);
int xstream_file_oflags(const char *mode) {
  if (strcmp(mode, "r") == 0)
    return (O_RDONLY);
  else if (strcmp(mode, "r+") == 0)
    return (O_RDWR);
  else if (strcmp(mode, "w") == 0)
    return (O_WRONLY | O_TRUNC | O_CREAT);
  else if (strcmp(mode, "w+") == 0)
    return (O_RDWR | O_TRUNC | O_CREAT);
  else if (strcmp(mode, "a") == 0)
    return (O_WRONLY | O_APPEND | O_CREAT);
  else if (strcmp(mode, "a+") == 0)
    return (O_RDWR | O_APPEND | O_CREAT);
  else
    return (O_RDONLY);
}


x86 assembly (clang, -O0):
<xstream_file_oflags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed9(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1147 <xstream_file_oflags+0x37>
mov    0x2e93(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1272 <xstream_file_oflags+0x162>
mov    -0x10(%rbp),%rdi
lea    0xeb0(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1172 <xstream_file_oflags+0x62>
mov    0x2e70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1272 <xstream_file_oflags+0x162>
mov    -0x10(%rbp),%rdi
lea    0xe88(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11af <xstream_file_oflags+0x9f>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    0x2e54(%rip),%rcx
or     (%rcx),%eax
mov    0x2e53(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1272 <xstream_file_oflags+0x162>
mov    -0x10(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11ec <xstream_file_oflags+0xdc>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    0x2e17(%rip),%rcx
or     (%rcx),%eax
mov    0x2e16(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1272 <xstream_file_oflags+0x162>
mov    -0x10(%rbp),%rdi
lea    0xe13(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1229 <xstream_file_oflags+0x119>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    0x2d9a(%rip),%rcx
or     (%rcx),%eax
mov    0x2dd9(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1272 <xstream_file_oflags+0x162>
mov    -0x10(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1266 <xstream_file_oflags+0x156>
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
mov    0x2d5d(%rip),%rcx
or     (%rcx),%eax
mov    0x2d9c(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1272 <xstream_file_oflags+0x162>
mov    0x2d63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstream_file_oflags>:
push   %rbx
mov    %rdi,%rbx
lea    0xee5(%rip),%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1189 <xstream_file_oflags+0x79>
lea    0xed6(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1192 <xstream_file_oflags+0x82>
lea    0xec5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     119d <xstream_file_oflags+0x8d>
lea    0xeb3(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11a6 <xstream_file_oflags+0x96>
lea    0xea2(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11c3 <xstream_file_oflags+0xb3>
lea    0xe90(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11d3 <xstream_file_oflags+0xc3>
mov    0x2e40(%rip),%rax
jmp    1199 <xstream_file_oflags+0x89>
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    0x2e14(%rip),%rcx
jmp    11ad <xstream_file_oflags+0x9d>
mov    0x2e2b(%rip),%rcx
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    0x2e39(%rip),%rcx
or     (%rcx),%eax
pop    %rbx
ret
mov    0x2dee(%rip),%rcx
mov    0x2ddf(%rip),%rax
jmp    11b4 <xstream_file_oflags+0xa4>
mov    0x2dfe(%rip),%rcx
mov    0x2dcf(%rip),%rax
jmp    11b4 <xstream_file_oflags+0xa4>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@O_RDONLY = global i32 0
@.str.1 = [3 x i8] c"r+\00"
@O_RDWR = global i32 0
@.str.2 = [2 x i8] c"w\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [2 x i8] c"a\00"
@O_APPEND = global i32 0
@.str.5 = [3 x i8] c"a+\00"
define i32 @xstream_file_oflags(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i32, i32* @O_RDONLY
store i32 %8, i32* %2
br label %57
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load i32, i32* @O_RDWR
store i32 %14, i32* %2
br label %57
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = load i32, i32* @O_WRONLY
%21 = load i32, i32* @O_TRUNC
%22 = or i32 %20, %21
%23 = load i32, i32* @O_CREAT
%24 = or i32 %22, %23
store i32 %24, i32* %2
br label %57
25: ; preds = %15
%26 = load i8*, i8** %3
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %25
%30 = load i32, i32* @O_RDWR
%31 = load i32, i32* @O_TRUNC
%32 = or i32 %30, %31
%33 = load i32, i32* @O_CREAT
%34 = or i32 %32, %33
store i32 %34, i32* %2
br label %57
35: ; preds = %25
%36 = load i8*, i8** %3
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %35
%40 = load i32, i32* @O_WRONLY
%41 = load i32, i32* @O_APPEND
%42 = or i32 %40, %41
%43 = load i32, i32* @O_CREAT
%44 = or i32 %42, %43
store i32 %44, i32* %2
br label %57
45: ; preds = %35
%46 = load i8*, i8** %3
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %45
%50 = load i32, i32* @O_RDWR
%51 = load i32, i32* @O_APPEND
%52 = or i32 %50, %51
%53 = load i32, i32* @O_CREAT
%54 = or i32 %52, %53
store i32 %54, i32* %2
br label %57
55: ; preds = %45
%56 = load i32, i32* @O_RDONLY
store i32 %56, i32* %2
br label %57
57: ; preds = %55, %49, %39, %29, %19, %13, %7
%58 = load i32, i32* %2
ret i32 %58
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@O_RDONLY = global i32 0
@.str.1 = [3 x i8] c"r+\00"
@O_RDWR = global i32 0
@.str.2 = [2 x i8] c"w\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [2 x i8] c"a\00"
@O_APPEND = global i32 0
@.str.5 = [3 x i8] c"a+\00"
define i32 @xstream_file_oflags(i8* %0) {
%2 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = load i32, i32* @O_RDONLY
br label %49
6: ; preds = %1
%7 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = load i32, i32* @O_RDWR
br label %49
11: ; preds = %6
%12 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* @O_WRONLY
%16 = load i32, i32* @O_TRUNC
%17 = or i32 %16, %15
%18 = load i32, i32* @O_CREAT
%19 = or i32 %17, %18
br label %49
20: ; preds = %11
%21 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i32, i32* @O_RDWR
%25 = load i32, i32* @O_TRUNC
%26 = or i32 %25, %24
%27 = load i32, i32* @O_CREAT
%28 = or i32 %26, %27
br label %49
29: ; preds = %20
%30 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i32, i32* @O_WRONLY
%34 = load i32, i32* @O_APPEND
%35 = or i32 %34, %33
%36 = load i32, i32* @O_CREAT
%37 = or i32 %35, %36
br label %49
38: ; preds = %29
%39 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load i32, i32* @O_RDWR
%43 = load i32, i32* @O_APPEND
%44 = or i32 %43, %42
%45 = load i32, i32* @O_CREAT
%46 = or i32 %44, %45
br label %49
47: ; preds = %38
%48 = load i32, i32* @O_RDONLY
br label %49
49: ; preds = %47, %41, %32, %23, %14, %9, %4
%50 = phi i32 [ %5, %4 ], [ %10, %9 ], [ %19, %14 ], [ %28, %23 ], [ %37, %32 ], [ %46, %41 ], [ %48, %47 ]
ret i32 %50
}