#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
void mrvl_hex_dump(char *pref, int width, uint8_t *buf, int len) {
  register int i, n;
  for (i = 0, n = 1; i < len; i++, n++) {
    if (n == 1) {
      printf("%s", pref);
    }
    printf("%2.2X ", buf[i]);
    if (n == width) {
      printf("\n");
      n = 0;
    }
  }
  if (i && n != 1) {
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<mrvl_hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b2 <mrvl_hex_dump+0xa2>
cmpl   $0x1,-0x24(%rbp)
jne    115c <mrvl_hex_dump+0x4c>
mov    -0x8(%rbp),%rsi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1196 <mrvl_hex_dump+0x86>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
jmp    119b <mrvl_hex_dump+0x8b>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1134 <mrvl_hex_dump+0x24>
cmpl   $0x0,-0x20(%rbp)
je     11d4 <mrvl_hex_dump+0xc4>
cmpl   $0x1,-0x24(%rbp)
je     11d4 <mrvl_hex_dump+0xc4>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mrvl_hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,(%rsp)
test   %ecx,%ecx
jle    11c2 <mrvl_hex_dump+0xa2>
mov    %rdx,%r13
mov    %esi,%ebp
mov    %ecx,%ebx
mov    $0x1,%eax
lea    0xeb9(%rip),%r12
xor    %r15d,%r15d
jmp    115d <mrvl_hex_dump+0x3d>
nop
add    $0x1,%r15
lea    0x1(%r14),%eax
cmp    %rbx,%r15
je     11a5 <mrvl_hex_dump+0x85>
mov    %eax,%r14d
cmp    $0x1,%eax
jne    1177 <mrvl_hex_dump+0x57>
lea    0xe94(%rip),%rdi
mov    (%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13,%r15,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %ebp,%r14d
jne    1150 <mrvl_hex_dump+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r15
mov    $0x1,%eax
cmp    %rbx,%r15
jne    115d <mrvl_hex_dump+0x3d>
jmp    11c2 <mrvl_hex_dump+0xa2>
test   %r14d,%r14d
je     11c2 <mrvl_hex_dump+0xa2>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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