#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ isprint(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ print_indent(int /*<<< orphan*/ *, int);
void output_buffer(FILE *stream, uint8_t *buffer, int length, int indent) {
  int i;
  if (length == 0) {
    fprintf(stream, "\n");
  }
  if (buffer == NULL) {
    return;
  }
  i = 0;
  while (i < length) {
    uint8_t array[16];
    int j;
    print_indent(stream, indent);
    memcpy(array, buffer + i, 16);
    for (j = 0; j < 16 && i + j < length; j++) {
      fprintf(stream, "%02X ", array[j]);
      if (j % 4 == 3) {
        fprintf(stream, " ");
      }
    }
    if (length > 16) {
      while (j < 16) {
        fprintf(stream, "   ");
        if (j % 4 == 3) {
          fprintf(stream, " ");
        }
        j++;
      }
    }
    fprintf(stream, " ");
    for (j = 0; j < 16 && i + j < length; j++) {
      if (isprint(array[j])) {
        fprintf(stream, "%c", array[j]);
      } else {
        fprintf(stream, ".");
      }
    }
    fprintf(stream, "\n");
    i += 16;
  }
}


x86 assembly (clang, -O0):
<output_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1172 <output_buffer+0x32>
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1182 <output_buffer+0x42>
jmp    136c <output_buffer+0x22c>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    136c <output_buffer+0x22c>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <print_indent@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
movl   $0x0,-0x64(%rbp)
xor    %eax,%eax
cmpl   $0x10,-0x64(%rbp)
mov    %al,-0x65(%rbp)
jge    11e3 <output_buffer+0xa3>
mov    -0x1c(%rbp),%eax
add    -0x64(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x65(%rbp)
mov    -0x65(%rbp),%al
test   $0x1,%al
jne    11f3 <output_buffer+0xb3>
jmp    1246 <output_buffer+0x106>
mov    -0x8(%rbp),%rdi
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edx
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x64(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x3,%edx
jne    1233 <output_buffer+0xf3>
mov    -0x8(%rbp),%rdi
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1238 <output_buffer+0xf8>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    11c5 <output_buffer+0x85>
cmpl   $0x10,-0x14(%rbp)
jle    12aa <output_buffer+0x16a>
jmp    1255 <output_buffer+0x115>
cmpl   $0x10,-0x64(%rbp)
jge    12a5 <output_buffer+0x165>
mov    -0x8(%rbp),%rdi
lea    0xd9e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x64(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x3,%edx
jne    1297 <output_buffer+0x157>
mov    -0x8(%rbp),%rdi
lea    0xd7a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1255 <output_buffer+0x115>
jmp    12aa <output_buffer+0x16a>
mov    -0x8(%rbp),%rdi
lea    0xd55(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x64(%rbp)
xor    %eax,%eax
cmpl   $0x10,-0x64(%rbp)
mov    %al,-0x66(%rbp)
jge    12e1 <output_buffer+0x1a1>
mov    -0x1c(%rbp),%eax
add    -0x64(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x66(%rbp)
mov    -0x66(%rbp),%al
test   $0x1,%al
jne    12f1 <output_buffer+0x1b1>
jmp    134c <output_buffer+0x20c>
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
je     1327 <output_buffer+0x1e7>
mov    -0x8(%rbp),%rdi
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%edx
lea    0xcf1(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1339 <output_buffer+0x1f9>
mov    -0x8(%rbp),%rdi
lea    0xcdd(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    133e <output_buffer+0x1fe>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    12c3 <output_buffer+0x183>
mov    -0x8(%rbp),%rdi
lea    0xca9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x1c(%rbp)
jmp    1189 <output_buffer+0x49>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %ecx,0xc(%rsp)
mov    %rdi,%rbx
test   %edx,%edx
je     1318 <output_buffer+0x1b8>
mov    %rsi,%r12
test   %rsi,%rsi
je     1309 <output_buffer+0x1a9>
mov    %edx,%ebp
test   %edx,%edx
jle    1309 <output_buffer+0x1a9>
movslq %ebp,%r14
mov    $0x1,%r15d
xor    %r13d,%r13d
mov    %ebp,0x8(%rsp)
mov    %r12,0x10(%rsp)
jmp    11d2 <output_buffer+0x72>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
add    $0x10,%r13
add    $0x10,%r15
mov    0x8(%rsp),%ebp
cmp    %ebp,%r13d
jge    1309 <output_buffer+0x1a9>
mov    %rbx,%rdi
mov    0xc(%rsp),%esi
call   1030 <print_indent@plt>
mov    %r13,0x18(%rsp)
lea    (%r12,%r13,4),%rsi
lea    0x20(%rsp),%rdi
mov    $0x10,%edx
call   1060 <memcpy@plt>
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    %r12,%r13
mov    0x20(%rsp,%r12,4),%edx
mov    %rbx,%rdi
lea    0xdee(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r13d,%eax
not    %eax
test   $0x3,%al
jne    122f <output_buffer+0xcf>
mov    $0x20,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
lea    0x1(%r13),%r12
cmp    $0xe,%r13
ja     1242 <output_buffer+0xe2>
lea    (%r15,%r13,1),%rax
cmp    %r14,%rax
jl     1200 <output_buffer+0xa0>
cmp    $0x11,%ebp
jb     12a0 <output_buffer+0x140>
cmp    $0xe,%r13
ja     12a0 <output_buffer+0x140>
cmp    $0x10,%r12d
mov    $0xf,%ebp
cmovae %r12d,%ebp
add    $0x1,%ebp
jmp    1269 <output_buffer+0x109>
nop
add    $0x1,%r12d
cmp    %r12d,%ebp
je     12a0 <output_buffer+0x140>
mov    $0x3,%esi
mov    $0x1,%edx
lea    0xd8c(%rip),%rdi
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %r12d,%eax
not    %eax
test   $0x3,%al
jne    1260 <output_buffer+0x100>
mov    $0x20,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
jmp    1260 <output_buffer+0x100>
nopw   0x0(%rax,%rax,1)
mov    $0x20,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
xor    %ebp,%ebp
mov    0x10(%rsp),%r12
mov    0x18(%rsp),%r13
nopl   0x0(%rax)
mov    0x20(%rsp,%rbp,4),%edi
call   1070 <isprint@plt>
test   %rax,%rax
je     12e0 <output_buffer+0x180>
mov    0x20(%rsp,%rbp,4),%edi
jmp    12e5 <output_buffer+0x185>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x2e,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
cmp    $0xe,%rbp
ja     11b0 <output_buffer+0x50>
lea    (%r15,%rbp,1),%rax
add    $0x1,%rbp
cmp    %r14,%rax
jl     12c0 <output_buffer+0x160>
jmp    11b0 <output_buffer+0x50>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xa,%edi
mov    %rbx,%rsi
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fputc@plt>

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

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%02X \00"
@.str.3 = [4 x i8] c" \00"
define void @output_buffer(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca [16 x i32]
%6 = icmp eq i32 %2, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @fputc(i32 10, i32* %0)
br label %77
9: ; preds = %4
%10 = icmp ne i32* %1, null
%11 = icmp sgt i32 %2, 0
%12 = and i1 %10, %11
br i1 %12, label %13, label %77
13: ; preds = %9
%14 = bitcast [16 x i32]* %5 to i8*
%15 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 0
%16 = icmp ugt i32 %2, 16
%17 = sext i32 %2 to i64
%18 = sext i32 %2 to i64
br label %19
19: ; preds = %72, %13
%20 = phi i64 [ 0, %13 ], [ %74, %72 ]
%21 = call i32 @print_indent(i32* %0, i32 %3)
%22 = getelementptr inbounds i32, i32* %1, i64 %20
%23 = call i32 @memcpy(i32* %15, i32* %22, i32 16)
br label %24
24: ; preds = %19, %33
%25 = phi i64 [ 0, %19 ], [ %34, %33 ]
%26 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = and i64 %25, 3
%30 = icmp eq i64 %29, 3
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 @fputc(i32 32, i32* %0)
br label %33
33: ; preds = %24, %31
%34 = add nuw nsw i64 %25, 1
%35 = icmp ult i64 %25, 15
%36 = add nuw nsw i64 %34, %20
%37 = icmp slt i64 %36, %17
%38 = select i1 %35, i1 %37, i1 false
br i1 %38, label %24, label %39
39: ; preds = %33
%40 = trunc i64 %34 to i32
%41 = select i1 %16, i1 %35, i1 false
br i1 %41, label %42, label %54
42: ; preds = %39
%43 = call i32 @llvm.umax.i32(i32 %40, i32 15)
br label %44
44: ; preds = %42, %51
%45 = phi i32 [ %52, %51 ], [ %40, %42 ]
%46 = call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 3, i64 1, i32* %0)
%47 = and i32 %45, 3
%48 = icmp eq i32 %47, 3
br i1 %48, label %49, label %51
49: ; preds = %44
%50 = call i32 @fputc(i32 32, i32* %0)
br label %51
51: ; preds = %49, %44
%52 = add nuw nsw i32 %45, 1
%53 = icmp eq i32 %45, %43
br i1 %53, label %54, label %44
54: ; preds = %51, %39
%55 = call i32 @fputc(i32 32, i32* %0)
br label %56
56: ; preds = %54, %64
%57 = phi i64 [ 0, %54 ], [ %67, %64 ]
%58 = getelementptr inbounds [16 x i32], [16 x i32]* %5, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = call i64 @isprint(i32 %59)
%61 = icmp eq i64 %60, 0
br i1 %61, label %64, label %62
62: ; preds = %56
%63 = load i32, i32* %58
br label %64
64: ; preds = %56, %62
%65 = phi i32 [ %63, %62 ], [ 46, %56 ]
%66 = call i32 @fputc(i32 %65, i32* %0)
%67 = add nuw nsw i64 %57, 1
%68 = icmp ult i64 %57, 15
%69 = add nuw nsw i64 %67, %20
%70 = icmp slt i64 %69, %18
%71 = select i1 %68, i1 %70, i1 false
br i1 %71, label %56, label %72
72: ; preds = %64
%73 = call i32 @fputc(i32 10, i32* %0)
%74 = add nuw i64 %20, 16
%75 = trunc i64 %74 to i32
%76 = icmp slt i32 %75, %2
br i1 %76, label %19, label %77
77: ; preds = %72, %7, %9
ret void
}