#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*/ printf(char *, ...);
void memread_memory(unsigned long phys_addr, void *addr, int len, int iosize) {
  int i;
  while (len) {
    printf("%08lx: ", phys_addr);
    i = 0;
    while (i < 16 && len) {
      switch (iosize) {
      case 1:
        printf(" %02x", *(unsigned char *)addr);
        break;
      case 2:
        printf(" %04x", *(unsigned short *)addr);
        break;
      case 4:
        printf(" %08lx", *(unsigned long *)addr);
        break;
      }
      i += iosize;
      addr += iosize;
      len -= iosize;
    }
    phys_addr += 16;
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<memread_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     123a <memread_memory+0x12a>
mov    -0x8(%rbp),%rsi
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x10,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jge    1162 <memread_memory+0x52>
cmpl   $0x0,-0x14(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1172 <memread_memory+0x62>
jmp    121b <memread_memory+0x10b>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x1,%eax
je     11a8 <memread_memory+0x98>
jmp    1186 <memread_memory+0x76>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
je     11c2 <memread_memory+0xb2>
jmp    1197 <memread_memory+0x87>
mov    -0x24(%rbp),%eax
sub    $0x4,%eax
je     11dc <memread_memory+0xcc>
jmp    11f1 <memread_memory+0xe1>
mov    -0x10(%rbp),%rax
movzbl (%rax),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f1 <memread_memory+0xe1>
mov    -0x10(%rbp),%rax
movzwl (%rax),%esi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f1 <memread_memory+0xe1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
jmp    1149 <memread_memory+0x39>
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1126 <memread_memory+0x16>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memread_memory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     1201 <memread_memory+0xe1>
mov    %ecx,%r15d
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
movslq %ecx,%r12
jmp    116b <memread_memory+0x4b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rsp),%rbx
add    $0x10,%rbx
mov    $0xa,%edi
call   1030 <putchar@plt>
sub    %r13d,%r14d
je     1201 <memread_memory+0xe1>
lea    0xe8e(%rip),%rdi
mov    %rbx,(%rsp)
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15d,%ebx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
cmp    $0x4,%r15d
je     11b0 <memread_memory+0x90>
cmp    $0x2,%r15d
je     11d0 <memread_memory+0xb0>
cmp    $0x1,%r15d
jne    11e2 <memread_memory+0xc2>
movzbl 0x0(%rbp),%esi
lea    0xe5b(%rip),%rdi
jmp    11db <memread_memory+0xbb>
nop
mov    0x0(%rbp),%rsi
lea    0xe59(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e2 <memread_memory+0xc2>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzwl 0x0(%rbp),%esi
lea    0xe33(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    %r15d,%r13d
add    %r12,%rbp
cmp    $0xf,%ebx
jg     1150 <memread_memory+0x30>
lea    (%rbx,%r15,1),%eax
cmp    %ebx,%r14d
mov    %eax,%ebx
jne    1190 <memread_memory+0x70>
jmp    1150 <memread_memory+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%08lx: \00"
@.str.1 = [6 x i8] c" %02x\00"
@.str.2 = [6 x i8] c" %04x\00"
@.str.3 = [7 x i8] c" %08lx\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @memread_memory(i64 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i64 %0, i64* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
br label %10
10: ; preds = %53, %4
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %57
13: ; preds = %10
%14 = load i64, i64* %5
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %14)
store i32 0, i32* %9
br label %16
16: ; preds = %42, %13
%17 = load i32, i32* %9
%18 = icmp slt i32 %17, 16
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 0
br label %22
22: ; preds = %19, %16
%23 = phi i1 [ false, %16 ], [ %21, %19 ]
br i1 %23, label %24, label %53
24: ; preds = %22
%25 = load i32, i32* %8
switch i32 %25, label %42 [
i32 1, label %26
i32 2, label %31
i32 4, label %37
]
26: ; preds = %24
%27 = load i8*, i8** %6
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %42
31: ; preds = %24
%32 = load i8*, i8** %6
%33 = bitcast i8* %32 to i16*
%34 = load i16, i16* %33
%35 = zext i16 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %42
37: ; preds = %24
%38 = load i8*, i8** %6
%39 = bitcast i8* %38 to i64*
%40 = load i64, i64* %39
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %40)
br label %42
42: ; preds = %24, %37, %31, %26
%43 = load i32, i32* %8
%44 = load i32, i32* %9
%45 = add nsw i32 %44, %43
store i32 %45, i32* %9
%46 = load i32, i32* %8
%47 = load i8*, i8** %6
%48 = sext i32 %46 to i64
%49 = getelementptr i8, i8* %47, i64 %48
store i8* %49, i8** %6
%50 = load i32, i32* %8
%51 = load i32, i32* %7
%52 = sub nsw i32 %51, %50
store i32 %52, i32* %7
br label %16
53: ; preds = %22
%54 = load i64, i64* %5
%55 = add i64 %54, 16
store i64 %55, i64* %5
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %10
57: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%08lx: \00"
@.str.1 = [6 x i8] c" %02x\00"
@.str.2 = [6 x i8] c" %04x\00"
@.str.3 = [7 x i8] c" %08lx\00"
define void @memread_memory(i64 %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %2, 0
br i1 %5, label %41, label %6
6: ; preds = %4
%7 = sext i32 %3 to i64
br label %8
8: ; preds = %6, %37
%9 = phi i64 [ %0, %6 ], [ %38, %37 ]
%10 = phi i32 [ %2, %6 ], [ %33, %37 ]
%11 = phi i8* [ %1, %6 ], [ %32, %37 ]
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %9)
br label %13
13: ; preds = %8, %30
%14 = phi i32 [ 0, %8 ], [ %31, %30 ]
%15 = phi i32 [ %10, %8 ], [ %33, %30 ]
%16 = phi i8* [ %11, %8 ], [ %32, %30 ]
switch i32 %3, label %30 [
i32 1, label %17
i32 2, label %21
i32 4, label %26
]
17: ; preds = %13
%18 = load i8, i8* %16
%19 = zext i8 %18 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %30
21: ; preds = %13
%22 = bitcast i8* %16 to i16*
%23 = load i16, i16* %22
%24 = zext i16 %23 to i32
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %24)
br label %30
26: ; preds = %13
%27 = bitcast i8* %16 to i64*
%28 = load i64, i64* %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %28)
br label %30
30: ; preds = %13, %26, %21, %17
%31 = add nsw i32 %14, %3
%32 = getelementptr i8, i8* %16, i64 %7
%33 = sub nsw i32 %15, %3
%34 = icmp slt i32 %31, 16
%35 = icmp ne i32 %33, 0
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %13, label %37
37: ; preds = %30
%38 = add i64 %9, 16
%39 = tail call i32 @putchar(i32 10)
%40 = icmp eq i32 %33, 0
br i1 %40, label %41, label %8
41: ; preds = %37, %4
ret void
}