#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 */
typedef int mode_t;

/* Variables and functions */
int R_OK;
int W_OK;
int X_OK;
unsigned int strlen(char const *);
mode_t pfs_resolve_parse_mode(const char *options) {
  unsigned int i;
  int mode = 0;
  for (i = 0; i < strlen(options); i++) {
    if (options[i] == 'r' || options[i] == 'R') {
      mode |= R_OK;
    } else if (options[i] == 'w' || options[i] == 'W') {
      mode |= W_OK;
    } else if (options[i] == 'x' || options[i] == 'X') {
      mode |= X_OK;
    } else {
      return -1;
    }
  }
  return mode;
}


x86 assembly (clang, -O0):
<pfs_resolve_parse_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jae    1223 <pfs_resolve_parse_mode+0x113>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x72,%eax
je     116e <pfs_resolve_parse_mode+0x5e>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x52,%eax
jne    1182 <pfs_resolve_parse_mode+0x72>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1210 <pfs_resolve_parse_mode+0x100>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x77,%eax
je     11aa <pfs_resolve_parse_mode+0x9a>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x57,%eax
jne    11be <pfs_resolve_parse_mode+0xae>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    120b <pfs_resolve_parse_mode+0xfb>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x78,%eax
je     11e6 <pfs_resolve_parse_mode+0xd6>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x58,%eax
jne    11fa <pfs_resolve_parse_mode+0xea>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
or     -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1206 <pfs_resolve_parse_mode+0xf6>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <pfs_resolve_parse_mode+0x119>
jmp    120b <pfs_resolve_parse_mode+0xfb>
jmp    1210 <pfs_resolve_parse_mode+0x100>
jmp    1215 <pfs_resolve_parse_mode+0x105>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112a <pfs_resolve_parse_mode+0x1a>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pfs_resolve_parse_mode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
je     11ab <pfs_resolve_parse_mode+0x9b>
xor    %ebx,%ebx
mov    0x2e9c(%rip),%r15
movabs $0x100000001,%r12
movabs $0x2000000020,%r13
xor    %ebp,%ebp
jmp    116e <pfs_resolve_parse_mode+0x5e>
nopl   0x0(%rax)
mov    0x2e91(%rip),%rdx
or     (%rdx),%ebp
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cmp    %rcx,%rbx
jae    11ad <pfs_resolve_parse_mode+0x9d>
movzbl (%r14,%rbx,1),%ecx
mov    $0xffffffff,%eax
add    $0xae,%cl
cmp    $0x26,%cl
ja     11ad <pfs_resolve_parse_mode+0x9d>
movzbl %cl,%ecx
bt     %rcx,%r12
mov    %r15,%rdx
jb     1157 <pfs_resolve_parse_mode+0x47>
bt     %rcx,%r13
jb     1150 <pfs_resolve_parse_mode+0x40>
movabs $0x4000000040,%rdx
bt     %rcx,%rdx
jae    11ad <pfs_resolve_parse_mode+0x9d>
mov    0x2e37(%rip),%rdx
jmp    1157 <pfs_resolve_parse_mode+0x47>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
define i32 @pfs_resolve_parse_mode(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
store i32 0, i32* %4
br label %6
6: ; preds = %75, %1
%7 = load i32, i32* %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = icmp ult i32 %7, %9
br i1 %10, label %11, label %78
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 114
br i1 %18, label %27, label %19
19: ; preds = %11
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 82
br i1 %26, label %27, label %31
27: ; preds = %19, %11
%28 = load i32, i32* @R_OK
%29 = load i32, i32* %5
%30 = or i32 %29, %28
store i32 %30, i32* %5
br label %74
31: ; preds = %19
%32 = load i8*, i8** %3
%33 = load i32, i32* %4
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 119
br i1 %38, label %47, label %39
39: ; preds = %31
%40 = load i8*, i8** %3
%41 = load i32, i32* %4
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 87
br i1 %46, label %47, label %51
47: ; preds = %39, %31
%48 = load i32, i32* @W_OK
%49 = load i32, i32* %5
%50 = or i32 %49, %48
store i32 %50, i32* %5
br label %73
51: ; preds = %39
%52 = load i8*, i8** %3
%53 = load i32, i32* %4
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 120
br i1 %58, label %67, label %59
59: ; preds = %51
%60 = load i8*, i8** %3
%61 = load i32, i32* %4
%62 = zext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 88
br i1 %66, label %67, label %71
67: ; preds = %59, %51
%68 = load i32, i32* @X_OK
%69 = load i32, i32* %5
%70 = or i32 %69, %68
store i32 %70, i32* %5
br label %72
71: ; preds = %59
store i32 -1, i32* %2
br label %80
72: ; preds = %67
br label %73
73: ; preds = %72, %47
br label %74
74: ; preds = %73, %27
br label %75
75: ; preds = %74
%76 = load i32, i32* %4
%77 = add i32 %76, 1
store i32 %77, i32* %4
br label %6
78: ; preds = %6
%79 = load i32, i32* %5
store i32 %79, i32* %2
br label %80
80: ; preds = %78, %71
%81 = load i32, i32* %2
ret i32 %81
}

LLVM IR (-O2):
@R_OK = global i32 0
@W_OK = global i32 0
@X_OK = global i32 0
define i32 @pfs_resolve_parse_mode(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %19, label %4
4: ; preds = %1, %11
%5 = phi i64 [ %15, %11 ], [ 0, %1 ]
%6 = phi i32 [ %14, %11 ], [ 0, %1 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %5
%8 = load i8, i8* %7
switch i8 %8, label %19 [
i8 114, label %11
i8 82, label %11
i8 119, label %9
i8 87, label %9
i8 120, label %10
i8 88, label %10
]
9: ; preds = %4, %4
br label %11
10: ; preds = %4, %4
br label %11
11: ; preds = %4, %4, %10, %9
%12 = phi i32* [ @W_OK, %9 ], [ @X_OK, %10 ], [ @R_OK, %4 ], [ @R_OK, %4 ]
%13 = load i32, i32* %12
%14 = or i32 %13, %6
%15 = add nuw nsw i64 %5, 1
%16 = tail call i32 @strlen(i8* %0)
%17 = zext i32 %16 to i64
%18 = icmp ult i64 %15, %17
br i1 %18, label %4, label %19
19: ; preds = %4, %11, %1
%20 = phi i32 [ 0, %1 ], [ %14, %11 ], [ -1, %4 ]
ret i32 %20
}