int jas_strtoopenmode(const char *s) {
  int openmode = 0;
  while (*s != '\0') {
    switch (*s) {
    case 'r':
      openmode |= 0x0001;
      break;
    case 'w':
      openmode |= 0x0002 | 0x0010;
      break;
    case 'b':
      openmode |= 0x0008;
      break;
    case 'a':
      openmode |= 0x0004;
      break;
    case '+':
      openmode |= 0x0001 | 0x0002;
      break;
    default:
      break;
    }
    ++s;
  }
  return openmode;
}


x86 assembly (clang, -O0):
<jas_strtoopenmode>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d7 <jas_strtoopenmode+0xd7>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x10(%rbp)
sub    $0x2b,%eax
je     11b3 <jas_strtoopenmode+0xb3>
jmp    1137 <jas_strtoopenmode+0x37>
mov    -0x10(%rbp),%eax
sub    $0x61,%eax
je     11a5 <jas_strtoopenmode+0xa5>
jmp    1148 <jas_strtoopenmode+0x48>
mov    -0x10(%rbp),%eax
sub    $0x62,%eax
je     1197 <jas_strtoopenmode+0x97>
jmp    1159 <jas_strtoopenmode+0x59>
mov    -0x10(%rbp),%eax
sub    $0x72,%eax
je     117b <jas_strtoopenmode+0x7b>
jmp    116a <jas_strtoopenmode+0x6a>
mov    -0x10(%rbp),%eax
sub    $0x77,%eax
je     1189 <jas_strtoopenmode+0x89>
jmp    11c1 <jas_strtoopenmode+0xc1>
mov    -0xc(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11c6 <jas_strtoopenmode+0xc6>
mov    -0xc(%rbp),%eax
or     $0x12,%eax
mov    %eax,-0xc(%rbp)
jmp    11c6 <jas_strtoopenmode+0xc6>
mov    -0xc(%rbp),%eax
or     $0x8,%eax
mov    %eax,-0xc(%rbp)
jmp    11c6 <jas_strtoopenmode+0xc6>
mov    -0xc(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0xc(%rbp)
jmp    11c6 <jas_strtoopenmode+0xc6>
mov    -0xc(%rbp),%eax
or     $0x3,%eax
mov    %eax,-0xc(%rbp)
jmp    11c6 <jas_strtoopenmode+0xc6>
jmp    11c6 <jas_strtoopenmode+0xc6>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    110f <jas_strtoopenmode+0xf>
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<jas_strtoopenmode>:
mov    (%rdi),%dl
test   %dl,%dl
je     1165 <jas_strtoopenmode+0x65>
add    $0x1,%rdi
xor    %eax,%eax
lea    0xeed(%rip),%rcx
jmp    112b <jas_strtoopenmode+0x2b>
or     $0x4,%eax
nopl   0x0(%rax,%rax,1)
movzbl (%rdi),%edx
add    $0x1,%rdi
test   %dl,%dl
je     1164 <jas_strtoopenmode+0x64>
movsbl %dl,%edx
lea    -0x61(%rdx),%esi
cmp    $0x16,%esi
ja     1150 <jas_strtoopenmode+0x50>
movslq (%rcx,%rsi,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
or     $0x8,%eax
jmp    1120 <jas_strtoopenmode+0x20>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x2b,%edx
jne    1120 <jas_strtoopenmode+0x20>
or     $0x3,%eax
jmp    1120 <jas_strtoopenmode+0x20>
or     $0x1,%eax
jmp    1120 <jas_strtoopenmode+0x20>
or     $0x12,%eax
jmp    1120 <jas_strtoopenmode+0x20>
ret
xor    %eax,%eax
ret

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

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