#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 dump_buffer(char *buff, int count) {
  int i, j, c;
  int printnext = 1;
  if (count % 16)
    c = count + (16 - count % 16);
  else
    c = count;
  for (i = 0; i < c; i++) {
    if (printnext) {
      printnext--;
      printf("%.4x ", i & 0xffff);
    }
    if (i < count)
      printf("%3.2x", buff[i] & 0xff);
    else
      printf("   ");
    if (!((i + 1) % 8)) {
      if ((i + 1) % 16)
        printf(" -");
      else {
        printf("   ");
        for (j = i - 15; j <= i; j++)
          if (j < count) {
            if ((buff[j] & 0xff) >= 0x20 && (buff[j] & 0xff) <= 0x7e)
              printf("%c", buff[j] & 0xff);
            else
              printf(".");
          } else
            printf(" ");
        printf("\n");
        printnext = 1;
      }
    }
  }
}


x86 assembly (clang, -O0):
<dump_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     115f <dump_buffer+0x4f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    -0x20(%rbp),%eax
mov    $0x10,%ecx
sub    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    1165 <dump_buffer+0x55>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    130b <dump_buffer+0x1fb>
cmpl   $0x0,-0x1c(%rbp)
je     11a2 <dump_buffer+0x92>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%esi
and    $0xffff,%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d3 <dump_buffer+0xc3>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e1 <dump_buffer+0xd1>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12f8 <dump_buffer+0x1e8>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1222 <dump_buffer+0x112>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12f3 <dump_buffer+0x1e3>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
sub    $0xf,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     12de <dump_buffer+0x1ce>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12bd <dump_buffer+0x1ad>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
cmp    $0x20,%eax
jl     12aa <dump_buffer+0x19a>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
cmp    $0x7e,%eax
jg     12aa <dump_buffer+0x19a>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12b8 <dump_buffer+0x1a8>
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12cb <dump_buffer+0x1bb>
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12d0 <dump_buffer+0x1c0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1239 <dump_buffer+0x129>
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x1c(%rbp)
jmp    12f8 <dump_buffer+0x1e8>
jmp    12fd <dump_buffer+0x1ed>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116c <dump_buffer+0x5c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,0x8(%rsp)
lea    0xf(%rsi),%eax
test   %esi,%esi
cmovns %esi,%eax
and    $0xfffffff0,%eax
mov    %esi,%ecx
sub    %eax,%ecx
mov    $0x10,%eax
sub    %ecx,%eax
test   %ecx,%ecx
cmove  %ecx,%eax
add    %esi,%eax
test   %eax,%eax
jle    1275 <dump_buffer+0x155>
movslq %esi,%r15
mov    %eax,%ebx
mov    $0x1,%r12d
mov    $0xfffffffffffffff1,%r14
lea    0xe95(%rip),%rbp
xor    %r13d,%r13d
mov    %rbx,0x10(%rsp)
jmp    11ad <dump_buffer+0x8d>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x1,%r12d
mov    0x10(%rsp),%rbx
lea    0xe6f(%rip),%rbp
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    %rbx,%r13
je     1275 <dump_buffer+0x155>
test   %r12d,%r12d
je     11c4 <dump_buffer+0xa4>
movzwl %r13w,%esi
lea    0xe43(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %r15,%r13
jge    11e0 <dump_buffer+0xc0>
mov    0x8(%rsp),%rax
movzbl (%rax,%r13,1),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11ee <dump_buffer+0xce>
nop
lea    0xe25(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r13
xor    %r12d,%r12d
test   $0x7,%r13b
jne    11a0 <dump_buffer+0x80>
test   $0xf,%r13b
je     1214 <dump_buffer+0xf4>
xor    %r12d,%r12d
lea    0xe05(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a0 <dump_buffer+0x80>
lea    0xdf1(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x10,%ebx
mov    %r14,%rbp
mov    0x8(%rsp),%r12
jmp    1253 <dump_buffer+0x133>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1030 <putchar@plt>
add    $0x1,%rbp
add    $0xffffffffffffffff,%rbx
je     117b <dump_buffer+0x5b>
mov    $0x20,%edi
cmp    %r15,%rbp
jge    1240 <dump_buffer+0x120>
movzbl (%r12,%rbp,1),%eax
lea    -0x20(%rax),%ecx
cmp    $0x5f,%cl
mov    $0x2e,%ecx
cmovae %ecx,%eax
movzbl %al,%edi
jmp    1240 <dump_buffer+0x120>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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