#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*/ printf(char *, ...);
void lnp_hexdump(char *prefix, void *data, unsigned length) {
  unsigned offset;
  unsigned char *dataptr = (unsigned char *)data;
  unsigned linesize, lineindex;
  for (offset = 0; offset < length; offset += 16) {
    linesize = (length - offset < 16) ? (length - offset) : 16;
    if (prefix)
      printf("%s ", prefix);
    printf("%04d ", offset);
    for (lineindex = 0; lineindex < 16; lineindex++) {
      if (lineindex < linesize)
        printf(" %d", *(dataptr++));
      else if (1)
        printf("   ");
      if ((lineindex % 8) == (8 - 1))
        printf(" ");
    }
    if (1) {
      printf(" ");
      dataptr -= linesize;
      for (lineindex = 0; lineindex < 16; lineindex++) {
        if (lineindex < linesize)
          printf("%c", (isprint(*dataptr)) ? (*dataptr) : '.');
        dataptr++;
      }
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<lnp_hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    12e7 <lnp_hexdump+0x1c7>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
cmp    $0x10,%eax
jae    116b <lnp_hexdump+0x4b>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1178 <lnp_hexdump+0x58>
mov    $0x10,%eax
mov    %eax,-0x2c(%rbp)
jmp    1178 <lnp_hexdump+0x58>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     119b <lnp_hexdump+0x7b>
mov    -0x8(%rbp),%rsi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x28(%rbp)
cmpl   $0x10,-0x28(%rbp)
jae    122c <lnp_hexdump+0x10c>
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    11ee <lnp_hexdump+0xce>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movzbl (%rax),%esi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fc <lnp_hexdump+0xdc>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
and    $0x7,%eax
cmp    $0x7,%eax
jne    1219 <lnp_hexdump+0xf9>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121e <lnp_hexdump+0xfe>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11b3 <lnp_hexdump+0x93>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,%ecx
mov    %ecx,%edx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x10,-0x28(%rbp)
jae    12cb <lnp_hexdump+0x1ab>
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jae    12b1 <lnp_hexdump+0x191>
mov    -0x20(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     1293 <lnp_hexdump+0x173>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
mov    %eax,-0x30(%rbp)
jmp    12a0 <lnp_hexdump+0x180>
mov    $0x2e,%eax
mov    %eax,-0x30(%rbp)
jmp    12a0 <lnp_hexdump+0x180>
mov    -0x30(%rbp),%esi
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1258 <lnp_hexdump+0x138>
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x18(%rbp)
jmp    1142 <lnp_hexdump+0x22>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lnp_hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edx,%edx
je     1290 <lnp_hexdump+0x160>
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %edx,%r12d
xor    %r15d,%r15d
mov    %edx,0xc(%rsp)
mov    %rdi,0x10(%rsp)
jmp    1188 <lnp_hexdump+0x58>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%r15d
add    $0xfffffff0,%r12d
add    %rbp,%rbx
mov    0xc(%rsp),%r14d
cmp    %r14d,%r15d
mov    0x10(%rsp),%rbp
jae    1290 <lnp_hexdump+0x160>
cmp    $0x10,%r12d
mov    $0x10,%r13d
cmovb  %r12d,%r13d
sub    %r15d,%r14d
cmp    $0x10,%r14d
mov    $0x10,%eax
cmovae %eax,%r14d
test   %rbp,%rbp
je     11bc <lnp_hexdump+0x8c>
lea    0xe4e(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
neg    %r13
xor    %ebp,%ebp
lea    0xe3c(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e8 <lnp_hexdump+0xb8>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebp
cmp    $0x10,%ebp
je     1240 <lnp_hexdump+0x110>
cmp    %r14d,%ebp
jae    1210 <lnp_hexdump+0xe0>
movzbl (%rbx),%esi
add    $0x1,%rbx
lea    0xe0f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    121e <lnp_hexdump+0xee>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xdf7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
not    %eax
test   $0x7,%al
jne    11e0 <lnp_hexdump+0xb0>
mov    $0x20,%edi
call   1030 <putchar@plt>
jmp    11e0 <lnp_hexdump+0xb0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    %r13,%rbx
xor    %ebp,%ebp
jmp    1276 <lnp_hexdump+0x146>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    $0x10,%ebp
je     1160 <lnp_hexdump+0x30>
cmp    %r14d,%ebp
jae    1269 <lnp_hexdump+0x139>
movzbl (%rbx,%rbp,1),%edi
call   1050 <isprint@plt>
test   %rax,%rax
jne    1260 <lnp_hexdump+0x130>
mov    $0x2e,%edi
jmp    1264 <lnp_hexdump+0x134>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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