#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 *, ...);
void display_buf(char *buf, int len) {
  long i;
  printf("%016lx: ", (size_t)buf);
  for (i = 0; i < len; i++) {
    if (i && i % 16 == 0)
      printf("\n%08lx: ", (size_t)(buf + i));
    printf("%02x ", *(buf + i));
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<display_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xed6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmp    %rcx,%rax
jge    11ae <display_buf+0x9e>
cmpq   $0x0,-0x18(%rbp)
je     1183 <display_buf+0x73>
mov    -0x18(%rbp),%rax
mov    $0x10,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1183 <display_buf+0x73>
mov    -0x8(%rbp),%rsi
add    -0x18(%rbp),%rsi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1139 <display_buf+0x29>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_buf>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xecc(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    1196 <display_buf+0x76>
movslq %ebp,%r12
lea    0xebd(%rip),%r14
lea    0xebf(%rip),%r15
xor    %ebp,%ebp
jmp    1177 <display_buf+0x57>
nopw   0x0(%rax,%rax,1)
movsbl (%rbx,%rbp,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
je     1196 <display_buf+0x76>
test   %rbp,%rbp
je     1160 <display_buf+0x40>
mov    %ebp,%eax
and    $0xf,%eax
test   %rax,%rax
jne    1160 <display_buf+0x40>
lea    (%rbx,%rbp,1),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <display_buf+0x40>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [9 x i8] c"%016lx: \00"
@.str.1 = [9 x i8] c"\0A%08lx: \00"
@.str.2 = [6 x i8] c"%02x \00"
define void @display_buf(i8* %0, i32 %1) {
%3 = ptrtoint i8* %0 to i64
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %3)
%5 = sext i32 %1 to i64
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %24
7: ; preds = %2, %17
%8 = phi i64 [ %22, %17 ], [ 0, %2 ]
%9 = icmp ne i64 %8, 0
%10 = and i64 %8, 15
%11 = icmp eq i64 %10, 0
%12 = and i1 %9, %11
br i1 %12, label %13, label %17
13: ; preds = %7
%14 = getelementptr inbounds i8, i8* %0, i64 %8
%15 = ptrtoint i8* %14 to i64
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i64 %15)
br label %17
17: ; preds = %13, %7
%18 = getelementptr inbounds i8, i8* %0, i64 %8
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = add nuw nsw i64 %8, 1
%23 = icmp eq i64 %22, %5
br i1 %23, label %24, label %7
24: ; preds = %17, %2
%25 = tail call i32 @putchar(i32 10)
ret void
}