#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 *, unsigned char);
void printHex(unsigned short size, unsigned char contentP[],
              unsigned char showhat) {
  unsigned short i = 0;
  for (; i < size; i++) {
    if (showhat == 1)
      printf("%c", *(contentP + i));
    else if (showhat == 2) {
      if (*(contentP + i) < 0x10)
        printf("0x0%x ", *(contentP + i));
      else
        printf("0x%x ", *(contentP + i));
    } else {
      if (*(contentP + i) < 0x10)
        printf("0%x", *(contentP + i));
      else
        printf("%x", *(contentP + i));
    }
  }
}


x86 assembly (clang, -O0):
<printHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %di,%cx
mov    %cx,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movw   $0x0,-0x14(%rbp)
movzwl -0x14(%rbp),%eax
movzwl -0x2(%rbp),%ecx
cmp    %ecx,%eax
jge    1243 <printHex+0x133>
movzbl -0x11(%rbp),%eax
cmp    $0x1,%eax
jne    116b <printHex+0x5b>
mov    -0x10(%rbp),%rax
movzwl -0x14(%rbp),%ecx
movslq %ecx,%rcx
lea    0xea3(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
jmp    122d <printHex+0x11d>
movzbl -0x11(%rbp),%eax
cmp    $0x2,%eax
jne    11d0 <printHex+0xc0>
mov    -0x10(%rbp),%rax
movzwl -0x14(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x10,%eax
jge    11b0 <printHex+0xa0>
mov    -0x10(%rbp),%rax
movzwl -0x14(%rbp),%ecx
movslq %ecx,%rcx
lea    0xe61(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
jmp    11cb <printHex+0xbb>
mov    -0x10(%rbp),%rax
movzwl -0x14(%rbp),%ecx
movslq %ecx,%rcx
lea    0xe48(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
jmp    1228 <printHex+0x118>
mov    -0x10(%rbp),%rax
movzwl -0x14(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x10,%eax
jge    1208 <printHex+0xf8>
mov    -0x10(%rbp),%rax
movzwl -0x14(%rbp),%ecx
movslq %ecx,%rcx
lea    0xe16(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
jmp    1223 <printHex+0x113>
mov    -0x10(%rbp),%rax
movzwl -0x14(%rbp),%ecx
movslq %ecx,%rcx
lea    0xdf7(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
jmp    1228 <printHex+0x118>
jmp    122d <printHex+0x11d>
jmp    1232 <printHex+0x122>
mov    -0x14(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x14(%rbp)
jmp    112e <printHex+0x1e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printHex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
je     11a3 <printHex+0x93>
mov    %edx,%ebx
mov    %rsi,%r14
movzwl %di,%r12d
xor    %ebp,%ebp
lea    0xecb(%rip),%r13
lea    0xed5(%rip),%r15
jmp    1156 <printHex+0x46>
xchg   %ax,%ax
movzbl (%r14,%rbp,1),%esi
mov    %r13,%rdi
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
je     11a3 <printHex+0x93>
cmp    $0x2,%bl
je     1180 <printHex+0x70>
cmp    $0x1,%bl
je     1140 <printHex+0x30>
movzbl (%r14,%rbp,1),%eax
movzbl %al,%esi
cmp    $0xf,%al
ja     1195 <printHex+0x85>
lea    0xe9d(%rip),%rdi
jmp    1148 <printHex+0x38>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r14,%rbp,1),%eax
movzbl %al,%esi
cmp    $0xf,%al
ja     119a <printHex+0x8a>
lea    0xe70(%rip),%rdi
jmp    1148 <printHex+0x38>
mov    %r15,%rdi
jmp    1148 <printHex+0x38>
lea    0xe69(%rip),%rdi
jmp    1148 <printHex+0x38>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.1 = [7 x i8] c"0x0%x \00"
@.str.2 = [6 x i8] c"0x%x \00"
@.str.3 = [4 x i8] c"0%x\00"
@.str.4 = [3 x i8] c"%x\00"
define void @printHex(i16 zeroext %0, i8* nocapture %1, i8 zeroext %2) {
%4 = icmp eq i16 %0, 0
br i1 %4, label %32, label %5
5: ; preds = %3
%6 = zext i16 %0 to i64
br label %7
7: ; preds = %5, %29
%8 = phi i64 [ 0, %5 ], [ %30, %29 ]
switch i8 %2, label %21 [
i8 1, label %9
i8 2, label %13
]
9: ; preds = %7
%10 = getelementptr inbounds i8, i8* %1, i64 %8
%11 = load i8, i8* %10
%12 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %11)
br label %29
13: ; preds = %7
%14 = getelementptr inbounds i8, i8* %1, i64 %8
%15 = load i8, i8* %14
%16 = icmp ult i8 %15, 16
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %15)
br label %29
19: ; preds = %13
%20 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %15)
br label %29
21: ; preds = %7
%22 = getelementptr inbounds i8, i8* %1, i64 %8
%23 = load i8, i8* %22
%24 = icmp ult i8 %23, 16
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8 zeroext %23)
br label %29
27: ; preds = %21
%28 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8 zeroext %23)
br label %29
29: ; preds = %9, %25, %27, %17, %19
%30 = add nuw nsw i64 %8, 1
%31 = icmp eq i64 %30, %6
br i1 %31, label %32, label %7
32: ; preds = %29, %3
ret void
}