#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*/ log_write(char *, ...);
void dump_memory(const unsigned char *data, size_t size) {
  if (!data || !size) {
    return;
  }
  log_write("0x");
  for (size_t i = 0; i < size; ++i) {
    log_write("%02X", data[i]);
  }
  log_write("");
}


x86 assembly (clang, -O0):
<dump_memory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1136 <dump_memory+0x26>
cmpq   $0x0,-0x10(%rbp)
jne    113b <dump_memory+0x2b>
jmp    1198 <dump_memory+0x88>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <log_write@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    118a <dump_memory+0x7a>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <log_write@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1151 <dump_memory+0x41>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <log_write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_memory>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     1171 <dump_memory+0x61>
mov    %rsi,%r14
test   %rsi,%rsi
je     1171 <dump_memory+0x61>
mov    %rdi,%r12
lea    0xed1(%rip),%rdi
xor    %eax,%eax
call   1030 <log_write@plt>
lea    0xec6(%rip),%r15
xor    %ebx,%ebx
nop
movzbl (%r12,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1030 <log_write@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <dump_memory+0x30>
lea    0xea8(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <log_write@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
@.str.1 = [5 x i8] c"%02X\00"
@.str.2 = [1 x i8] zeroinitializer
define void @dump_memory(i8* %0, i64 %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i64 %1, 0
%5 = and i1 %3, %4
br i1 %5, label %6, label %18
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %10
8: ; preds = %10
%9 = tail call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %18
10: ; preds = %6, %10
%11 = phi i64 [ %16, %10 ], [ 0, %6 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = tail call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = add nuw i64 %11, 1
%17 = icmp eq i64 %16, %1
br i1 %17, label %8, label %10
18: ; preds = %2, %8
ret void
}