#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*/ uart_print_long(char *);
int /*<<< orphan*/ uart_print_str(char *);
void printHex(const void *lpvbits, const unsigned int n) {
  char *data = (char *)lpvbits;
  unsigned int i = 0;
  char line[17] = {};
  uart_print_str("Print Hex:\n");
  uart_print_long(data);
  while (i < n) {
    line[i % 16] = *(data + i);
    if ((line[i % 16] < 32) || (line[i % 16] > 126)) {
      line[i % 16] = '.';
    }
    uart_print_long(data + i);
    i++;
    if (i % 4 == 0) {
      if (i % 16 == 0) {
        if (i < n - 1)
          uart_print_long(data + i);
      } else {
        uart_print_str(" ");
      }
    }
  }
  while (i % 16 > 0) {
    (i % 4 == 0) ? uart_print_str("   ") : uart_print_str("   ");
    line[i % 16] = ' ';
    i++;
  }
  uart_print_str(" | ");
  uart_print_str(line);
  uart_print_long("\r");
}


x86 assembly (clang, -O0):
<printHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x11,%edx
call   1040 <memset@plt>
lea    0xe9b(%rip),%rdi
call   1050 <uart_print_str@plt>
mov    -0x18(%rbp),%rdi
call   1030 <uart_print_long@plt>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    123f <printHex+0x10f>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,1),%cl
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
mov    %eax,%eax
mov    %cl,-0x30(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
mov    %eax,%eax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x20,%eax
jl     11c1 <printHex+0x91>
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
mov    %eax,%eax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x7e,%eax
jle    11ce <printHex+0x9e>
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
mov    %eax,%eax
movb   $0x2e,-0x30(%rbp,%rax,1)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
call   1030 <uart_print_long@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
jne    123a <printHex+0x10a>
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    1229 <printHex+0xf9>
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jae    1224 <printHex+0xf4>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
call   1030 <uart_print_long@plt>
jmp    1235 <printHex+0x105>
lea    0xdde(%rip),%rdi
call   1050 <uart_print_str@plt>
jmp    123a <printHex+0x10a>
jmp    1173 <printHex+0x43>
jmp    1244 <printHex+0x114>
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jbe    129a <printHex+0x16a>
mov    -0x1c(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
jne    1273 <printHex+0x143>
lea    0xda3(%rip),%rdi
call   1050 <uart_print_str@plt>
jmp    127f <printHex+0x14f>
lea    0xd92(%rip),%rdi
call   1050 <uart_print_str@plt>
mov    -0x1c(%rbp),%eax
and    $0xf,%eax
mov    %eax,%eax
movb   $0x20,-0x30(%rbp,%rax,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1244 <printHex+0x114>
lea    0xd6f(%rip),%rdi
call   1050 <uart_print_str@plt>
lea    -0x30(%rbp),%rdi
call   1050 <uart_print_str@plt>
lea    0xd5e(%rip),%rdi
call   1030 <uart_print_long@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printHex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
lea    0xeb9(%rip),%rdi
call   1040 <uart_print_str@plt>
mov    %rbx,%rdi
call   1030 <uart_print_long@plt>
test   %r14d,%r14d
je     121c <printHex+0xfc>
lea    -0x1(%r14),%r12d
mov    %r14d,%r13d
neg    %r13
mov    $0x1,%ebp
mov    $0x2e,%r15d
jmp    11a1 <printHex+0x81>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xe87(%rip),%rdi
call   1040 <uart_print_str@plt>
lea    0x1(,%rbp,1),%rax
add    %r13,%rax
add    $0x1,%rbp
cmp    $0x1,%rax
je     11e2 <printHex+0xc2>
lea    -0x1(%rbp),%eax
lea    (%rbx,%rbp,1),%rdi
add    $0xffffffffffffffff,%rdi
movzbl -0x1(%rbx,%rbp,1),%ecx
and    $0xf,%eax
lea    -0x7f(%rcx),%edx
cmp    $0xa1,%dl
cmovb  %r15d,%ecx
mov    %cl,(%rsp,%rax,1)
call   1030 <uart_print_long@plt>
test   $0x3,%bpl
jne    118c <printHex+0x6c>
test   $0xf,%bpl
jne    1180 <printHex+0x60>
cmp    %r12,%rbp
jae    118c <printHex+0x6c>
lea    (%rbx,%rbp,1),%rdi
call   1030 <uart_print_long@plt>
jmp    118c <printHex+0x6c>
test   $0xf,%r14b
je     121c <printHex+0xfc>
mov    %r14d,%eax
and    $0xf,%eax
lea    (%rsp,%rax,1),%rbp
add    $0x1,%r14d
lea    0xe0f(%rip),%r15
mov    %r14d,%ebx
mov    %r15,%rdi
call   1040 <uart_print_str@plt>
movb   $0x20,0x0(%rbp)
add    $0x1,%rbp
add    $0x1,%ebx
test   $0xf,%r14b
mov    %ebx,%r14d
jne    1200 <printHex+0xe0>
lea    0xded(%rip),%rdi
call   1040 <uart_print_str@plt>
mov    %rsp,%rdi
call   1040 <uart_print_str@plt>
lea    0xddd(%rip),%rdi
call   1030 <uart_print_long@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"Print Hex:\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c" \00"
@.str.3 = [4 x i8] c" | \00"
@.str.4 = [2 x i8] c"\0D\00"
define void @printHex(i8* %0, i32 %1) {
%3 = alloca [17 x i8]
%4 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @uart_print_str(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @uart_print_long(i8* %0)
%7 = icmp eq i32 %1, 0
br i1 %7, label %53, label %8
8: ; preds = %2
%9 = add i32 %1, -1
%10 = zext i32 %9 to i64
%11 = zext i32 %1 to i64
br label %18
12: ; preds = %42
%13 = and i32 %1, 15
%14 = icmp eq i32 %13, 0
br i1 %14, label %53, label %15
15: ; preds = %12
%16 = and i32 %1, 15
%17 = zext i32 %16 to i64
br label %44
18: ; preds = %8, %42
%19 = phi i64 [ 0, %8 ], [ %28, %42 ]
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = and i64 %19, 15
%23 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %22
%24 = add i8 %21, -127
%25 = icmp ult i8 %24, -95
%26 = select i1 %25, i8 46, i8 %21
store i8 %26, i8* %23
%27 = tail call i32 @uart_print_long(i8* %20)
%28 = add nuw nsw i64 %19, 1
%29 = trunc i64 %28 to i32
%30 = and i32 %29, 3
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %18
%33 = and i32 %29, 15
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = icmp ult i64 %28, %10
br i1 %36, label %37, label %42
37: ; preds = %35
%38 = getelementptr inbounds i8, i8* %0, i64 %28
%39 = tail call i32 @uart_print_long(i8* %38)
br label %42
40: ; preds = %32
%41 = tail call i32 @uart_print_str(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %42
42: ; preds = %40, %37, %35, %18
%43 = icmp eq i64 %28, %11
br i1 %43, label %12, label %18
44: ; preds = %15, %44
%45 = phi i64 [ %17, %15 ], [ %50, %44 ]
%46 = phi i32 [ %1, %15 ], [ %49, %44 ]
%47 = tail call i32 @uart_print_str(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%48 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %45
store i8 32, i8* %48
%49 = add i32 %46, 1
%50 = add nuw nsw i64 %45, 1
%51 = trunc i32 %49 to i4
%52 = icmp eq i4 %51, 0
br i1 %52, label %53, label %44
53: ; preds = %44, %2, %12
%54 = tail call i32 @uart_print_str(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%55 = call i32 @uart_print_str(i8* %4)
%56 = call i32 @uart_print_long(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}