#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 */
char hexdig(unsigned char);
scalar_t__ isprint(char);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sprintf(char *, char *, long);
void hexdumpbuf(unsigned char *buf, long buflen) {
  char LINE[80];
  long offset = 0L;
  long left = buflen;
  int i, upto16, x;
  unsigned char b;
  while (left > 0) {
    for (i = 0; i < 78; i++)
      LINE[i] = ' ';
    LINE[9] = LINE[59] = '|';
    LINE[77] = '\0';
    LINE[78] = '\0';
    sprintf(LINE, "%08lX", offset);
    LINE[8] = ' ';
    upto16 = (left > 16) ? 16 : (int)left;
    for (x = 0; x < upto16; x++) {
      b = buf[offset + x];
      LINE[11 + (3 * x)] = hexdig((b & 0xf0) >> 4);
      LINE[12 + (3 * x)] = hexdig(b & 0x0f);
      LINE[61 + x] = isprint((char)b) ? ((char)b) : '.';
    }
    puts(LINE);
    offset += 16L;
    left -= 16L;
  }
}


x86 assembly (clang, -O0):
<hexdumpbuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jle    12cf <hexdumpbuf+0x18f>
movl   $0x0,-0x74(%rbp)
cmpl   $0x4e,-0x74(%rbp)
jge    1196 <hexdumpbuf+0x56>
movslq -0x74(%rbp),%rax
movb   $0x20,-0x60(%rbp,%rax,1)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1175 <hexdumpbuf+0x35>
movb   $0x7c,-0x25(%rbp)
movb   $0x7c,-0x57(%rbp)
movb   $0x0,-0x13(%rbp)
movb   $0x0,-0x12(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%rdx
lea    0xe4b(%rip),%rsi
call   1060 <sprintf@plt>
movb   $0x20,-0x58(%rbp)
cmpq   $0x10,-0x70(%rbp)
jle    11d9 <hexdumpbuf+0x99>
mov    $0x10,%eax
mov    %eax,-0x84(%rbp)
jmp    11e3 <hexdumpbuf+0xa3>
mov    -0x70(%rbp),%rax
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
cmp    -0x78(%rbp),%eax
jge    12a9 <hexdumpbuf+0x169>
mov    -0x8(%rbp),%rax
mov    -0x68(%rbp),%rcx
movslq -0x7c(%rbp),%rdx
add    %rdx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x7d(%rbp)
movzbl -0x7d(%rbp),%eax
and    $0xf0,%eax
sar    $0x4,%eax
movzbl %al,%edi
call   1040 <hexdig@plt>
mov    %al,%cl
imul   $0x3,-0x7c(%rbp),%eax
add    $0xb,%eax
cltq
mov    %cl,-0x60(%rbp,%rax,1)
movzbl -0x7d(%rbp),%eax
and    $0xf,%eax
movzbl %al,%edi
call   1040 <hexdig@plt>
mov    %al,%cl
imul   $0x3,-0x7c(%rbp),%eax
add    $0xc,%eax
cltq
mov    %cl,-0x60(%rbp,%rax,1)
movsbl -0x7d(%rbp),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     1277 <hexdumpbuf+0x137>
movsbl -0x7d(%rbp),%eax
mov    %eax,-0x88(%rbp)
jmp    1287 <hexdumpbuf+0x147>
mov    $0x2e,%eax
mov    %eax,-0x88(%rbp)
jmp    1287 <hexdumpbuf+0x147>
mov    -0x88(%rbp),%eax
mov    %al,%cl
mov    -0x7c(%rbp),%eax
add    $0x3d,%eax
cltq
mov    %cl,-0x60(%rbp,%rax,1)
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    11f3 <hexdumpbuf+0xb3>
lea    -0x60(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x68(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x68(%rbp)
mov    -0x70(%rbp),%rax
sub    $0x10,%rax
mov    %rax,-0x70(%rbp)
jmp    1163 <hexdumpbuf+0x23>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdumpbuf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
test   %rsi,%rsi
jle    1254 <hexdumpbuf+0x114>
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edx,%edx
lea    0x20(%rsp),%r15
mov    $0x2e,%r12d
mov    %rsi,%rbp
nopl   (%rax)
movaps 0xe89(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x20(%rsp)
movups %xmm0,0x5e(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movb   $0x7c,0x5b(%rsp)
movb   $0x7c,0x29(%rsp)
movb   $0x0,0x6d(%rsp)
movb   $0x0,0x6e(%rsp)
mov    %r15,%rdi
lea    0xe62(%rip),%rsi
mov    %rdx,0x10(%rsp)
call   1060 <sprintf@plt>
movb   $0x20,0x28(%rsp)
sub    $0x10,%rbp
mov    %rbp,0x8(%rsp)
mov    $0x10,%r13d
mov    %r14,0x18(%rsp)
cmovb  %r14,%r13
mov    $0xc,%r14d
xor    %r15d,%r15d
xchg   %ax,%ax
movsbl (%rbx,%r15,1),%ebp
mov    %ebp,%eax
shr    $0x4,%al
movzbl %al,%edi
call   1040 <hexdig@plt>
mov    %al,0x1f(%rsp,%r14,1)
mov    %ebp,%edi
and    $0xf,%edi
call   1040 <hexdig@plt>
mov    %al,0x20(%rsp,%r14,1)
mov    %ebp,%edi
call   1050 <isprint@plt>
test   %rax,%rax
cmove  %r12d,%ebp
mov    %bpl,0x5d(%rsp,%r15,1)
add    $0x1,%r15
add    $0x3,%r14
cmp    %r13,%r15
jl     11e0 <hexdumpbuf+0xa0>
lea    0x20(%rsp),%r15
mov    %r15,%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%rdx
add    $0x10,%rdx
add    $0x10,%rbx
cmpq   $0x10,0x18(%rsp)
mov    0x8(%rsp),%rbp
mov    %rbp,%r14
jg     1170 <hexdumpbuf+0x30>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%08lX\00"
define void @hexdumpbuf(i8* nocapture %0, i64 %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%6 = icmp sgt i64 %1, 0
br i1 %6, label %7, label %48
7: ; preds = %2
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 59
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 9
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 77
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 78
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 8
br label %13
13: ; preds = %7, %43
%14 = phi i64 [ 0, %7 ], [ %45, %43 ]
%15 = phi i64 [ %1, %7 ], [ %46, %43 ]
store i8 124, i8* %8
store i8 124, i8* %9
store i8 0, i8* %10
store i8 0, i8* %11
%16 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %14)
store i8 32, i8* %12
%17 = icmp ult i64 %15, 16
%18 = select i1 %17, i64 %15, i64 16
br label %19
19: ; preds = %13, %19
%20 = phi i64 [ 0, %13 ], [ %41, %19 ]
%21 = add nuw nsw i64 %14, %20
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = lshr i8 %23, 4
%25 = tail call signext i8 @hexdig(i8 zeroext %24)
%26 = trunc i64 %20 to i32
%27 = mul nsw i32 %26, 3
%28 = add nuw nsw i32 %27, 11
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %29
store i8 %25, i8* %30
%31 = and i8 %23, 15
%32 = tail call signext i8 @hexdig(i8 zeroext %31)
%33 = add nuw nsw i32 %27, 12
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %34
store i8 %32, i8* %35
%36 = tail call i64 @isprint(i8 signext %23)
%37 = icmp eq i64 %36, 0
%38 = select i1 %37, i8 46, i8 %23
%39 = add nuw nsw i64 %20, 61
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %39
store i8 %38, i8* %40
%41 = add nuw nsw i64 %20, 1
%42 = icmp slt i64 %41, %18
br i1 %42, label %19, label %43
43: ; preds = %19
%44 = call i32 @puts(i8* %5)
%45 = add nuw nsw i64 %14, 16
%46 = add nsw i64 %15, -16
%47 = icmp sgt i64 %15, 16
br i1 %47, label %13, label %48
48: ; preds = %43, %2
ret void
}