#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 *, ...);
void hexdump_data(char *prompt, void *p, int len, char delim) {
  int i;
  unsigned char *s = p;
  if (prompt) {
    printf("%s: len=%d\n", prompt, (int)len);
  }
  for (i = 0; i < len; i++) {
    if (i != len - 1)
      printf("%02x%c", *s++, delim);
    else
      printf("%02x\n", *s);
    if ((i + 1) % 16 == 0)
      printf("\n");
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<hexdump_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1150 <hexdump_data+0x40>
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ea <hexdump_data+0xda>
mov    -0x1c(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     119d <hexdump_data+0x8d>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movzbl (%rax),%esi
movsbl -0x15(%rbp),%edx
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b2 <hexdump_data+0xa2>
mov    -0x28(%rbp),%rax
movzbl (%rax),%esi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11d7 <hexdump_data+0xc7>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11dc <hexdump_data+0xcc>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1157 <hexdump_data+0x47>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %edx,%r14d
mov    %rsi,%rbx
test   %rdi,%rdi
je     114c <hexdump_data+0x2c>
mov    %rdi,%rsi
lea    0xebe(%rip),%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14d,%r14d
jle    11cf <hexdump_data+0xaf>
movsbl %bpl,%r13d
neg    %r14d
mov    $0x1,%ebp
lea    0xeaf(%rip),%r15
lea    0xea1(%rip),%r12
jmp    1183 <hexdump_data+0x63>
nopl   (%rax)
lea    (%r14,%rbp,1),%eax
add    $0x1,%eax
mov    %ebp,%ecx
add    $0x1,%ecx
mov    %ecx,%ebp
cmp    $0x1,%eax
je     11cf <hexdump_data+0xaf>
mov    %r14d,%eax
add    %ebp,%eax
je     11b0 <hexdump_data+0x90>
movzbl (%rbx),%esi
add    $0x1,%rbx
mov    %r12,%rdi
mov    %r13d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
test   $0xf,%bpl
jne    1170 <hexdump_data+0x50>
jmp    11c3 <hexdump_data+0xa3>
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   $0xf,%bpl
jne    1170 <hexdump_data+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1170 <hexdump_data+0x50>
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 = [12 x i8] c"%s: len=%d\0A\00"
@.str.1 = [7 x i8] c"%02x%c\00"
@.str.2 = [6 x i8] c"%02x\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @hexdump_data(i8* %0, i8* %1, i32 %2, i8 signext %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8 %3, i8* %8
%11 = load i8*, i8** %6
store i8* %11, i8** %10
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = load i8*, i8** %5
%16 = load i32, i32* %7
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %16)
br label %18
18: ; preds = %14, %4
store i32 0, i32* %9
br label %19
19: ; preds = %49, %18
%20 = load i32, i32* %9
%21 = load i32, i32* %7
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %52
23: ; preds = %19
%24 = load i32, i32* %9
%25 = load i32, i32* %7
%26 = sub nsw i32 %25, 1
%27 = icmp ne i32 %24, %26
br i1 %27, label %28, label %36
28: ; preds = %23
%29 = load i8*, i8** %10
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %10
%31 = load i8, i8* %29
%32 = zext i8 %31 to i32
%33 = load i8, i8* %8
%34 = sext i8 %33 to i32
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %34)
br label %41
36: ; preds = %23
%37 = load i8*, i8** %10
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %36, %28
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
%44 = srem i32 %43, 16
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %41
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46, %41
br label %49
49: ; preds = %48
%50 = load i32, i32* %9
%51 = add nsw i32 %50, 1
store i32 %51, i32* %9
br label %19
52: ; preds = %19
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret void
}

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