char *au_check_openmode(char *mode) {
  int i, j = 0;
  static char buf[10];
  for (i = 0, j = 0; mode[i] != '\0' && i < 9; i++) {
    switch (mode[i]) {
    case 'r':
    case 'w':
    case 'a':
    case '+':
      buf[j] = mode[i];
      j++;
      break;
    }
  }
  buf[j] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<au_check_openmode>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     1141 <au_check_openmode+0x41>
cmpl   $0x9,-0xc(%rbp)
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1151 <au_check_openmode+0x51>
jmp    11d6 <au_check_openmode+0xd6>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x18(%rbp)
sub    $0x2b,%eax
je     11a1 <au_check_openmode+0xa1>
jmp    116e <au_check_openmode+0x6e>
mov    -0x18(%rbp),%eax
sub    $0x61,%eax
je     11a1 <au_check_openmode+0xa1>
jmp    117f <au_check_openmode+0x7f>
mov    -0x18(%rbp),%eax
sub    $0x72,%eax
je     11a1 <au_check_openmode+0xa1>
jmp    1190 <au_check_openmode+0x90>
mov    -0x18(%rbp),%eax
sub    $0x77,%eax
jne    11c3 <au_check_openmode+0xc3>
jmp    11a1 <au_check_openmode+0xa1>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
movslq -0x10(%rbp),%rcx
lea    0x2e6a(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11c8 <au_check_openmode+0xc8>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    111d <au_check_openmode+0x1d>
movslq -0x10(%rbp),%rcx
lea    0x2e40(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e35(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<au_check_openmode>:
mov    (%rdi),%dl
test   %dl,%dl
je     1159 <au_check_openmode+0x59>
xor    %ecx,%ecx
lea    0x2f12(%rip),%r9
mov    $0x420001,%r8d
xor    %r10d,%r10d
nopl   0x0(%rax,%rax,1)
movsbl %dl,%esi
lea    -0x61(%rsi),%eax
cmp    $0x16,%eax
ja     1131 <au_check_openmode+0x31>
bt     %eax,%r8d
jb     1136 <au_check_openmode+0x36>
cmp    $0x2b,%esi
jne    1141 <au_check_openmode+0x41>
movslq %r10d,%r10
mov    %dl,(%r10,%r9,1)
add    $0x1,%r10d
movzbl 0x1(%rdi,%rcx,1),%edx
test   %dl,%dl
je     115c <au_check_openmode+0x5c>
lea    0x1(%rcx),%rax
cmp    $0x8,%rcx
mov    %rax,%rcx
jb     1120 <au_check_openmode+0x20>
jmp    115c <au_check_openmode+0x5c>
xor    %r10d,%r10d
movslq %r10d,%rcx
lea    0x2ebb(%rip),%rax
movb   $0x0,(%rcx,%rax,1)
ret

LLVM IR (-O0):
@au_check_openmode.buf = internal global [10 x i8] zeroinitializer
define i8* @au_check_openmode(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
store i32 0, i32* %3
store i32 0, i32* %4
br label %5
5: ; preds = %37, %1
%6 = load i8*, i8** %2
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %5
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 9
br label %16
16: ; preds = %13, %5
%17 = phi i1 [ false, %5 ], [ %15, %13 ]
br i1 %17, label %18, label %40
18: ; preds = %16
%19 = load i8*, i8** %2
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
switch i32 %24, label %36 [
i32 114, label %25
i32 119, label %25
i32 97, label %25
i32 43, label %25
]
25: ; preds = %18, %18, %18, %18
%26 = load i8*, i8** %2
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [10 x i8], [10 x i8]* @au_check_openmode.buf, i64 0, i64 %32
store i8 %30, i8* %33
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %36
36: ; preds = %18, %25
br label %37
37: ; preds = %36
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %5
40: ; preds = %16
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [10 x i8], [10 x i8]* @au_check_openmode.buf, i64 0, i64 %42
store i8 0, i8* %43
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @au_check_openmode.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@au_check_openmode.buf = internal global [10 x i8] zeroinitializer
define i8* @au_check_openmode(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %21, label %4
4: ; preds = %1, %13
%5 = phi i64 [ %15, %13 ], [ 0, %1 ]
%6 = phi i8 [ %17, %13 ], [ %2, %1 ]
%7 = phi i32 [ %14, %13 ], [ 0, %1 ]
%8 = sext i8 %6 to i32
switch i32 %8, label %13 [
i32 114, label %9
i32 119, label %9
i32 97, label %9
i32 43, label %9
]
9: ; preds = %4, %4, %4, %4
%10 = sext i32 %7 to i64
%11 = getelementptr inbounds [10 x i8], [10 x i8]* @au_check_openmode.buf, i64 0, i64 %10
store i8 %6, i8* %11
%12 = add nsw i32 %7, 1
br label %13
13: ; preds = %9, %4
%14 = phi i32 [ %7, %4 ], [ %12, %9 ]
%15 = add nuw nsw i64 %5, 1
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
%19 = icmp ult i64 %5, 8
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %4, label %21
21: ; preds = %13, %1
%22 = phi i32 [ 0, %1 ], [ %14, %13 ]
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [10 x i8], [10 x i8]* @au_check_openmode.buf, i64 0, i64 %23
store i8 0, i8* %24
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @au_check_openmode.buf, i64 0, i64 0)
}