#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 *, char);
int /*<<< orphan*/ puts(char *);
void dump_buffer(char *buf, size_t len) {
  int i;
  for (i = 0; i < len; i++) {
    if ((i % 16) == 0) {
      printf("%04x:", i);
    }
    printf(" %02x", buf[i]);
    if ((i % 16) == 15) {
      puts("");
    }
  }
  if ((i % 16) != 0) {
    puts("");
  }
}


x86 assembly (clang, -O0):
<dump_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11b6 <dump_buffer+0x96>
mov    -0x14(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    116b <dump_buffer+0x4b>
mov    -0x14(%rbp),%eax
lea    0xe9d(%rip),%rdi
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
lea    0xe8c(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0xf,%edx
jne    11a3 <dump_buffer+0x83>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
jmp    11a8 <dump_buffer+0x88>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <dump_buffer+0x17>
mov    -0x14(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11d6 <dump_buffer+0xb6>
lea    0xe34(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_buffer>:
test   %rsi,%rsi
je     11b5 <dump_buffer+0x95>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0xebd(%rip),%r15
lea    0xebc(%rip),%r12
jmp    1171 <dump_buffer+0x51>
nopl   0x0(%rax)
movsbl %bl,%esi
mov    %r15,%rdi
call   1040 <printf@plt>
movsbl (%r14,%rbx,1),%esi
mov    %r12,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
je     1196 <dump_buffer+0x76>
mov    %ebx,%ebp
and    $0xf,%ebp
je     1150 <dump_buffer+0x30>
movsbl (%r14,%rbx,1),%esi
mov    %r12,%rdi
call   1040 <printf@plt>
cmp    $0xf,%ebp
jne    1168 <dump_buffer+0x48>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1168 <dump_buffer+0x48>
test   $0xf,%r13b
lea    0x8(%rsp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
je     11b5 <dump_buffer+0x95>
mov    $0xa,%edi
jmp    1030 <putchar@plt>
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%04x:\00"
@.str.1 = [6 x i8] c" %02x\00"
@.str.2 = [1 x i8] zeroinitializer
define void @dump_buffer(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
store i32 0, i32* %5
br label %6
6: ; preds = %32, %2
%7 = load i32, i32* %5
%8 = sext i32 %7 to i64
%9 = load i64, i64* %4
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %35
11: ; preds = %6
%12 = load i32, i32* %5
%13 = srem i32 %12, 16
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32, i32* %5
%17 = trunc i32 %16 to i8
%18 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 signext %17)
br label %19
19: ; preds = %15, %11
%20 = load i8*, i8** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8 signext %24)
%26 = load i32, i32* %5
%27 = srem i32 %26, 16
%28 = icmp eq i32 %27, 15
br i1 %28, label %29, label %31
29: ; preds = %19
%30 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %19
br label %32
32: ; preds = %31
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %6
35: ; preds = %6
%36 = load i32, i32* %5
%37 = srem i32 %36, 16
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %39, %35
ret void
}

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