#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 strlen(char const *);
int THMemoryFile_mode(const char *mode, int *isReadable, int *isWritable) {
  *isReadable = 0;
  *isWritable = 0;
  if (strlen(mode) == 1) {
    if (*mode == 'r') {
      *isReadable = 1;
      return 1;
    } else if (*mode == 'w') {
      *isWritable = 1;
      return 1;
    }
  } else if (strlen(mode) == 2) {
    if (mode[0] == 'r' && mode[1] == 'w') {
      *isReadable = 1;
      *isWritable = 1;
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<THMemoryFile_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jne    11a0 <THMemoryFile_mode+0x90>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x72,%eax
jne    1170 <THMemoryFile_mode+0x60>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1204 <THMemoryFile_mode+0xf4>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x77,%eax
jne    1196 <THMemoryFile_mode+0x86>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1204 <THMemoryFile_mode+0xf4>
jmp    119b <THMemoryFile_mode+0x8b>
jmp    11fd <THMemoryFile_mode+0xed>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jne    11f8 <THMemoryFile_mode+0xe8>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x72,%eax
jne    11f3 <THMemoryFile_mode+0xe3>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x77,%eax
jne    11f3 <THMemoryFile_mode+0xe3>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1204 <THMemoryFile_mode+0xf4>
jmp    11f8 <THMemoryFile_mode+0xe8>
jmp    11fd <THMemoryFile_mode+0xed>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<THMemoryFile_mode>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
movl   $0x0,(%rsi)
movl   $0x0,(%rdx)
call   1030 <strlen@plt>
cmp    $0x1,%eax
jne    1147 <THMemoryFile_mode+0x37>
mov    (%rbx),%cl
cmp    $0x72,%cl
je     116d <THMemoryFile_mode+0x5d>
xor    %eax,%eax
mov    %r14,%r15
cmp    $0x77,%cl
je     116d <THMemoryFile_mode+0x5d>
jmp    1179 <THMemoryFile_mode+0x69>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x2,%ecx
jne    1179 <THMemoryFile_mode+0x69>
cmpb   $0x72,(%rbx)
jne    1179 <THMemoryFile_mode+0x69>
cmpb   $0x77,0x1(%rbx)
jne    1179 <THMemoryFile_mode+0x69>
movl   $0x1,(%r15)
mov    %r14,%r15
movl   $0x1,(%r15)
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @THMemoryFile_mode(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%8 = load i32*, i32** %6
store i32 0, i32* %8
%9 = load i32*, i32** %7
store i32 0, i32* %9
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %29
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 114
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = load i32*, i32** %6
store i32 1, i32* %19
store i32 1, i32* %4
br label %51
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 119
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i32*, i32** %7
store i32 1, i32* %26
store i32 1, i32* %4
br label %51
27: ; preds = %20
br label %28
28: ; preds = %27
br label %50
29: ; preds = %3
%30 = load i8*, i8** %5
%31 = call i32 @strlen(i8* %30)
%32 = icmp eq i32 %31, 2
br i1 %32, label %33, label %49
33: ; preds = %29
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 114
br i1 %38, label %39, label %48
39: ; preds = %33
%40 = load i8*, i8** %5
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 119
br i1 %44, label %45, label %48
45: ; preds = %39
%46 = load i32*, i32** %6
store i32 1, i32* %46
%47 = load i32*, i32** %7
store i32 1, i32* %47
store i32 1, i32* %4
br label %51
48: ; preds = %39, %33
br label %49
49: ; preds = %48, %29
br label %50
50: ; preds = %49, %28
store i32 0, i32* %4
br label %51
51: ; preds = %50, %45, %25, %18
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
define i32 @THMemoryFile_mode(i8* %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
store i32 0, i32* %1
store i32 0, i32* %2
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = load i8, i8* %0
switch i8 %7, label %22 [
i8 114, label %20
i8 119, label %8
]
8: ; preds = %6
br label %20
9: ; preds = %3
%10 = tail call i32 @strlen(i8* %0)
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %22
12: ; preds = %9
%13 = load i8, i8* %0
%14 = icmp eq i8 %13, 114
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %0, i64 1
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 119
br i1 %18, label %19, label %22
19: ; preds = %15
store i32 1, i32* %1
br label %20
20: ; preds = %6, %8, %19
%21 = phi i32* [ %2, %19 ], [ %2, %8 ], [ %1, %6 ]
store i32 1, i32* %21
br label %22
22: ; preds = %20, %12, %15, %9, %6
%23 = phi i32 [ 0, %6 ], [ 0, %9 ], [ 0, %15 ], [ 0, %12 ], [ 1, %20 ]
ret i32 %23
}