#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 */
scalar_t__ isprint(unsigned char);
int /*<<< orphan*/ printerr(int, char *, ...);
void print_hex(int pri, unsigned char *cp, int length) {
  int i, j, jm;
  unsigned char c;
  for (i = 0; i < length; i += 0x10) {
    printerr(pri, "  %04x: ", (unsigned int)i);
    jm = length - i;
    jm = jm > 16 ? 16 : jm;
    for (j = 0; j < jm; j++) {
      if ((j % 2) == 1)
        printerr(pri, "%02x ", (unsigned int)cp[i + j]);
      else
        printerr(pri, "%02x", (unsigned int)cp[i + j]);
    }
    for (; j < 16; j++) {
      if ((j % 2) == 1)
        printerr(pri, "   ");
      else
        printerr(pri, "  ");
    }
    printerr(pri, " ");
    for (j = 0; j < jm; j++) {
      c = cp[i + j];
      c = isprint(c) ? c : '.';
      printerr(pri, "%c", c);
    }
    printerr(pri, "\n");
  }
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1310 <print_hex+0x1f0>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%edx
lea    0xeae(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x10,-0x20(%rbp)
jle    1179 <print_hex+0x59>
mov    $0x10,%eax
mov    %eax,-0x28(%rbp)
jmp    117f <print_hex+0x5f>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1208 <print_hex+0xe8>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    11d3 <print_hex+0xb3>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe42(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
jmp    11f5 <print_hex+0xd5>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
jmp    11fa <print_hex+0xda>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118c <print_hex+0x6c>
jmp    120d <print_hex+0xed>
cmpl   $0x10,-0x1c(%rbp)
jge    1265 <print_hex+0x145>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1241 <print_hex+0x121>
mov    -0x4(%rbp),%edi
lea    0xddf(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
jmp    1252 <print_hex+0x132>
mov    -0x4(%rbp),%edi
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
jmp    1257 <print_hex+0x137>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120d <print_hex+0xed>
mov    -0x4(%rbp),%edi
lea    0xda7(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12f1 <print_hex+0x1d1>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
movzbl -0x21(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     12bb <print_hex+0x19b>
movzbl -0x21(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    12c8 <print_hex+0x1a8>
mov    $0x2e,%eax
mov    %eax,-0x2c(%rbp)
jmp    12c8 <print_hex+0x1a8>
mov    -0x2c(%rbp),%eax
mov    %al,-0x21(%rbp)
mov    -0x4(%rbp),%edi
movzbl -0x21(%rbp),%edx
lea    0xd3c(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    127d <print_hex+0x15d>
mov    -0x4(%rbp),%edi
lea    0xd20(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
mov    -0x18(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x18(%rbp)
jmp    1139 <print_hex+0x19>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edx,%edx
jle    1296 <print_hex+0x176>
mov    %edx,%r15d
mov    %rsi,%r12
mov    %edi,%ebp
xor    %ebx,%ebx
mov    %edx,0x8(%rsp)
jmp    117b <print_hex+0x5b>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
lea    0xec2(%rip),%rsi
xor    %eax,%eax
call   1030 <printerr@plt>
mov    0x10(%rsp),%rbx
add    $0x10,%rbx
add    $0x10,%r12
mov    0x8(%rsp),%r15d
cmp    %r15d,%ebx
jge    1296 <print_hex+0x176>
mov    %ebp,%edi
lea    0xe7c(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printerr@plt>
mov    %rbx,0x10(%rsp)
sub    %ebx,%r15d
cmp    $0x10,%r15d
mov    $0x10,%eax
cmovl  %r15d,%eax
movslq %eax,%r13
mov    $0x0,%r14d
mov    %r15d,0xc(%rsp)
test   %r15d,%r15d
lea    0xe55(%rip),%rbx
jle    11f8 <print_hex+0xd8>
xor    %r14d,%r14d
lea    0xe43(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
test   $0x1,%r14b
movzbl (%r12,%r14,1),%edx
mov    %r15,%rsi
cmove  %rbx,%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <printerr@plt>
add    $0x1,%r14
cmp    %r13,%r14
jl     11d0 <print_hex+0xb0>
cmp    $0xf,%r14d
ja     122e <print_hex+0x10e>
lea    0xe16(%rip),%r15
lea    0xe0e(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
test   $0x1,%r14b
mov    %rbx,%rsi
cmove  %r15,%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <printerr@plt>
add    $0x1,%r14d
cmp    $0x10,%r14d
jne    1210 <print_hex+0xf0>
mov    %ebp,%edi
lea    0xddf(%rip),%rsi
xor    %eax,%eax
call   1030 <printerr@plt>
cmpl   $0x0,0xc(%rsp)
lea    0xdce(%rip),%r14
jle    1150 <print_hex+0x30>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r12,%rbx,1),%r15d
mov    %r15d,%edi
call   1040 <isprint@plt>
test   %rax,%rax
mov    $0x2e,%eax
cmove  %eax,%r15d
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15d,%edx
xor    %eax,%eax
call   1030 <printerr@plt>
add    $0x1,%rbx
cmp    %r13,%rbx
jl     1260 <print_hex+0x140>
jmp    1150 <print_hex+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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