#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_data(unsigned char *buf, unsigned int size) {
  int i;
  for (i = 0; i < size; i++) {
    if ((i % 8 == 0) && i) {
      printf(" ");
    }
    if ((i % 16 == 0) && i) {
      printf("\n");
    }
    printf("%02X ", *buf++);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<print_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11b8 <print_data+0xa8>
mov    -0x10(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    115e <print_data+0x4e>
cmpl   $0x0,-0x10(%rbp)
je     115e <print_data+0x4e>
lea    0xeaf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    118a <print_data+0x7a>
cmpl   $0x0,-0x10(%rbp)
je     118a <print_data+0x7a>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movzbl (%rax),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <print_data+0x16>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_data>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1184 <print_data+0x64>
mov    %rdi,%r15
mov    %esi,%r12d
lea    0xec7(%rip),%r14
xor    %ebx,%ebx
jmp    1158 <print_data+0x38>
nopl   (%rax)
movzbl (%r15,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %ebx,%r12d
je     1184 <print_data+0x64>
test   %ebx,%ebx
je     116d <print_data+0x4d>
mov    %ebx,%eax
and    $0x7,%eax
jne    116d <print_data+0x4d>
mov    $0x20,%edi
call   1030 <putchar@plt>
test   %ebx,%ebx
je     1140 <print_data+0x20>
mov    %ebx,%eax
and    $0xf,%eax
jne    1140 <print_data+0x20>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1140 <print_data+0x20>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [6 x i8] c"%02X \00"
define void @print_data(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %34, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp ult i32 %7, %8
br i1 %9, label %10, label %37
10: ; preds = %6
%11 = load i32, i32* %5
%12 = srem i32 %11, 8
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i32, i32* %5
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %14, %10
%20 = load i32, i32* %5
%21 = srem i32 %20, 16
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = load i32, i32* %5
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %23
%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, %23, %19
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %3
%31 = load i8, i8* %29
%32 = zext 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 = %28
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %6
37: ; preds = %6
%38 = 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.2 = [6 x i8] c"%02X \00"
define void @print_data(i8* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %26, label %4
4: ; preds = %2, %19
%5 = phi i32 [ %24, %19 ], [ 0, %2 ]
%6 = phi i8* [ %20, %19 ], [ %0, %2 ]
%7 = and i32 %5, 7
%8 = icmp eq i32 %7, 0
%9 = icmp ne i32 %5, 0
%10 = and i1 %9, %8
br i1 %10, label %11, label %13
11: ; preds = %4
%12 = tail call i32 @putchar(i32 32)
br label %13
13: ; preds = %11, %4
%14 = and i32 %5, 15
%15 = icmp eq i32 %14, 0
%16 = and i1 %9, %15
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @putchar(i32 10)
br label %19
19: ; preds = %17, %13
%20 = getelementptr inbounds i8, i8* %6, i64 1
%21 = load i8, i8* %6
%22 = zext i8 %21 to i32
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = add nuw i32 %5, 1
%25 = icmp eq i32 %24, %1
br i1 %25, label %26, label %4
26: ; preds = %19, %2
%27 = tail call i32 @putchar(i32 10)
ret void
}