#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 print_buffer(void *buf, unsigned size) {
  short step = 1;
  unsigned char *i = (unsigned char *)buf;
  unsigned char *end = (unsigned char *)buf + size;
  while (i < end) {
    printf("%x ", *i);
    if (step % 10 == 0)
      printf("\n");
    ++step;
    ++i;
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movw   $0x1,-0xe(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    119e <print_buffer+0x8e>
mov    -0x18(%rbp),%rax
movzbl (%rax),%esi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movswl -0xe(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1181 <print_buffer+0x71>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xe(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0xe(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    113b <print_buffer+0x2b>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_buffer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
je     118d <print_buffer+0x6d>
mov    %rdi,%rbx
mov    %esi,%r15d
add    %rdi,%r15
mov    $0x1,%bp
lea    0xec1(%rip),%r14
jmp    115c <print_buffer+0x3c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
add    $0x1,%rbx
cmp    %r15,%rbx
jae    118d <print_buffer+0x6d>
movzbl (%rbx),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
imul   $0xffffcccd,%ebp,%eax
add    $0x1998,%eax
ror    %ax
movzwl %ax,%eax
cmp    $0x1998,%eax
ja     1150 <print_buffer+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1150 <print_buffer+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [4 x i8] c"%x \00"
define void @print_buffer(i8* %0, i32 %1) {
%3 = zext i32 %1 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = icmp eq i32 %1, 0
br i1 %5, label %20, label %6
6: ; preds = %2, %16
%7 = phi i16 [ %17, %16 ], [ 1, %2 ]
%8 = phi i8* [ %18, %16 ], [ %0, %2 ]
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = srem i16 %7, 10
%13 = icmp eq i16 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = tail call i32 @putchar(i32 10)
br label %16
16: ; preds = %14, %6
%17 = add i16 %7, 1
%18 = getelementptr inbounds i8, i8* %8, i64 1
%19 = icmp ult i8* %18, %4
br i1 %19, label %6, label %20
20: ; preds = %16, %2
%21 = tail call i32 @putchar(i32 10)
ret void
}