#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void log_dump(unsigned char *buf, int start_index, int end_index) {
  int dump_index = start_index;
  int dump_num = 0;
  int i = 0;
  do {
    if ((end_index + 1) <= dump_index + 16) {
      dump_num = end_index - dump_index + 1;
    } else {
      dump_num = 16;
    }
    for (i = 0; i < dump_num; i++) {
      fprintf(stderr, "%02x", buf[dump_index + i]);
    }
    fprintf(stderr, "\n");
    dump_index += 16;
  } while (dump_index <= end_index);
}


x86 assembly (clang, -O0):
<log_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    -0x14(%rbp),%ecx
add    $0x10,%ecx
cmp    %ecx,%eax
jg     115b <log_dump+0x4b>
mov    -0x10(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1162 <log_dump+0x52>
movl   $0x10,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11ab <log_dump+0x9b>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1169 <log_dump+0x59>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    1136 <log_dump+0x26>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movslq %esi,%r13
movslq %edx,%rcx
add    $0x1,%edx
mov    %edx,0xc(%rsp)
add    %r13,%rbx
mov    0x2ea8(%rip),%r15
lea    0xec1(%rip),%rbp
mov    %rcx,0x10(%rsp)
jmp    116f <log_dump+0x5f>
cs nopw 0x0(%rax,%rax,1)
mov    (%r15),%edi
lea    0xeab(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x10,%rbx
mov    0x10(%rsp),%rcx
cmp    %rcx,%r13
jg     11ad <log_dump+0x9d>
mov    0xc(%rsp),%eax
sub    %r13d,%eax
add    $0x10,%r13
cmp    %rcx,%r13
mov    $0x10,%ecx
cmovle %ecx,%eax
test   %eax,%eax
jle    1150 <log_dump+0x40>
mov    %eax,%r14d
xor    %r12d,%r12d
nop
mov    (%r15),%edi
movzbl (%rbx,%r12,1),%edx
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%r14
jne    1190 <log_dump+0x80>
jmp    1150 <log_dump+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [5 x i8] c"%02x\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @log_dump(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %5
store i32 %10, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
br label %11
11: ; preds = %47, %3
%12 = load i32, i32* %6
%13 = add nsw i32 %12, 1
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 16
%16 = icmp sle i32 %13, %15
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = sub nsw i32 %18, %19
%21 = add nsw i32 %20, 1
store i32 %21, i32* %8
br label %23
22: ; preds = %11
store i32 16, i32* %8
br label %23
23: ; preds = %22, %17
store i32 0, i32* %9
br label %24
24: ; preds = %39, %23
%25 = load i32, i32* %9
%26 = load i32, i32* %8
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %42
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %4
%31 = load i32, i32* %7
%32 = load i32, i32* %9
%33 = add nsw i32 %31, %32
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %30, i64 %34
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %28
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %24
42: ; preds = %24
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 16
store i32 %46, i32* %7
br label %47
47: ; preds = %42
%48 = load i32, i32* %7
%49 = load i32, i32* %6
%50 = icmp sle i32 %48, %49
br i1 %50, label %11, label %51
51: ; preds = %47
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [5 x i8] c"%02x\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @log_dump(i8* nocapture %0, i32 %1, i32 %2) {
%4 = add i32 %2, 1
%5 = sext i32 %1 to i64
%6 = sext i32 %2 to i64
br label %7
7: ; preds = %27, %3
%8 = phi i64 [ %9, %27 ], [ %5, %3 ]
%9 = add i64 %8, 16
%10 = icmp sgt i64 %9, %6
%11 = trunc i64 %8 to i32
%12 = sub i32 %4, %11
%13 = select i1 %10, i32 %12, i32 16
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %27
15: ; preds = %7
%16 = zext i32 %13 to i64
br label %17
17: ; preds = %15, %17
%18 = phi i64 [ 0, %15 ], [ %25, %17 ]
%19 = load i32, i32* @stderr
%20 = add nsw i64 %18, %8
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = add nuw nsw i64 %18, 1
%26 = icmp eq i64 %25, %16
br i1 %26, label %27, label %17
27: ; preds = %17, %7
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br i1 %10, label %30, label %7
30: ; preds = %27
ret void
}