#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*/ byte2hex(unsigned char, char *);
int /*<<< orphan*/ cout_h(unsigned int);
int /*<<< orphan*/ uart_write(char);
int /*<<< orphan*/ uart_write_str(char *);
void uart_dump_mem(unsigned char *start_addr, unsigned char *end_addr) {
  char tmp[3];
  char cntChars;
  if (start_addr > end_addr)
    return;
  do {
    cout_h((unsigned int)start_addr);
    uart_write_str("  ");
    cntChars = 0;
    do {
      byte2hex(*start_addr, &tmp[0]);
      uart_write_str(tmp);
      cntChars++;
      start_addr++;
      if (cntChars == 16)
        uart_write_str("\r\n");
      else if (cntChars % 4 == 0) {
        uart_write(' ');
      }
    } while ((start_addr <= end_addr) && (cntChars < 16));
  } while (start_addr <= end_addr);
  uart_write_str("\r\n");
}


x86 assembly (clang, -O0):
<uart_dump_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    1163 <uart_dump_mem+0x23>
jmp    1243 <uart_dump_mem+0x103>
jmp    1168 <uart_dump_mem+0x28>
mov    -0x8(%rbp),%rax
mov    %eax,%edi
call   1060 <cout_h@plt>
lea    0xe86(%rip),%rdi
call   1030 <uart_write_str@plt>
movb   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
lea    -0x13(%rbp),%rsi
movzbl %al,%edi
call   1040 <byte2hex@plt>
lea    -0x13(%rbp),%rdi
call   1030 <uart_write_str@plt>
mov    -0x14(%rbp),%al
add    $0x1,%al
mov    %al,-0x14(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
movsbl -0x14(%rbp),%eax
cmp    $0x10,%eax
jne    11d0 <uart_dump_mem+0x90>
lea    0xe3d(%rip),%rdi
call   1030 <uart_write_str@plt>
jmp    11f4 <uart_dump_mem+0xb4>
movsbl -0x14(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11ef <uart_dump_mem+0xaf>
mov    $0x20,%edi
call   1050 <uart_write@plt>
jmp    11f4 <uart_dump_mem+0xb4>
jmp    11f9 <uart_dump_mem+0xb9>
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x15(%rbp)
ja     1219 <uart_dump_mem+0xd9>
movsbl -0x14(%rbp),%eax
cmp    $0x10,%eax
setl   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1183 <uart_dump_mem+0x43>
jmp    1229 <uart_dump_mem+0xe9>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    1168 <uart_dump_mem+0x28>
lea    0xdc5(%rip),%rdi
call   1030 <uart_write_str@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_dump_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %rsi,%rdi
ja     11dd <uart_dump_mem+0x9d>
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xe9f(%rip),%r15
lea    0x5(%rsp),%r12
lea    0xe96(%rip),%r13
mov    %ebp,%edi
call   1060 <cout_h@plt>
mov    %r15,%rdi
call   1030 <uart_write_str@plt>
mov    $0x1,%bl
jmp    1188 <uart_dump_mem+0x48>
add    $0x1,%bl
cmp    %r14,%rbp
ja     11d1 <uart_dump_mem+0x91>
movzbl 0x0(%rbp),%edi
mov    %r12,%rsi
call   1040 <byte2hex@plt>
mov    %r12,%rdi
call   1030 <uart_write_str@plt>
cmp    $0x10,%bl
je     11c0 <uart_dump_mem+0x80>
add    $0x1,%rbp
test   $0x3,%bl
jne    1180 <uart_dump_mem+0x40>
mov    $0x20,%edi
call   1050 <uart_write@plt>
jmp    1180 <uart_dump_mem+0x40>
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1030 <uart_write_str@plt>
add    $0x1,%rbp
cmp    %r14,%rbp
jbe    116d <uart_dump_mem+0x2d>
lea    0xe2b(%rip),%rdi
call   1030 <uart_write_str@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c" \00"
@.str.1 = [3 x i8] c"\0D\0A\00"
define void @uart_dump_mem(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [3 x i8]
%6 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = load i8*, i8** %4
%9 = icmp ugt i8* %7, %8
br i1 %9, label %10, label %11
10: ; preds = %2
br label %59
11: ; preds = %2
br label %12
12: ; preds = %53, %11
%13 = load i8*, i8** %3
%14 = ptrtoint i8* %13 to i32
%15 = call i32 @cout_h(i32 %14)
%16 = call i32 @uart_write_str(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8 0, i8* %6
br label %17
17: ; preds = %50, %12
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%21 = call i32 @byte2hex(i8 zeroext %19, i8* %20)
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%23 = call i32 @uart_write_str(i8* %22)
%24 = load i8, i8* %6
%25 = add i8 %24, 1
store i8 %25, i8* %6
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
%28 = load i8, i8* %6
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 16
br i1 %30, label %31, label %33
31: ; preds = %17
%32 = call i32 @uart_write_str(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %41
33: ; preds = %17
%34 = load i8, i8* %6
%35 = sext i8 %34 to i32
%36 = srem i32 %35, 4
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @uart_write(i8 signext 32)
br label %40
40: ; preds = %38, %33
br label %41
41: ; preds = %40, %31
br label %42
42: ; preds = %41
%43 = load i8*, i8** %3
%44 = load i8*, i8** %4
%45 = icmp ule i8* %43, %44
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i8, i8* %6
%48 = sext i8 %47 to i32
%49 = icmp slt i32 %48, 16
br label %50
50: ; preds = %46, %42
%51 = phi i1 [ false, %42 ], [ %49, %46 ]
br i1 %51, label %17, label %52
52: ; preds = %50
br label %53
53: ; preds = %52
%54 = load i8*, i8** %3
%55 = load i8*, i8** %4
%56 = icmp ule i8* %54, %55
br i1 %56, label %12, label %57
57: ; preds = %53
%58 = call i32 @uart_write_str(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %59
59: ; preds = %57, %10
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c" \00"
@.str.1 = [3 x i8] c"\0D\0A\00"
define void @uart_dump_mem(i8* %0, i8* readnone %1) {
%3 = alloca [3 x i8]
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%5 = icmp ugt i8* %0, %1
br i1 %5, label %33, label %6
6: ; preds = %2, %21
%7 = phi i8* [ %19, %21 ], [ %0, %2 ]
%8 = ptrtoint i8* %7 to i64
%9 = trunc i64 %8 to i32
%10 = call i32 @cout_h(i32 %9)
%11 = call i32 @uart_write_str(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %29, %6
%13 = phi i8* [ %7, %6 ], [ %19, %29 ]
%14 = phi i8 [ 0, %6 ], [ %18, %29 ]
%15 = load i8, i8* %13
%16 = call i32 @byte2hex(i8 zeroext %15, i8* %4)
%17 = call i32 @uart_write_str(i8* %4)
%18 = add nuw nsw i8 %14, 1
%19 = getelementptr inbounds i8, i8* %13, i64 1
%20 = icmp eq i8 %18, 16
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = call i32 @uart_write_str(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp ugt i8* %19, %1
br i1 %23, label %31, label %6
24: ; preds = %12
%25 = and i8 %18, 3
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @uart_write(i8 signext 32)
br label %29
29: ; preds = %27, %24
%30 = icmp ugt i8* %19, %1
br i1 %30, label %31, label %12
31: ; preds = %21, %29
%32 = call i32 @uart_write_str(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %2, %31
ret void
}