#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int);
int /*<<< orphan*/ stderr;
char detectRegion(unsigned char *data) {
  unsigned checksum =
      (unsigned int)(((&data[0x10])[0] << 24) + ((&data[0x10])[1] << 16) +
                     ((&data[0x10])[2] << 8) + ((&data[0x10])[3]));
  switch (checksum) {
  case 0xA03CF036:
    return 'E';
  case 0x4EAA3D0E:
    return 'J';
  case 0xD6FBA4A8:
    return 'S';
  case 0x635A2BFF:
    return 'U';
  default:
    fprintf(stderr, "Unknown ROM checksum: 0x%08X\n", checksum);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<detectRegion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%eax
bswap  %eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0xa03cf036,%eax
je     1187 <detectRegion+0x67>
jmp    114e <detectRegion+0x2e>
mov    -0x18(%rbp),%eax
sub    $0xd6fba4a8,%eax
je     1199 <detectRegion+0x79>
jmp    1161 <detectRegion+0x41>
mov    -0x18(%rbp),%eax
sub    $0x4eaa3d0e,%eax
je     1190 <detectRegion+0x70>
jmp    1174 <detectRegion+0x54>
mov    -0x18(%rbp),%eax
sub    $0x635a2bff,%eax
je     11a2 <detectRegion+0x82>
jmp    11ab <detectRegion+0x8b>
movb   $0x45,-0x1(%rbp)
jmp    11cd <detectRegion+0xad>
movb   $0x4a,-0x1(%rbp)
jmp    11cd <detectRegion+0xad>
movb   $0x53,-0x1(%rbp)
jmp    11cd <detectRegion+0xad>
movb   $0x55,-0x1(%rbp)
jmp    11cd <detectRegion+0xad>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe42(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detectRegion>:
push   %rax
mov    0x10(%rdi),%edx
bswap  %edx
cmp    $0x4eaa3d0d,%edx
jg     1144 <detectRegion+0x24>
mov    $0x45,%al
cmp    $0xa03cf036,%edx
je     115a <detectRegion+0x3a>
cmp    $0xd6fba4a8,%edx
jne    115c <detectRegion+0x3c>
mov    $0x53,%al
pop    %rcx
ret
cmp    $0x635a2bff,%edx
je     1158 <detectRegion+0x38>
cmp    $0x4eaa3d0e,%edx
jne    115c <detectRegion+0x3c>
mov    $0x4a,%al
pop    %rcx
ret
mov    $0x55,%al
pop    %rcx
ret
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Unknown ROM checksum: 0x%08X\0A\00"
define signext i8 @detectRegion(i8* %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i64 16
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = zext i8 %8 to i32
%10 = shl i32 %9, 24
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 16
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = shl i32 %15, 16
%17 = add nsw i32 %10, %16
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 16
%20 = getelementptr inbounds i8, i8* %19, i64 2
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = shl i32 %22, 8
%24 = add nsw i32 %17, %23
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 16
%27 = getelementptr inbounds i8, i8* %26, i64 3
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = add nsw i32 %24, %29
store i32 %30, i32* %4
%31 = load i32, i32* %4
switch i32 %31, label %36 [
i32 -1606619082, label %32
i32 1319779598, label %33
i32 -688151384, label %34
i32 1666853887, label %35
]
32: ; preds = %1
store i8 69, i8* %2
br label %41
33: ; preds = %1
store i8 74, i8* %2
br label %41
34: ; preds = %1
store i8 83, i8* %2
br label %41
35: ; preds = %1
store i8 85, i8* %2
br label %41
36: ; preds = %1
%37 = load i32, i32* @stderr
%38 = load i32, i32* %4
%39 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %35, %34, %33, %32
%42 = load i8, i8* %2
ret i8 %42
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Unknown ROM checksum: 0x%08X\0A\00"
define signext i8 @detectRegion(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 16
%3 = load i8, i8* %2
%4 = zext i8 %3 to i32
%5 = shl nuw i32 %4, 24
%6 = getelementptr inbounds i8, i8* %0, i64 17
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = shl nuw nsw i32 %8, 16
%10 = or i32 %9, %5
%11 = getelementptr inbounds i8, i8* %0, i64 18
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = shl nuw nsw i32 %13, 8
%15 = or i32 %10, %14
%16 = getelementptr inbounds i8, i8* %0, i64 19
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = or i32 %15, %18
switch i32 %19, label %23 [
i32 -1606619082, label %27
i32 1319779598, label %20
i32 -688151384, label %21
i32 1666853887, label %22
]
20: ; preds = %1
br label %27
21: ; preds = %1
br label %27
22: ; preds = %1
br label %27
23: ; preds = %1
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %19)
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %1, %22, %21, %20
%28 = phi i8 [ 85, %22 ], [ 83, %21 ], [ 74, %20 ], [ 69, %1 ]
ret i8 %28
}