#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_hexl(int pri, unsigned char *cp, int length) {
  int i, j, jm;
  unsigned char c;
  printerr(pri, "length %d\n", length);
  printerr(pri, "\n");
  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_hexl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x14(%rbp),%edx
lea    0xec1(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
mov    -0x4(%rbp),%edi
lea    0xeb9(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1335 <print_hexl+0x215>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%edx
lea    0xe94(%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    119e <print_hexl+0x7e>
mov    $0x10,%eax
mov    %eax,-0x28(%rbp)
jmp    11a4 <print_hexl+0x84>
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    122d <print_hexl+0x10d>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    11f8 <print_hexl+0xd8>
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    0xe28(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
jmp    121a <print_hexl+0xfa>
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    0xe07(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
jmp    121f <print_hexl+0xff>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b1 <print_hexl+0x91>
jmp    1232 <print_hexl+0x112>
cmpl   $0x10,-0x1c(%rbp)
jge    128a <print_hexl+0x16a>
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    1266 <print_hexl+0x146>
mov    -0x4(%rbp),%edi
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
jmp    1277 <print_hexl+0x157>
mov    -0x4(%rbp),%edi
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
jmp    127c <print_hexl+0x15c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1232 <print_hexl+0x112>
mov    -0x4(%rbp),%edi
lea    0xd8d(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1316 <print_hexl+0x1f6>
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     12e0 <print_hexl+0x1c0>
movzbl -0x21(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    12ed <print_hexl+0x1cd>
mov    $0x2e,%eax
mov    %eax,-0x2c(%rbp)
jmp    12ed <print_hexl+0x1cd>
mov    -0x2c(%rbp),%eax
mov    %al,-0x21(%rbp)
mov    -0x4(%rbp),%edi
movzbl -0x21(%rbp),%edx
lea    0xd22(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12a2 <print_hexl+0x182>
mov    -0x4(%rbp),%edi
lea    0xce9(%rip),%rsi
mov    $0x0,%al
call   1030 <printerr@plt>
mov    -0x18(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x18(%rbp)
jmp    115e <print_hexl+0x3e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hexl>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r15d
mov    %rsi,%r12
mov    %edi,%ebp
lea    0xec3(%rip),%rsi
xor    %eax,%eax
call   1030 <printerr@plt>
lea    0xebe(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <printerr@plt>
test   %r15d,%r15d
jle    12b6 <print_hexl+0x196>
xor    %ebx,%ebx
mov    %r15d,0x8(%rsp)
jmp    119b <print_hexl+0x7b>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
lea    0xe90(%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    12b6 <print_hexl+0x196>
mov    %ebp,%edi
lea    0xe67(%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    0xe40(%rip),%rbx
jle    1218 <print_hexl+0xf8>
xor    %r14d,%r14d
lea    0xe2e(%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     11f0 <print_hexl+0xd0>
cmp    $0xf,%r14d
ja     124e <print_hexl+0x12e>
lea    0xe01(%rip),%r15
lea    0xdf9(%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    1230 <print_hexl+0x110>
mov    %ebp,%edi
lea    0xdca(%rip),%rsi
xor    %eax,%eax
call   1030 <printerr@plt>
cmpl   $0x0,0xc(%rsp)
lea    0xdb9(%rip),%r14
jle    1170 <print_hexl+0x50>
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     1280 <print_hexl+0x160>
jmp    1170 <print_hexl+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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