#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*/ STDERR_FILENO;
int /*<<< orphan*/ dprintf(int /*<<< orphan*/, char *, ...);
void printhex(unsigned char *buf, int len) {
  int ptr = 0;
  int lineptr;
  unsigned char ascii[17];
  ascii[16] = 0;
  while (ptr < len) {
    lineptr = 0;
    dprintf(STDERR_FILENO, "%04x  ", ptr);
    while (ptr < len && lineptr < 16) {
      if (lineptr == 8)
        dprintf(STDERR_FILENO, "    %02X ", buf[ptr]);
      else
        dprintf(STDERR_FILENO, "%02X ", buf[ptr]);
      if (buf[ptr] > 31 && buf[ptr] < 127)
        ascii[lineptr] = buf[ptr];
      else
        ascii[lineptr] = '.';
      ptr++;
      lineptr++;
    }
    if (lineptr < 16)
      ascii[lineptr] = 0;
    dprintf(STDERR_FILENO, " %s \n", ascii);
  }
}


x86 assembly (clang, -O0):
<printhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movb   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    126c <printhex+0x15c>
movl   $0x0,-0x14(%rbp)
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xeb0(%rip),%rsi
mov    $0x0,%al
call   1030 <dprintf@plt>
mov    -0x10(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x31(%rbp)
jge    1172 <printhex+0x62>
cmpl   $0x10,-0x14(%rbp)
setl   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1182 <printhex+0x72>
jmp    1239 <printhex+0x129>
cmpl   $0x8,-0x14(%rbp)
jne    11b4 <printhex+0xa4>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1030 <dprintf@plt>
jmp    11d7 <printhex+0xc7>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1030 <dprintf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x1f,%eax
jle    1219 <printhex+0x109>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7f,%eax
jge    1219 <printhex+0x109>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0x30(%rbp,%rax,1)
jmp    1222 <printhex+0x112>
movslq -0x14(%rbp),%rax
movb   $0x2e,-0x30(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1157 <printhex+0x47>
cmpl   $0x10,-0x14(%rbp)
jge    124c <printhex+0x13c>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1030 <dprintf@plt>
jmp    112a <printhex+0x1a>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printhex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,0x18(%rsp)
movb   $0x0,0x30(%rsp)
test   %esi,%esi
jle    1250 <printhex+0x140>
mov    %esi,%ebx
mov    %esi,%r14d
mov    0x2ea4(%rip),%r15
lea    0xebd(%rip),%rbp
lea    0xec1(%rip),%r13
lea    0xec0(%rip),%r12
xor    %eax,%eax
mov    %esi,0x14(%rsp)
jmp    1186 <printhex+0x76>
nopl   0x0(%rax)
xor    %eax,%eax
movb   $0x0,0x20(%rsp,%rax,1)
mov    (%r15),%edi
mov    %r12,%rsi
lea    0x20(%rsp),%rdx
xor    %eax,%eax
call   1030 <dprintf@plt>
mov    0x8(%rsp),%rax
cmp    %ebx,%eax
jge    1250 <printhex+0x140>
mov    %rax,0x8(%rsp)
mov    (%r15),%edi
mov    %rbp,%rsi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1030 <dprintf@plt>
mov    0x8(%rsp),%rax
cmp    %ebx,%eax
jge    1160 <printhex+0x50>
movslq %eax,%rbp
mov    0x18(%rsp),%rax
lea    (%rax,%rbp,1),%r12
add    $0x1,%rbp
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
mov    %rax,%rbx
cmp    $0x8,%rax
mov    (%r15),%edi
movzbl (%r12,%rax,1),%edx
mov    %r13,%rsi
lea    0xe2e(%rip),%rax
cmove  %rax,%rsi
xor    %eax,%eax
call   1030 <dprintf@plt>
movzbl (%r12,%rbx,1),%eax
lea    -0x20(%rax),%ecx
cmp    $0x5f,%cl
mov    $0x2e,%ecx
cmovae %ecx,%eax
mov    %al,0x20(%rsp,%rbx,1)
lea    0x1(%rbx),%rax
lea    (%rbx,%rbp,1),%rcx
cmp    %r14,%rcx
jge    120e <printhex+0xfe>
cmp    $0xf,%rbx
jb     11c0 <printhex+0xb0>
mov    0x8(%rsp),%rcx
mov    %ecx,%ecx
add    %rax,%rcx
cmp    $0xf,%rbx
lea    0xdee(%rip),%r12
mov    %rcx,0x8(%rsp)
jae    1240 <printhex+0x130>
mov    0x14(%rsp),%ebx
lea    0xdcb(%rip),%rbp
jmp    1162 <printhex+0x52>
nopw   0x0(%rax,%rax,1)
mov    0x14(%rsp),%ebx
lea    0xdb5(%rip),%rbp
jmp    1167 <printhex+0x57>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@STDERR_FILENO = global i32 0
@.str = [7 x i8] c"%04x \00"
@.str.1 = [10 x i8] c" %02X \00"
@.str.2 = [6 x i8] c"%02X \00"
@.str.3 = [6 x i8] c" %s \0A\00"
define void @printhex(i8* nocapture %0, i32 %1) {
%3 = alloca [17 x i8]
%4 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 16
store i8 0, i8* %5
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %48
7: ; preds = %2
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %43
%10 = phi i32 [ %44, %43 ], [ 0, %7 ]
%11 = load i32, i32* @STDERR_FILENO
%12 = call i32 (i32, i8*, ...) @dprintf(i32 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %10)
%13 = icmp slt i32 %10, %1
br i1 %13, label %14, label %39
14: ; preds = %9
%15 = sext i32 %10 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ %15, %14 ], [ %32, %16 ]
%18 = phi i64 [ 0, %14 ], [ %33, %16 ]
%19 = icmp eq i64 %18, 8
%20 = load i32, i32* @STDERR_FILENO
%21 = getelementptr inbounds i8, i8* %0, i64 %17
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = select i1 %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%25 = call i32 (i32, i8*, ...) @dprintf(i32 %20, i8* %24, i32 %23)
%26 = getelementptr inbounds i8, i8* %0, i64 %17
%27 = load i8, i8* %26
%28 = add i8 %27, -32
%29 = icmp ult i8 %28, 95
%30 = select i1 %29, i8 %27, i8 46
%31 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %18
store i8 %30, i8* %31
%32 = add nsw i64 %17, 1
%33 = add nuw nsw i64 %18, 1
%34 = icmp slt i64 %32, %8
%35 = icmp ult i64 %18, 15
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %16, label %37
37: ; preds = %16
%38 = trunc i64 %32 to i32
br i1 %35, label %39, label %43
39: ; preds = %9, %37
%40 = phi i64 [ %33, %37 ], [ 0, %9 ]
%41 = phi i32 [ %38, %37 ], [ %10, %9 ]
%42 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %40
store i8 0, i8* %42
br label %43
43: ; preds = %39, %37
%44 = phi i32 [ %41, %39 ], [ %38, %37 ]
%45 = load i32, i32* @STDERR_FILENO
%46 = call i32 (i32, i8*, ...) @dprintf(i32 %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%47 = icmp slt i32 %44, %1
br i1 %47, label %9, label %48
48: ; preds = %43, %2
ret void
}