#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 shexdump(unsigned char *data, int data_len) {
  int i;
  if (!data || (data_len <= 0)) {
    printf("shexdump: invalid parameters\n");
    return;
  }
  printf("Hexdump from %p:\n", data);
  for (i = 0; i < data_len; i++) {
    if ((i % 16) == 0) {
      printf("\n0x%04x: ", i);
    }
    printf("%02x ", data[i]);
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<shexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1134 <shexdump+0x24>
cmpl   $0x0,-0xc(%rbp)
jg     1147 <shexdump+0x37>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c7 <shexdump+0xb7>
mov    -0x8(%rbp),%rsi
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b9 <shexdump+0xa9>
mov    -0x10(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1191 <shexdump+0x81>
mov    -0x10(%rbp),%esi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1160 <shexdump+0x50>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<shexdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xef0(%rip),%r14
test   %rdi,%rdi
je     119c <shexdump+0x7c>
mov    %esi,%ebx
test   %esi,%esi
jle    119c <shexdump+0x7c>
mov    %rdi,%r13
lea    0xeb9(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%ebp
lea    0xeb8(%rip),%r15
lea    0xebb(%rip),%r12
lea    0xea8(%rip),%r14
xor    %ebx,%ebx
jmp    1189 <shexdump+0x69>
nopl   0x0(%rax)
movzbl 0x0(%r13,%rbx,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
je     119c <shexdump+0x7c>
test   $0xf,%bl
jne    1170 <shexdump+0x50>
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1170 <shexdump+0x50>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"shexdump: invalid parameters\0A\00"
@.str.1 = [18 x i8] c"Hexdump from %p:\0A\00"
@.str.2 = [10 x i8] c"\0A0x%04x: \00"
@.str.3 = [6 x i8] c"%02x \00"
@.str.4 = [3 x i8] c"\0A\0A\00"
define void @shexdump(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8, %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %40
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32 0, i32* %5
br label %16
16: ; preds = %35, %13
%17 = load i32, i32* %5
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %38
20: ; preds = %16
%21 = load i32, i32* %5
%22 = srem i32 %21, 16
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* %5
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %24, %20
%28 = load i8*, i8** %3
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %27
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %16
38: ; preds = %16
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %38, %11
ret void
}

LLVM IR (-O2):
@.str.1 = [18 x i8] c"Hexdump from %p:\0A\00"
@.str.2 = [10 x i8] c"\0A0x%04x: \00"
@.str.3 = [6 x i8] c"%02x \00"
@str = [2 x i8] c"\0A\00"
@str.5 = [29 x i8] c"shexdump: invalid parameters\00"
define void @shexdump(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
%4 = icmp slt i32 %1, 1
%5 = or i1 %3, %4
br i1 %5, label %23, label %6
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %6, %16
%10 = phi i64 [ 0, %6 ], [ %21, %16 ]
%11 = trunc i64 %10 to i32
%12 = and i32 %11, 15
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %16
16: ; preds = %14, %9
%17 = getelementptr inbounds i8, i8* %0, i64 %10
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = add nuw nsw i64 %10, 1
%22 = icmp eq i64 %21, %8
br i1 %22, label %23, label %9
23: ; preds = %16, %2
%24 = phi i8* [ getelementptr inbounds ([29 x i8], [29 x i8]* @str.5, i64 0, i64 0), %2 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0), %16 ]
%25 = tail call i32 @puts(i8* dereferenceable(1) %24)
ret void
}