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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void print_chunk(FILE *out, const char *label, const unsigned char *buf,
                 int size, int cols) {
  int i, j, m;
  int pos = 0;
  if (label)
    fprintf(out, "%s:\n", label);
  for (i = 0; i < size / cols; ++i) {
    fprintf(out, ".db ");
    for (j = 0; j < cols - 1; ++j)
      fprintf(out, "$%.2X,", buf[pos++]);
    fprintf(out, "$%.2X\n", buf[pos++]);
  }
  m = size % cols;
  if (m > 0) {
    fprintf(out, ".db ");
    for (j = 0; j < m - 1; ++j)
      fprintf(out, "$%.2X,", buf[pos++]);
    fprintf(out, "$%.2X\n", buf[pos++]);
  }
}


x86 assembly (clang, -O0):
<print_chunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1153 <print_chunk+0x43>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeb4(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    120a <print_chunk+0xfa>
mov    -0x8(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d4 <print_chunk+0xc4>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x30(%rbp)
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe4b(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    118d <print_chunk+0x7d>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x30(%rbp)
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe1c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115a <print_chunk+0x4a>
mov    -0x1c(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    %edx,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    12a6 <print_chunk+0x196>
mov    -0x8(%rbp),%rdi
lea    0xddc(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    127e <print_chunk+0x16e>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x30(%rbp)
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xda1(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1237 <print_chunk+0x127>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x30(%rbp)
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_chunk>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8d,%ebp
mov    %ecx,%r14d
mov    %rdx,%r13
mov    %rdi,%rbx
test   %rsi,%rsi
je     1153 <print_chunk+0x33>
mov    %rsi,%rdx
lea    0xeb7(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %r14d,%eax
cltd
idiv   %ebp
mov    %eax,0x14(%rsp)
test   %eax,%eax
mov    %edx,0x10(%rsp)
jle    121d <print_chunk+0xfd>
mov    %rbp,0x20(%rsp)
lea    -0x1(%rbp),%r14d
lea    0xe91(%rip),%r15
xor    %ebp,%ebp
xor    %r12d,%r12d
mov    %r13,0x18(%rsp)
jmp    11b8 <print_chunk+0x98>
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ebp,%rax
add    $0x1,%ebp
movzbl 0x0(%r13,%rax,1),%edx
mov    %rbx,%rdi
lea    0xe6b(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%r12d
cmp    0x14(%rsp),%r12d
je     121f <print_chunk+0xff>
mov    $0x4,%esi
mov    $0x1,%edx
lea    0xe3c(%rip),%rdi
mov    %rbx,%rcx
call   1040 <fwrite@plt>
cmpl   $0x2,0x20(%rsp)
jl     1190 <print_chunk+0x70>
mov    %ebp,0xc(%rsp)
movslq %ebp,%rbp
add    %r13,%rbp
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x0(%rbp,%r13,1),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%r13
cmp    %r13d,%r14d
jne    11f0 <print_chunk+0xd0>
mov    0xc(%rsp),%ebp
add    %r13d,%ebp
mov    0x18(%rsp),%r13
jmp    1190 <print_chunk+0x70>
xor    %ebp,%ebp
mov    0x10(%rsp),%r14d
test   %r14d,%r14d
jle    12bb <print_chunk+0x19b>
lea    0xdd1(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
cmp    $0x1,%r14d
je     1293 <print_chunk+0x173>
add    $0xffffffff,%r14d
mov    %ebp,0xc(%rsp)
movslq %ebp,%r12
add    %r13,%r12
mov    %r14d,%r15d
lea    0xda6(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movzbl (%r12,%rbp,1),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%rbp
cmp    %ebp,%r15d
jne    1270 <print_chunk+0x150>
mov    0xc(%rsp),%eax
add    %ebp,%eax
mov    %eax,%ebp
movslq %ebp,%rax
movzbl 0x0(%r13,%rax,1),%edx
lea    0xd6e(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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