#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 *, ...);
int hexdump_helper(void *ptr, int len, int format_offset) {
  int i, newlined = 0, format_val;
  char *data = (char *)ptr;
  for (i = 0, format_val = format_offset; i < len; i++, format_val++) {
    printf("%02X ", (unsigned char)data[i]);
    newlined = 0;
    if (format_val > 0) {
      int mod = format_val % (16);
      if (mod == 0) {
        printf("\n");
        newlined = 1;
      } else if (mod == (16) / 2) {
        printf("- ");
      }
    }
  }
  return format_val;
}


x86 assembly (clang, -O0):
<hexdump_helper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e5 <hexdump_helper+0xd5>
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11c9 <hexdump_helper+0xb9>
mov    -0x1c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11a7 <hexdump_helper+0x97>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x18(%rbp)
jmp    11c4 <hexdump_helper+0xb4>
cmpl   $0x8,-0x2c(%rbp)
jne    11bf <hexdump_helper+0xaf>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c4 <hexdump_helper+0xb4>
jmp    11c9 <hexdump_helper+0xb9>
jmp    11ce <hexdump_helper+0xbe>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113e <hexdump_helper+0x2e>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump_helper>:
mov    %edx,%eax
test   %esi,%esi
jle    11b0 <hexdump_helper+0x90>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbp
mov    %esi,(%rsp)
mov    %esi,%ebx
mov    %eax,0x4(%rsp)
mov    %eax,%r12d
lea    0xeb5(%rip),%r13
xor    %r14d,%r14d
jmp    1167 <hexdump_helper+0x47>
lea    0xeaf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r14
cmp    %r14,%rbx
je     119b <hexdump_helper+0x7b>
lea    (%r12,%r14,1),%r15
movzbl 0x0(%rbp,%r14,1),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r15d,%r15d
jle    115e <hexdump_helper+0x3e>
and    $0xf,%r15d
cmp    $0x8,%r15d
je     1150 <hexdump_helper+0x30>
test   %r15d,%r15d
jne    115e <hexdump_helper+0x3e>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    115e <hexdump_helper+0x3e>
mov    0x4(%rsp),%eax
add    (%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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