#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(char *buf, int start_index, int end_index) {
  int dump_index = start_index;
  int dump_num = 0;
  int i = 0;
  fprintf(stderr, "end_index=%d\n", end_index);
  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    0x2ea3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
lea    0xeb7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    -0x14(%rbp),%ecx
add    $0x10,%ecx
cmp    %ecx,%eax
jg     1175 <log_dump+0x65>
mov    -0x10(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117c <log_dump+0x6c>
movl   $0x10,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11c5 <log_dump+0xb5>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    -0x1c(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1183 <log_dump+0x73>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%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    1150 <log_dump+0x40>
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    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2eb3(%rip),%r12
mov    (%r12),%edi
lea    0xec8(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
movslq %r14d,%r15
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %ebp,0xc(%rsp)
add    %r15,%rbx
lea    0xeb8(%rip),%rbp
mov    %rcx,0x10(%rsp)
jmp    1180 <log_dump+0x70>
nopl   (%rax)
mov    (%r12),%edi
lea    0xea1(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x10,%rbx
mov    0x10(%rsp),%rcx
cmp    %rcx,%r15
jg     11be <log_dump+0xae>
mov    0xc(%rsp),%eax
sub    %r15d,%eax
add    $0x10,%r15
cmp    %rcx,%r15
mov    $0x10,%ecx
cmovle %ecx,%eax
test   %eax,%eax
jle    1160 <log_dump+0x50>
mov    %eax,%r14d
xor    %r13d,%r13d
mov    (%r12),%edi
movsbl (%rbx,%r13,1),%edx
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%r14
jne    11a0 <log_dump+0x90>
jmp    1160 <log_dump+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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