#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void dup_mem(void *ptr, size_t size) {
  int i;
  for (i = 0; i < (int)size; i++) {
    printf("%02x ", ((uint8_t *)ptr)[i]);
    if ((i + 1) % 10 == 0)
      printf("\n");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dup_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    %ecx,%eax
jge    1187 <dup_mem+0x77>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1174 <dup_mem+0x64>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1179 <dup_mem+0x69>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1127 <dup_mem+0x17>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dup_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1198 <dup_mem+0x78>
mov    %rdi,%r15
mov    %esi,%r12d
shl    $0x2,%r12
mov    $0xffffffff,%ebp
mov    $0x1,%ebx
xor    %r13d,%r13d
jmp    115f <dup_mem+0x3f>
nopl   0x0(%rax,%rax,1)
add    $0x4,%r13
add    $0xffffffff,%ebp
add    $0x1,%ebx
cmp    %r13,%r12
je     1198 <dup_mem+0x78>
mov    %ebx,%eax
mov    $0xcccccccd,%ecx
imul   %rcx,%rax
shr    $0x23,%rax
lea    (%rax,%rax,4),%r14d
add    %r14d,%r14d
mov    (%r15,%r13,1),%esi
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    %ebp,%r14d
jne    1150 <dup_mem+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1150 <dup_mem+0x30>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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