#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;
int __stdio_parse_mode(const char *mode) {
  int f = 0;
  for (;;) {
    switch (*mode) {
    case 0:
      return f;
    case 'b':
      break;
    case 'r':
      f = O_RDONLY;
      break;
    case 'w':
      f = O_WRONLY | O_CREAT | O_TRUNC;
      break;
    case 'a':
      f = O_WRONLY | O_CREAT | O_APPEND;
      break;
    case '+':
      f = (f & (~O_WRONLY)) | O_RDWR;
      break;
    }
    ++mode;
  }
}


x86 assembly (clang, -O0):
<__stdio_parse_mode>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x10(%rbp)
test   %eax,%eax
je     117b <__stdio_parse_mode+0x7b>
jmp    1126 <__stdio_parse_mode+0x26>
mov    -0x10(%rbp),%eax
sub    $0x2b,%eax
je     11dc <__stdio_parse_mode+0xdc>
jmp    1137 <__stdio_parse_mode+0x37>
mov    -0x10(%rbp),%eax
sub    $0x61,%eax
je     11b9 <__stdio_parse_mode+0xb9>
jmp    1148 <__stdio_parse_mode+0x48>
mov    -0x10(%rbp),%eax
sub    $0x62,%eax
je     1180 <__stdio_parse_mode+0x80>
jmp    1159 <__stdio_parse_mode+0x59>
mov    -0x10(%rbp),%eax
sub    $0x72,%eax
je     1185 <__stdio_parse_mode+0x85>
jmp    116a <__stdio_parse_mode+0x6a>
mov    -0x10(%rbp),%eax
sub    $0x77,%eax
je     1196 <__stdio_parse_mode+0x96>
jmp    11f9 <__stdio_parse_mode+0xf9>
mov    -0xc(%rbp),%eax
pop    %rbp
ret
jmp    11f9 <__stdio_parse_mode+0xf9>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
jmp    11f9 <__stdio_parse_mode+0xf9>
mov    0x2e1b(%rip),%rax
mov    (%rax),%eax
mov    0x2e52(%rip),%rcx
or     (%rcx),%eax
mov    0x2e41(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0xc(%rbp)
jmp    11f9 <__stdio_parse_mode+0xf9>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    0x2e2f(%rip),%rcx
or     (%rcx),%eax
mov    0x2dde(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0xc(%rbp)
jmp    11f9 <__stdio_parse_mode+0xf9>
mov    -0xc(%rbp),%eax
mov    0x2dd2(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    0x2de4(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    110f <__stdio_parse_mode+0xf>

x86 assembly (clang, -O2):
<__stdio_parse_mode>:
mov    0x2eb1(%rip),%rax
mov    (%rax),%r8d
mov    0x2ee7(%rip),%rax
mov    (%rax),%r9d
or     %r8d,%r9d
mov    0x2e92(%rip),%rax
mov    (%rax),%r11d
or     %r9d,%r11d
mov    0x2ec5(%rip),%rax
or     (%rax),%r9d
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
not    %r8d
mov    0x2e97(%rip),%rax
mov    (%rax),%r10d
xor    %eax,%eax
jmp    1156 <__stdio_parse_mode+0x56>
and    %r8d,%eax
or     %r10d,%eax
mov    %eax,%ecx
add    $0x1,%rdi
mov    %ecx,%eax
movsbl (%rdi),%edx
cmp    $0x71,%edx
jg     1180 <__stdio_parse_mode+0x80>
cmp    $0x2b,%edx
je     1148 <__stdio_parse_mode+0x48>
mov    %r11d,%ecx
cmp    $0x61,%edx
je     1150 <__stdio_parse_mode+0x50>
test   %edx,%edx
jne    114e <__stdio_parse_mode+0x4e>
jmp    1193 <__stdio_parse_mode+0x93>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %esi,%ecx
cmp    $0x72,%edx
je     1150 <__stdio_parse_mode+0x50>
mov    %eax,%ecx
cmp    $0x77,%edx
jne    1150 <__stdio_parse_mode+0x50>
mov    %r9d,%ecx
jmp    1150 <__stdio_parse_mode+0x50>
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_APPEND = global i32 0
@O_RDWR = global i32 0
define i32 @__stdio_parse_mode(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %32, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
switch i32 %7, label %32 [
i32 0, label %8
i32 98, label %10
i32 114, label %11
i32 119, label %13
i32 97, label %19
i32 43, label %25
]
8: ; preds = %4
%9 = load i32, i32* %3
ret i32 %9
10: ; preds = %4
br label %32
11: ; preds = %4
%12 = load i32, i32* @O_RDONLY
store i32 %12, i32* %3
br label %32
13: ; preds = %4
%14 = load i32, i32* @O_WRONLY
%15 = load i32, i32* @O_CREAT
%16 = or i32 %14, %15
%17 = load i32, i32* @O_TRUNC
%18 = or i32 %16, %17
store i32 %18, i32* %3
br label %32
19: ; preds = %4
%20 = load i32, i32* @O_WRONLY
%21 = load i32, i32* @O_CREAT
%22 = or i32 %20, %21
%23 = load i32, i32* @O_APPEND
%24 = or i32 %22, %23
store i32 %24, i32* %3
br label %32
25: ; preds = %4
%26 = load i32, i32* %3
%27 = load i32, i32* @O_WRONLY
%28 = xor i32 %27, -1
%29 = and i32 %26, %28
%30 = load i32, i32* @O_RDWR
%31 = or i32 %29, %30
store i32 %31, i32* %3
br label %32
32: ; preds = %4, %25, %19, %13, %11, %10
%33 = load i8*, i8** %2
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %2
br label %4
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_APPEND = global i32 0
@O_RDWR = global i32 0
define i32 @__stdio_parse_mode(i8* nocapture %0) {
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_CREAT
%4 = or i32 %3, %2
%5 = load i32, i32* @O_APPEND
%6 = or i32 %4, %5
%7 = load i32, i32* @O_TRUNC
%8 = or i32 %4, %7
%9 = load i32, i32* @O_RDONLY
%10 = xor i32 %2, -1
%11 = load i32, i32* @O_RDWR
br label %12
12: ; preds = %24, %1
%13 = phi i8* [ %0, %1 ], [ %26, %24 ]
%14 = phi i32 [ 0, %1 ], [ %25, %24 ]
%15 = load i8, i8* %13
%16 = sext i8 %15 to i32
switch i32 %16, label %24 [
i32 0, label %17
i32 43, label %21
i32 114, label %18
i32 119, label %19
i32 97, label %20
]
17: ; preds = %12
ret i32 %14
18: ; preds = %12
br label %24
19: ; preds = %12
br label %24
20: ; preds = %12
br label %24
21: ; preds = %12
%22 = and i32 %14, %10
%23 = or i32 %22, %11
br label %24
24: ; preds = %12, %21, %20, %19, %18
%25 = phi i32 [ %14, %12 ], [ %6, %20 ], [ %8, %19 ], [ %9, %18 ], [ %23, %21 ]
%26 = getelementptr inbounds i8, i8* %13, i64 1
br label %12
}