#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 hex_dump(char *pref, int width, unsigned char *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):
<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    11b3 <hex_dump+0xa3>
cmpl   $0x1,-0x24(%rbp)
jne    115c <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
movzbl (%rax,%rcx,1),%esi
lea    0xe94(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1197 <hex_dump+0x87>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
jmp    119c <hex_dump+0x8c>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1134 <hex_dump+0x24>
cmpl   $0x0,-0x20(%rbp)
je     11d5 <hex_dump+0xc5>
cmpl   $0x1,-0x24(%rbp)
je     11d5 <hex_dump+0xc5>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,(%rsp)
test   %ecx,%ecx
jle    11c3 <hex_dump+0xa3>
mov    %rdx,%r13
mov    %esi,%ebp
mov    %ecx,%ebx
mov    $0x1,%eax
lea    0xeb9(%rip),%r12
xor    %r15d,%r15d
jmp    115d <hex_dump+0x3d>
nop
add    $0x1,%r15
lea    0x1(%r14),%eax
cmp    %rbx,%r15
je     11a6 <hex_dump+0x86>
mov    %eax,%r14d
cmp    $0x1,%eax
jne    1177 <hex_dump+0x57>
lea    0xe94(%rip),%rdi
mov    (%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl 0x0(%r13,%r15,1),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    %ebp,%r14d
jne    1150 <hex_dump+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r15
mov    $0x1,%eax
cmp    %rbx,%r15
jne    115d <hex_dump+0x3d>
jmp    11c3 <hex_dump+0xa3>
test   %r14d,%r14d
je     11c3 <hex_dump+0xa3>
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 @hex_dump(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i32 1, i32* %10
br label %11
11: ; preds = %35, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %8
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %40
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 i8*, i8** %7
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %10
%30 = load i32, i32* %6
%31 = icmp eq i32 %29, %30
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = 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 %34
34: ; preds = %32, %21
br label %35
35: ; preds = %34
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
%38 = load i32, i32* %10
%39 = add nsw i32 %38, 1
store i32 %39, i32* %10
br label %11
40: ; preds = %11
%41 = load i32, i32* %9
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = load i32, i32* %10
%45 = icmp ne i32 %44, 1
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %46, %43, %40
ret void
}

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