#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*/ printf(char *, ...);
void dumpbuf(unsigned char *pbuf, int sz) {
  unsigned char line[17];
  unsigned char a;
  int i, j;
  line[0] = 0;
  line[16] = 0;
  j = 0;
  for (i = 0; i < sz; i++) {
    if (i % 16 == 0) {
      j = 0;
      printf("%s\n  %04d: ", line, i);
    }
    a = pbuf[i];
    if (a < 0x20 || a > 0x7f)
      a = '.';
    line[j++] = a;
    printf("%02x ", pbuf[i]);
  }
  line[j] = 0;
  printf("%s\n", line);
  return;
}


x86 assembly (clang, -O0):
<dumpbuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movb   $0x0,-0x20(%rbp)
movb   $0x0,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d9 <dumpbuf+0xc9>
mov    -0x28(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1171 <dumpbuf+0x61>
movl   $0x0,-0x2c(%rbp)
lea    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%edx
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
movzbl -0x21(%rbp),%eax
cmp    $0x20,%eax
jl     1199 <dumpbuf+0x89>
movzbl -0x21(%rbp),%eax
cmp    $0x7f,%eax
jle    119d <dumpbuf+0x8d>
movb   $0x2e,-0x21(%rbp)
mov    -0x21(%rbp),%cl
mov    -0x2c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
cltq
mov    %cl,-0x20(%rbp,%rax,1)
mov    -0x8(%rbp),%rax
movslq -0x28(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1135 <dumpbuf+0x25>
movslq -0x2c(%rbp),%rax
movb   $0x0,-0x20(%rbp,%rax,1)
lea    -0x20(%rbp),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumpbuf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movb   $0x0,(%rsp)
movb   $0x0,0x10(%rsp)
xor    %eax,%eax
test   %esi,%esi
jle    11ad <dumpbuf+0x8d>
mov    %rdi,%r13
mov    %esi,%ebp
mov    $0x2e,%r14d
lea    0xebd(%rip),%r12
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    118d <dumpbuf+0x6d>
cs nopw 0x0(%rax,%rax,1)
movzbl 0x0(%r13,%rbx,1),%esi
cmp    $0x20,%sil
mov    %esi,%eax
cmovl  %r14d,%eax
movslq %r15d,%rcx
add    $0x1,%r15d
mov    %al,(%rsp,%rcx,1)
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
je     11aa <dumpbuf+0x8a>
test   $0xf,%bl
jne    1160 <dumpbuf+0x40>
xor    %r15d,%r15d
lea    0xe64(%rip),%rdi
mov    %rsp,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <dumpbuf+0x40>
movslq %r15d,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1030 <puts@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"%s\0A %04d: \00"
@.str.1 = [6 x i8] c"%02x \00"
define void @dumpbuf(i8* nocapture %0, i32 %1) {
%3 = alloca [17 x i8]
%4 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 0
store i8 0, i8* %4
%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 %32
7: ; preds = %2
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %17
%10 = phi i64 [ 0, %7 ], [ %28, %17 ]
%11 = phi i32 [ 0, %7 ], [ %23, %17 ]
%12 = trunc i64 %10 to i32
%13 = and i32 %12, 15
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %4, i32 %12)
br label %17
17: ; preds = %15, %9
%18 = phi i32 [ 0, %15 ], [ %11, %9 ]
%19 = getelementptr inbounds i8, i8* %0, i64 %10
%20 = load i8, i8* %19
%21 = icmp slt i8 %20, 32
%22 = select i1 %21, i8 46, i8 %20
%23 = add nsw i32 %18, 1
%24 = sext i32 %18 to i64
%25 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %24
store i8 %22, i8* %25
%26 = zext i8 %20 to i32
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = add nuw nsw i64 %10, 1
%29 = icmp eq i64 %28, %8
br i1 %29, label %30, label %9
30: ; preds = %17
%31 = sext i32 %23 to i64
br label %32
32: ; preds = %30, %2
%33 = phi i64 [ 0, %2 ], [ %31, %30 ]
%34 = getelementptr inbounds [17 x i8], [17 x i8]* %3, i64 0, i64 %33
store i8 0, i8* %34
%35 = call i32 @puts(i8* %4)
ret void
}