#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*/ fprintf(int /*<<< orphan*/, char *, unsigned char const,
                           char *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ stdout;
void print_buf(const unsigned char *buf, size_t buf_len, const char *footer) {
  size_t i = 0;
  for (i = 0; i < buf_len; ++i)
    fprintf(stdout, "%02X%s", buf[i], (i + 1) % 16 == 0 ? " " : " ");
  printf("%s\n", footer);
}


x86 assembly (clang, -O0):
<print_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a1 <print_buf+0x81>
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x20(%rbp),%rdx
add    $0x1,%rdx
and    $0xf,%rdx
lea    0xe8e(%rip),%rcx
cmp    $0x0,%rdx
cmove  %rcx,%rcx
lea    0xe78(%rip),%rsi
movzbl %al,%edx
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1144 <print_buf+0x24>
mov    -0x18(%rbp),%rsi
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_buf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
test   %rsi,%rsi
je     117c <print_buf+0x5c>
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %ebp,%ebp
mov    0x2e9d(%rip),%r14
lea    0xeb6(%rip),%r12
lea    0xeb6(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14),%edi
movzbl (%r15,%rbp,1),%edx
add    $0x1,%rbp
mov    %r12,%rsi
mov    %r13,%rcx
call   1040 <fprintf@plt>
cmp    %rbp,%rbx
jne    1160 <print_buf+0x40>
lea    0xe86(%rip),%rdi
mov    (%rsp),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [7 x i8] c"%02X%s\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @print_buf(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
store i64 0, i64* %7
store i64 0, i64* %7
br label %8
8: ; preds = %25, %3
%9 = load i64, i64* %7
%10 = load i64, i64* %5
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %28
12: ; preds = %8
%13 = load i32, i32* @stdout
%14 = load i8*, i8** %4
%15 = load i64, i64* %7
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = load i8, i8* %16
%18 = load i64, i64* %7
%19 = add i64 %18, 1
%20 = urem i64 %19, 16
%21 = icmp eq i64 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%24 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %17, i8* %23)
br label %25
25: ; preds = %12
%26 = load i64, i64* %7
%27 = add i64 %26, 1
store i64 %27, i64* %7
br label %8
28: ; preds = %8
%29 = load i8*, i8** %6
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %29)
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [7 x i8] c"%02X%s\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @print_buf(i8* nocapture %0, i64 %1, i8* %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %13, label %5
5: ; preds = %3, %5
%6 = phi i64 [ %10, %5 ], [ 0, %3 ]
%7 = load i32, i32* @stdout
%8 = getelementptr inbounds i8, i8* %0, i64 %6
%9 = load i8, i8* %8
%10 = add nuw i64 %6, 1
%11 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %10, %1
br i1 %12, label %13, label %5
13: ; preds = %5, %3
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
ret void
}