#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 */
scalar_t__ strcmp(char *, char *);
size_t strlen(char *);
char toupper(char);
int _file_explorer_is_valid_rom_type(char *name) {
  char extension[4];
  size_t len = strlen(name);
  extension[3] = '\0';
  extension[2] = toupper(name[len - 1]);
  extension[1] = toupper(name[len - 2]);
  extension[0] = toupper(name[len - 3]);
  if (strcmp(extension, "GBA") == 0)
    return 1;
  if (strcmp(extension, "AGB") == 0)
    return 1;
  if (strcmp(extension, "BIN") == 0)
    return 1;
  if (strcmp(extension, "GBC") == 0)
    return 1;
  if (strcmp(extension, "CGB") == 0)
    return 1;
  if (strcmp(extension, "SGB") == 0)
    return 1;
  extension[0] = extension[1];
  extension[1] = extension[2];
  extension[2] = '\0';
  if (strcmp(extension, "GB") == 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<_file_explorer_is_valid_rom_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,-0x12(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x2,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,-0x13(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x3,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <toupper@plt>
mov    %al,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11bb <_file_explorer_is_valid_rom_type+0x8b>
movl   $0x1,-0x4(%rbp)
jmp    12b6 <_file_explorer_is_valid_rom_type+0x186>
lea    -0x14(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11e1 <_file_explorer_is_valid_rom_type+0xb1>
movl   $0x1,-0x4(%rbp)
jmp    12b6 <_file_explorer_is_valid_rom_type+0x186>
lea    -0x14(%rbp),%rdi
lea    0xe1c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1207 <_file_explorer_is_valid_rom_type+0xd7>
movl   $0x1,-0x4(%rbp)
jmp    12b6 <_file_explorer_is_valid_rom_type+0x186>
lea    -0x14(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    122d <_file_explorer_is_valid_rom_type+0xfd>
movl   $0x1,-0x4(%rbp)
jmp    12b6 <_file_explorer_is_valid_rom_type+0x186>
lea    -0x14(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1253 <_file_explorer_is_valid_rom_type+0x123>
movl   $0x1,-0x4(%rbp)
jmp    12b6 <_file_explorer_is_valid_rom_type+0x186>
lea    -0x14(%rbp),%rdi
lea    0xdb6(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1279 <_file_explorer_is_valid_rom_type+0x149>
movl   $0x1,-0x4(%rbp)
jmp    12b6 <_file_explorer_is_valid_rom_type+0x186>
mov    -0x13(%rbp),%al
mov    %al,-0x14(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x13(%rbp)
movb   $0x0,-0x12(%rbp)
lea    -0x14(%rbp),%rdi
lea    0xd71(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12af <_file_explorer_is_valid_rom_type+0x17f>
movl   $0x1,-0x4(%rbp)
jmp    12b6 <_file_explorer_is_valid_rom_type+0x186>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_file_explorer_is_valid_rom_type>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rax,%r14
movb   $0x0,0x7(%rsp)
movsbl -0x1(%rax,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %al,0x6(%rsp)
movsbl -0x2(%r14,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %al,0x5(%rsp)
movsbl -0x3(%r14,%rbx,1),%edi
call   1030 <toupper@plt>
mov    %al,0x4(%rsp)
lea    0xe89(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1050 <strcmp@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     1229 <_file_explorer_is_valid_rom_type+0xf9>
lea    0xe6e(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1229 <_file_explorer_is_valid_rom_type+0xf9>
lea    0xe58(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1229 <_file_explorer_is_valid_rom_type+0xf9>
lea    0xe46(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1229 <_file_explorer_is_valid_rom_type+0xf9>
lea    0xe34(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1229 <_file_explorer_is_valid_rom_type+0xf9>
lea    0xe22(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1229 <_file_explorer_is_valid_rom_type+0xf9>
movzwl 0x5(%rsp),%eax
mov    %ax,0x4(%rsp)
movb   $0x0,0x6(%rsp)
lea    0xdee(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1050 <strcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
sete   %bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"GBA\00"
@.str.1 = [4 x i8] c"AGB\00"
@.str.2 = [4 x i8] c"BIN\00"
@.str.3 = [4 x i8] c"GBC\00"
@.str.4 = [4 x i8] c"CGB\00"
@.str.5 = [4 x i8] c"SGB\00"
@.str.6 = [3 x i8] c"GB\00"
define i32 @_file_explorer_is_valid_rom_type(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4 x i8]
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
store i64 %7, i64* %5
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 3
store i8 0, i8* %8
%9 = load i8*, i8** %3
%10 = load i64, i64* %5
%11 = sub i64 %10, 1
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = call signext i8 @toupper(i8 signext %13)
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
store i8 %14, i8* %15
%16 = load i8*, i8** %3
%17 = load i64, i64* %5
%18 = sub i64 %17, 2
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = call signext i8 @toupper(i8 signext %20)
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
store i8 %21, i8* %22
%23 = load i8*, i8** %3
%24 = load i64, i64* %5
%25 = sub i64 %24, 3
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = call signext i8 @toupper(i8 signext %27)
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
store i8 %28, i8* %29
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%31 = call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %1
store i32 1, i32* %2
br label %72
34: ; preds = %1
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 1, i32* %2
br label %72
39: ; preds = %34
%40 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%41 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %39
store i32 1, i32* %2
br label %72
44: ; preds = %39
%45 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %44
store i32 1, i32* %2
br label %72
49: ; preds = %44
%50 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%51 = call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %49
store i32 1, i32* %2
br label %72
54: ; preds = %49
%55 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%56 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %54
store i32 1, i32* %2
br label %72
59: ; preds = %54
%60 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%61 = load i8, i8* %60
%62 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
store i8 %61, i8* %62
%63 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
%64 = load i8, i8* %63
%65 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
store i8 %64, i8* %65
%66 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
store i8 0, i8* %66
%67 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%68 = call i64 @strcmp(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %71
70: ; preds = %59
store i32 1, i32* %2
br label %72
71: ; preds = %59
store i32 0, i32* %2
br label %72
72: ; preds = %71, %70, %58, %53, %48, %43, %38, %33
%73 = load i32, i32* %2
ret i32 %73
}

LLVM IR (-O2):
@.str = [4 x i8] c"GBA\00"
@.str.1 = [4 x i8] c"AGB\00"
@.str.2 = [4 x i8] c"BIN\00"
@.str.3 = [4 x i8] c"GBC\00"
@.str.4 = [4 x i8] c"CGB\00"
@.str.5 = [4 x i8] c"SGB\00"
@.str.6 = [3 x i8] c"GB\00"
define i32 @_file_explorer_is_valid_rom_type(i8* nocapture %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
store i8 0, i8* %5
%6 = add i64 %4, -1
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = tail call signext i8 @toupper(i8 signext %8)
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 2
store i8 %9, i8* %10
%11 = add i64 %4, -2
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = tail call signext i8 @toupper(i8 signext %13)
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 1
store i8 %14, i8* %15
%16 = add i64 %4, -3
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = tail call signext i8 @toupper(i8 signext %18)
store i8 %19, i8* %3
%20 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %43, label %22
22: ; preds = %1
%23 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %43, label %25
25: ; preds = %22
%26 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %43, label %28
28: ; preds = %25
%29 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %43, label %31
31: ; preds = %28
%32 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %43, label %34
34: ; preds = %31
%35 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %43, label %37
37: ; preds = %34
%38 = load i8, i8* %15
store i8 %38, i8* %3
%39 = load i8, i8* %10
store i8 %39, i8* %15
store i8 0, i8* %10
%40 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
%42 = zext i1 %41 to i32
br label %43
43: ; preds = %37, %34, %31, %28, %25, %22, %1
%44 = phi i32 [ 1, %1 ], [ 1, %22 ], [ 1, %25 ], [ 1, %28 ], [ 1, %31 ], [ 1, %34 ], [ %42, %37 ]
ret i32 %44
}