#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, ...);
unsigned int read32(unsigned int);
int read_register(int);
int /*<<< orphan*/ stderr;
unsigned int fetch32(unsigned int addr) {
  unsigned int data;
  if (0)
    fprintf(stderr, "fetch32(0x%08X)=", addr);
  if (0)
    fprintf(stderr, "fetch32(0x%08X)=", addr);
  switch (addr & 0xF0000000) {
  case 0x00000000:
    if (addr < 0x50) {
      data = read32(addr);
      if (0)
        fprintf(stderr, "0x%08X\n", data);
      if (0)
        fprintf(stderr, "0x%08X\n", data);
      if (addr == 0x00000000)
        return (data);
      if (addr == 0x00000004)
        return (data);
      if (addr == 0x0000003C)
        return (data);
      fprintf(stderr, "fetch32(0x%08X), abort pc = 0x%04X\n", addr,
              read_register(15));
      exit(1);
    }
  case 0x10000000:
    data = read32(addr);
    if (0)
      fprintf(stderr, "0x%08X\n", data);
    if (0)
      fprintf(stderr, "0x%08X\n", data);
    return (data);
  case 0x20000000:
    data = read32(addr);
    if (0)
      fprintf(stderr, "0x%08X\n", data);
    if (0)
      fprintf(stderr, "0x%08X\n", data);
    return (data);
  }
  fprintf(stderr, "fetch32(0x%08X), abort pc 0x%04X\n", addr,
          read_register(15));
  exit(1);
}


x86 assembly (clang, -O0):
<fetch32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0xf0000000,%eax
mov    %eax,-0x10(%rbp)
je     1187 <fetch32+0x47>
jmp    1161 <fetch32+0x21>
mov    -0x10(%rbp),%eax
sub    $0x10000000,%eax
je     121c <fetch32+0xdc>
jmp    1174 <fetch32+0x34>
mov    -0x10(%rbp),%eax
sub    $0x20000000,%eax
je     1232 <fetch32+0xf2>
jmp    1248 <fetch32+0x108>
cmpl   $0x50,-0x8(%rbp)
jae    1217 <fetch32+0xd7>
mov    -0x8(%rbp),%edi
call   1050 <read32@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11b1 <fetch32+0x71>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1284 <fetch32+0x144>
cmpl   $0x4,-0x8(%rbp)
jne    11c6 <fetch32+0x86>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1284 <fetch32+0x144>
cmpl   $0x3c,-0x8(%rbp)
jne    11db <fetch32+0x9b>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1284 <fetch32+0x144>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0xf,%edi
call   1030 <read_register@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%edx
mov    %eax,%ecx
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    121c <fetch32+0xdc>
mov    -0x8(%rbp),%edi
call   1050 <read32@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1284 <fetch32+0x144>
mov    -0x8(%rbp),%edi
call   1050 <read32@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1284 <fetch32+0x144>
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0xf,%edi
call   1030 <read_register@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%edx
mov    %eax,%ecx
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fetch32>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %edi,%eax
and    $0xf0000000,%eax
cmp    $0x20000000,%eax
je     1188 <fetch32+0x48>
cmp    $0x10000000,%eax
je     1188 <fetch32+0x48>
test   %eax,%eax
jne    1195 <fetch32+0x55>
cmp    $0x4f,%ebx
ja     1188 <fetch32+0x48>
mov    %ebx,%edi
call   1050 <read32@plt>
cmp    $0x3c,%ebx
ja     11c6 <fetch32+0x86>
mov    %ebx,%ecx
movabs $0x1000000000000011,%rdx
bt     %rcx,%rdx
jae    11c6 <fetch32+0x86>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <read32@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%ebp
mov    $0xf,%edi
call   1030 <read_register@plt>
lea    0xe75(%rip),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%ebp
mov    $0xf,%edi
call   1030 <read_register@plt>
lea    0xe20(%rip),%rsi
jmp    11af <fetch32+0x6f>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"fetch32(0x%08X), abort pc = 0x%04X\0A\00"
@.str.1 = [34 x i8] c"fetch32(0x%08X), abort pc 0x%04X\0A\00"
define i32 @fetch32(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = and i32 %5, -268435456
switch i32 %6, label %42 [
i32 0, label %7
i32 268435456, label %34
i32 536870912, label %38
]
7: ; preds = %1
%8 = load i32, i32* %3
%9 = icmp ult i32 %8, 80
br i1 %9, label %10, label %33
10: ; preds = %7
%11 = load i32, i32* %3
%12 = call i32 @read32(i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = load i32, i32* %4
store i32 %16, i32* %2
br label %48
17: ; preds = %10
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 4
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = load i32, i32* %4
store i32 %21, i32* %2
br label %48
22: ; preds = %17
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 60
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = load i32, i32* %4
store i32 %26, i32* %2
br label %48
27: ; preds = %22
%28 = load i32, i32* @stderr
%29 = load i32, i32* %3
%30 = call i32 @read_register(i32 15)
%31 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %29, i32 %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %7
br label %34
34: ; preds = %1, %33
%35 = load i32, i32* %3
%36 = call i32 @read32(i32 %35)
store i32 %36, i32* %4
%37 = load i32, i32* %4
store i32 %37, i32* %2
br label %48
38: ; preds = %1
%39 = load i32, i32* %3
%40 = call i32 @read32(i32 %39)
store i32 %40, i32* %4
%41 = load i32, i32* %4
store i32 %41, i32* %2
br label %48
42: ; preds = %1
%43 = load i32, i32* @stderr
%44 = load i32, i32* %3
%45 = call i32 @read_register(i32 15)
%46 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %44, i32 %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %38, %34, %25, %20, %15
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"fetch32(0x%08X), abort pc = 0x%04X\0A\00"
@.str.1 = [34 x i8] c"fetch32(0x%08X), abort pc 0x%04X\0A\00"
define i32 @fetch32(i32 %0) {
%2 = and i32 %0, -268435456
switch i32 %2, label %12 [
i32 0, label %3
i32 268435456, label %17
i32 536870912, label %17
]
3: ; preds = %1
%4 = icmp ult i32 %0, 80
br i1 %4, label %5, label %17
5: ; preds = %3
%6 = tail call i32 @read32(i32 %0)
switch i32 %0, label %7 [
i32 0, label %19
i32 4, label %19
i32 60, label %19
]
7: ; preds = %5
%8 = load i32, i32* @stderr
%9 = tail call i32 @read_register(i32 15)
%10 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = tail call i32 @read_register(i32 15)
%15 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %1, %1, %3
%18 = tail call i32 @read32(i32 %0)
br label %19
19: ; preds = %17, %5, %5, %5
%20 = phi i32 [ %6, %5 ], [ %6, %5 ], [ %6, %5 ], [ %18, %17 ]
ret i32 %20
}