#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 */
scalar_t__ printf(char *, ...);
void print_data(const void *data, size_t size, unsigned cols) {
  size_t i;
  unsigned pos = 0;
  for (i = 0; i < size; ++i) {
    pos += printf(" %02x", ((unsigned)*(const char *)(data + i)) & 0xffu);
    if (pos >= cols - 3) {
      printf("\n");
      pos = 0;
    }
  }
}


x86 assembly (clang, -O0):
<print_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11a8 <print_data+0x98>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
and    $0xff,%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %rax,%rcx
mov    -0x24(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x3,%ecx
cmp    %ecx,%eax
jb     1192 <print_data+0x82>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
jmp    1197 <print_data+0x87>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1132 <print_data+0x22>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     1180 <print_data+0x60>
mov    %edx,%r13d
mov    %rsi,%r14
mov    %rdi,%r15
add    $0xfffffffd,%r13d
lea    0xebc(%rip),%r12
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    1159 <print_data+0x39>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     1180 <print_data+0x60>
movzbl (%r15,%rbx,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%ebp
add    %rax,%rbp
cmp    %ebp,%r13d
ja     1150 <print_data+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
jmp    1150 <print_data+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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