#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_mem(void *start, int size, int row_size) {
  int i;
  for (i = 0; i < size; i++) {
    printf("%02x", ((unsigned char *)start)[i]);
    if ((i + 1) % row_size == 0 && i > 0)
      printf("\n");
    else
      printf(" ");
  }
}


x86 assembly (clang, -O0):
<print_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a0 <print_mem+0x90>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltd
idivl  -0x10(%rbp)
cmp    $0x0,%edx
jne    117f <print_mem+0x6f>
cmpl   $0x0,-0x14(%rbp)
jle    117f <print_mem+0x6f>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    118d <print_mem+0x7d>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1192 <print_mem+0x82>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <print_mem+0x19>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1191 <print_mem+0x71>
mov    %edx,%r15d
mov    %rdi,%r12
mov    %esi,%r13d
lea    0xec1(%rip),%r14
xor    %ebp,%ebp
jmp    1163 <print_mem+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %rbp,%rbp
cmovne %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rbp
cmp    %rbx,%r13
je     1191 <print_mem+0x71>
movzbl (%r12,%rbp,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x1(%rbp),%rbx
mov    %ebx,%eax
cltd
idiv   %r15d
mov    $0xa,%eax
mov    $0x20,%edi
test   %edx,%edx
je     1150 <print_mem+0x30>
mov    $0x20,%eax
jmp    1150 <print_mem+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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