#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 */
typedef int uint8_t;
typedef int uint32_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void print_mem(void *addr, uint32_t count, uint32_t size) {
  int i;
  uint8_t *addr8 = addr;
  uint16_t *addr16 = addr;
  uint32_t *addr32 = addr;
  uint32_t g_paddr;
  g_paddr = (uint32_t)addr;
  switch (size) {
  case 1:
    for (i = 0; i < count; i++) {
      if ((i % 16) == 0)
        printf("\n0x%08X: ", g_paddr);
      printf(" %02X", addr8[i]);
      g_paddr++;
    }
    break;
  case 2:
    for (i = 0; i < count; i++) {
      if ((i % 8) == 0)
        printf("\n0x%08X: ", g_paddr);
      printf(" %04X", addr16[i]);
      g_paddr += 2;
    }
    break;
  case 4:
    for (i = 0; i < count; i++) {
      if ((i % 4) == 0)
        printf("\n0x%08X: ", g_paddr);
      printf(" %08X", addr32[i]);
      g_paddr += 4;
    }
    break;
  default:
    printf("error value!\n");
    break;
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<print_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x1,%eax
je     1176 <print_mem+0x66>
jmp    1154 <print_mem+0x44>
mov    -0x38(%rbp),%eax
sub    $0x2,%eax
je     11e3 <print_mem+0xd3>
jmp    1165 <print_mem+0x55>
mov    -0x38(%rbp),%eax
sub    $0x4,%eax
je     1250 <print_mem+0x140>
jmp    12bd <print_mem+0x1ad>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11de <print_mem+0xce>
mov    -0x14(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ae <print_mem+0x9e>
mov    -0x34(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <print_mem+0x6d>
jmp    12cb <print_mem+0x1bb>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    124b <print_mem+0x13b>
mov    -0x14(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    121b <print_mem+0x10b>
mov    -0x34(%rbp),%esi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ea <print_mem+0xda>
jmp    12cb <print_mem+0x1bb>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12b8 <print_mem+0x1a8>
mov    -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1288 <print_mem+0x178>
mov    -0x34(%rbp),%esi
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1257 <print_mem+0x147>
jmp    12cb <print_mem+0x1bb>
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
cmp    $0x1,%edx
je     11a2 <print_mem+0x82>
cmp    $0x2,%edx
je     11ed <print_mem+0xcd>
cmp    $0x4,%edx
jne    123e <print_mem+0x11e>
test   %esi,%esi
jle    124a <print_mem+0x12a>
mov    %esi,%r12d
lea    0xea9(%rip),%r14
lea    0xeb8(%rip),%r15
xor    %ebx,%ebx
mov    %r13d,%ebp
jmp    118f <print_mem+0x6f>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x4,%ebp
add    $0x1,%rbx
cmp    %rbx,%r12
je     124a <print_mem+0x12a>
test   $0x3,%bl
jne    1170 <print_mem+0x50>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1170 <print_mem+0x50>
test   %esi,%esi
jle    124a <print_mem+0x12a>
mov    %esi,%ebp
lea    0xe4d(%rip),%r14
lea    0xe50(%rip),%r15
xor    %ebx,%ebx
jmp    11d8 <print_mem+0xb8>
xchg   %ax,%ax
mov    0x0(%r13,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
je     124a <print_mem+0x12a>
test   $0xf,%bl
jne    11c0 <print_mem+0xa0>
lea    (%rbx,%r13,1),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c0 <print_mem+0xa0>
test   %esi,%esi
jle    124a <print_mem+0x12a>
mov    %esi,%r12d
lea    0xe05(%rip),%r14
lea    0xe0e(%rip),%r15
xor    %ebx,%ebx
mov    %r13d,%ebp
jmp    122b <print_mem+0x10b>
nopl   0x0(%rax)
mov    0x0(%r13,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x2,%ebp
add    $0x1,%rbx
cmp    %rbx,%r12
je     124a <print_mem+0x12a>
test   $0x7,%bl
jne    1210 <print_mem+0xf0>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1210 <print_mem+0xf0>
lea    0xdd9(%rip),%rdi
call   1030 <puts@plt>
lea    0xdcb(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"\0A0x%08X: \00"
@.str.1 = [6 x i8] c" %02X\00"
@.str.2 = [6 x i8] c" %04X\00"
@.str.3 = [6 x i8] c" %08X\00"
@.str.4 = [14 x i8] c"error value!\0A\00"
@.str.5 = [3 x i8] c"\0A\0A\00"
define void @print_mem(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i8*, i8** %4
%13 = bitcast i8* %12 to i32*
store i32* %13, i32** %8
%14 = load i8*, i8** %4
%15 = bitcast i8* %14 to i32*
store i32* %15, i32** %9
%16 = load i8*, i8** %4
%17 = bitcast i8* %16 to i32*
store i32* %17, i32** %10
%18 = load i8*, i8** %4
%19 = ptrtoint i8* %18 to i32
store i32 %19, i32* %11
%20 = load i32, i32* %6
switch i32 %20, label %96 [
i32 1, label %21
i32 2, label %46
i32 4, label %71
]
21: ; preds = %3
store i32 0, i32* %7
br label %22
22: ; preds = %42, %21
%23 = load i32, i32* %7
%24 = load i32, i32* %5
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %45
26: ; preds = %22
%27 = load i32, i32* %7
%28 = srem i32 %27, 16
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* %11
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %26
%34 = load i32*, i32** %8
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %11
%41 = add nsw i32 %40, 1
store i32 %41, i32* %11
br label %42
42: ; preds = %33
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %22
45: ; preds = %22
br label %98
46: ; preds = %3
store i32 0, i32* %7
br label %47
47: ; preds = %67, %46
%48 = load i32, i32* %7
%49 = load i32, i32* %5
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %70
51: ; preds = %47
%52 = load i32, i32* %7
%53 = srem i32 %52, 8
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = load i32, i32* %11
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %56)
br label %58
58: ; preds = %55, %51
%59 = load i32*, i32** %9
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
%63 = load i32, i32* %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %63)
%65 = load i32, i32* %11
%66 = add nsw i32 %65, 2
store i32 %66, i32* %11
br label %67
67: ; preds = %58
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
store i32 %69, i32* %7
br label %47
70: ; preds = %47
br label %98
71: ; preds = %3
store i32 0, i32* %7
br label %72
72: ; preds = %92, %71
%73 = load i32, i32* %7
%74 = load i32, i32* %5
%75 = icmp slt i32 %73, %74
br i1 %75, label %76, label %95
76: ; preds = %72
%77 = load i32, i32* %7
%78 = srem i32 %77, 4
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %76
%81 = load i32, i32* %11
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %81)
br label %83
83: ; preds = %80, %76
%84 = load i32*, i32** %10
%85 = load i32, i32* %7
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i32, i32* %84, i64 %86
%88 = load i32, i32* %87
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %88)
%90 = load i32, i32* %11
%91 = add nsw i32 %90, 4
store i32 %91, i32* %11
br label %92
92: ; preds = %83
%93 = load i32, i32* %7
%94 = add nsw i32 %93, 1
store i32 %94, i32* %7
br label %72
95: ; preds = %72
br label %98
96: ; preds = %3
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %98
98: ; preds = %96, %95, %70, %45
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"\0A0x%08X: \00"
@.str.1 = [6 x i8] c" %02X\00"
@.str.2 = [6 x i8] c" %04X\00"
@.str.3 = [6 x i8] c" %08X\00"
@str = [2 x i8] c"\0A\00"
@str.6 = [13 x i8] c"error value!\00"
define void @print_mem(i8* %0, i32 %1, i32 %2) {
%4 = bitcast i8* %0 to i32*
%5 = ptrtoint i8* %0 to i64
%6 = trunc i64 %5 to i32
switch i32 %2, label %61 [
i32 1, label %15
i32 2, label %11
i32 4, label %7
]
7: ; preds = %3
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %63
9: ; preds = %7
%10 = zext i32 %1 to i64
br label %47
11: ; preds = %3
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %63
13: ; preds = %11
%14 = zext i32 %1 to i64
br label %33
15: ; preds = %3
%16 = icmp sgt i32 %1, 0
br i1 %16, label %17, label %63
17: ; preds = %15
%18 = zext i32 %1 to i64
br label %19
19: ; preds = %17, %26
%20 = phi i64 [ 0, %17 ], [ %31, %26 ]
%21 = phi i32 [ %6, %17 ], [ %30, %26 ]
%22 = and i64 %20, 15
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %26
26: ; preds = %24, %19
%27 = getelementptr inbounds i32, i32* %4, i64 %20
%28 = load i32, i32* %27
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = add nsw i32 %21, 1
%31 = add nuw nsw i64 %20, 1
%32 = icmp eq i64 %31, %18
br i1 %32, label %63, label %19
33: ; preds = %13, %40
%34 = phi i64 [ 0, %13 ], [ %45, %40 ]
%35 = phi i32 [ %6, %13 ], [ %44, %40 ]
%36 = and i64 %34, 7
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %35)
br label %40
40: ; preds = %38, %33
%41 = getelementptr inbounds i32, i32* %4, i64 %34
%42 = load i32, i32* %41
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = add nsw i32 %35, 2
%45 = add nuw nsw i64 %34, 1
%46 = icmp eq i64 %45, %14
br i1 %46, label %63, label %33
47: ; preds = %9, %54
%48 = phi i64 [ 0, %9 ], [ %59, %54 ]
%49 = phi i32 [ %6, %9 ], [ %58, %54 ]
%50 = and i64 %48, 3
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %47
%53 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %49)
br label %54
54: ; preds = %52, %47
%55 = getelementptr inbounds i32, i32* %4, i64 %48
%56 = load i32, i32* %55
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %56)
%58 = add nsw i32 %49, 4
%59 = add nuw nsw i64 %48, 1
%60 = icmp eq i64 %59, %10
br i1 %60, label %63, label %47
61: ; preds = %3
%62 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.6, i64 0, i64 0))
br label %63
63: ; preds = %54, %40, %26, %7, %11, %15, %61
%64 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
ret void
}