#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 pp_buf(FILE *fp, char *buf, size_t bufsize, size_t width, size_t group) {
  int i = 0;
  for (i = 0; i < bufsize; ++i) {
    fprintf(fp, "%02x", (unsigned char)*(buf + i));
    if ((i + 1) % group == 0 && i + 1 < bufsize)
      fprintf(fp, " ");
    if ((i + 1) % width == 0 && i + 1 < bufsize)
      fprintf(fp, "\n");
  }
  fprintf(fp, "\n");
}


x86 assembly (clang, -O0):
<pp_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11f5 <pp_buf+0xe5>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xea1(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x28(%rbp)
cmp    $0x0,%rdx
jne    11a4 <pp_buf+0x94>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
cmp    -0x18(%rbp),%rax
jae    11a4 <pp_buf+0x94>
mov    -0x8(%rbp),%rdi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
cmp    $0x0,%rdx
jne    11e2 <pp_buf+0xd2>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
cltq
cmp    -0x18(%rbp),%rax
jae    11e2 <pp_buf+0xd2>
mov    -0x8(%rbp),%rdi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11e7 <pp_buf+0xd7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    113a <pp_buf+0x2a>
mov    -0x8(%rbp),%rdi
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pp_buf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,(%rsp)
mov    %rdi,%r12
test   %rdx,%rdx
je     121b <pp_buf+0xfb>
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rdx,%r13
neg    %r13
mov    $0x1,%ebp
jmp    1179 <pp_buf+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(,%rbp,1),%rax
add    %r13,%rax
add    $0x1,%rbp
cmp    $0x1,%rax
je     121b <pp_buf+0xfb>
mov    (%rsp),%rax
movzbl -0x1(%rax,%rbp,1),%edx
mov    %r12,%rdi
lea    0xe74(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbp,%rax
or     %r14,%rax
shr    $0x20,%rax
je     11b0 <pp_buf+0x90>
mov    %rbp,%rax
xor    %edx,%edx
div    %r14
cmp    %rbx,%rbp
jb     11bc <pp_buf+0x9c>
jmp    11ce <pp_buf+0xae>
xchg   %ax,%ax
mov    %ebp,%eax
xor    %edx,%edx
div    %r14d
cmp    %rbx,%rbp
jae    11ce <pp_buf+0xae>
test   %rdx,%rdx
jne    11ce <pp_buf+0xae>
mov    $0x20,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
mov    %rbp,%rax
or     %r15,%rax
shr    $0x20,%rax
je     11f0 <pp_buf+0xd0>
mov    %rbp,%rax
xor    %edx,%edx
div    %r15
cmp    %rbx,%rbp
jb     1200 <pp_buf+0xe0>
jmp    1160 <pp_buf+0x40>
nopl   0x0(%rax)
mov    %ebp,%eax
xor    %edx,%edx
div    %r15d
cmp    %rbx,%rbp
jae    1160 <pp_buf+0x40>
test   %rdx,%rdx
jne    1160 <pp_buf+0x40>
mov    $0xa,%edi
mov    %r12,%rsi
call   1030 <fputc@plt>
jmp    1160 <pp_buf+0x40>
mov    $0xa,%edi
mov    %r12,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define void @pp_buf(i32* nocapture %0, i8* nocapture %1, i64 %2, i64 %3, i64 %4) {
%6 = icmp eq i64 %2, 0
br i1 %6, label %28, label %7
7: ; preds = %5, %26
%8 = phi i64 [ %13, %26 ], [ 0, %5 ]
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = add nuw i64 %8, 1
%14 = urem i64 %13, %4
%15 = icmp eq i64 %14, 0
%16 = icmp ult i64 %13, %2
%17 = and i1 %16, %15
br i1 %17, label %18, label %20
18: ; preds = %7
%19 = tail call i32 @fputc(i32 32, i32* %0)
br label %20
20: ; preds = %18, %7
%21 = urem i64 %13, %3
%22 = icmp eq i64 %21, 0
%23 = and i1 %16, %22
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 @fputc(i32 10, i32* %0)
br label %26
26: ; preds = %20, %24
%27 = icmp eq i64 %13, %2
br i1 %27, label %28, label %7
28: ; preds = %26, %5
%29 = tail call i32 @fputc(i32 10, i32* %0)
ret void
}