#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 0x40000000:
    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     1174 <fetch32+0x34>
jmp    1161 <fetch32+0x21>
mov    -0x10(%rbp),%eax
sub    $0x40000000,%eax
je     1209 <fetch32+0xc9>
jmp    121f <fetch32+0xdf>
cmpl   $0x50,-0x8(%rbp)
jae    1204 <fetch32+0xc4>
mov    -0x8(%rbp),%edi
call   1050 <read32@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    119e <fetch32+0x5e>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125b <fetch32+0x11b>
cmpl   $0x4,-0x8(%rbp)
jne    11b3 <fetch32+0x73>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125b <fetch32+0x11b>
cmpl   $0x3c,-0x8(%rbp)
jne    11c8 <fetch32+0x88>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125b <fetch32+0x11b>
mov    0x2e11(%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    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1209 <fetch32+0xc9>
mov    -0x8(%rbp),%edi
call   1050 <read32@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125b <fetch32+0x11b>
mov    0x2dba(%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    0xdda(%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    $0x40000000,%eax
je     1181 <fetch32+0x41>
test   %eax,%eax
jne    118e <fetch32+0x4e>
cmp    $0x4f,%ebx
ja     1181 <fetch32+0x41>
mov    %ebx,%edi
call   1050 <read32@plt>
cmp    $0x3c,%ebx
ja     11bf <fetch32+0x7f>
mov    %ebx,%ecx
movabs $0x1000000000000011,%rdx
bt     %rcx,%rdx
jae    11bf <fetch32+0x7f>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <read32@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%ebp
mov    $0xf,%edi
call   1030 <read_register@plt>
lea    0xe7c(%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    0x2e1a(%rip),%rax
mov    (%rax),%ebp
mov    $0xf,%edi
call   1030 <read_register@plt>
lea    0xe27(%rip),%rsi
jmp    11a8 <fetch32+0x68>

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 %38 [
i32 0, label %7
i32 1073741824, label %34
]
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 %44
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 %44
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 %44
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 %44
38: ; preds = %1
%39 = load i32, i32* @stderr
%40 = load i32, i32* %3
%41 = call i32 @read_register(i32 15)
%42 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %40, i32 %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %34, %25, %20, %15
%45 = load i32, i32* %2
ret i32 %45
}

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 %14 [
i32 0, label %3
i32 1073741824, label %12
]
3: ; preds = %1
%4 = icmp ult i32 %0, 80
br i1 %4, label %5, label %12
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 = %3, %1
%13 = tail call i32 @read32(i32 %0)
br label %19
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = tail call i32 @read_register(i32 15)
%17 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %16)
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %5, %5, %5, %12
%20 = phi i32 [ %13, %12 ], [ %6, %5 ], [ %6, %5 ], [ %6, %5 ]
ret i32 %20
}