#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 /*<<< orphan*/ tmp;
typedef int /*<<< orphan*/ line;

/* Variables and functions */
int /*<<< orphan*/ logd(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char);
int /*<<< orphan*/ strlcpy(char *, char *, int);
int /*<<< orphan*/ strncat(char *, char *, int);
void hex_dump(char *prefix, int width, unsigned char *buf, int len) {
  char tmp[3 * 256 + 8] = "";
  char line[3 * 256 + 8] = "";
  if (width > 256)
    width = 256;
  int i, n;
  line[0] = 0;
  if (prefix)
    strlcpy(line, prefix, sizeof(line));
  for (i = 0, n = 1; i < len; i++, n++) {
    snprintf(tmp, sizeof(tmp), "%2.2x ", buf[i]);
    strncat(line, tmp, sizeof(line));
    if (n == width) {
      n = 0;
      logd(line);
      line[0] = 0;
      if (prefix)
        strlcpy(line, prefix, sizeof(line));
    } else if (i == len - 1 && n)
      logd(line);
  }
}


x86 assembly (clang, -O0):
<hex_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x650,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    -0x330(%rbp),%rdi
xor    %esi,%esi
mov    $0x308,%edx
call   1050 <memset@plt>
lea    -0x640(%rbp),%rdi
xor    %esi,%esi
mov    $0x308,%edx
call   1050 <memset@plt>
cmpl   $0x100,-0xc(%rbp)
jle    11a3 <hex_dump+0x53>
movl   $0x100,-0xc(%rbp)
movb   $0x0,-0x640(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ca <hex_dump+0x7a>
lea    -0x640(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x308,%edx
call   1070 <strlcpy@plt>
movl   $0x0,-0x644(%rbp)
movl   $0x1,-0x648(%rbp)
mov    -0x644(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12d7 <hex_dump+0x187>
lea    -0x330(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x644(%rbp),%rcx
mov    $0x308,%esi
lea    0xdf5(%rip),%rdx
movzbl (%rax,%rcx,1),%ecx
call   1040 <snprintf@plt>
lea    -0x640(%rbp),%rdi
lea    -0x330(%rbp),%rsi
mov    $0x308,%edx
call   1060 <strncat@plt>
mov    -0x648(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    127d <hex_dump+0x12d>
movl   $0x0,-0x648(%rbp)
lea    -0x640(%rbp),%rdi
call   1030 <logd@plt>
movb   $0x0,-0x640(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1278 <hex_dump+0x128>
lea    -0x640(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x308,%edx
call   1070 <strlcpy@plt>
jmp    12af <hex_dump+0x15f>
mov    -0x644(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    12aa <hex_dump+0x15a>
cmpl   $0x0,-0x648(%rbp)
je     12aa <hex_dump+0x15a>
lea    -0x640(%rbp),%rdi
call   1030 <logd@plt>
jmp    12af <hex_dump+0x15f>
jmp    12b4 <hex_dump+0x164>
mov    -0x644(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x644(%rbp)
mov    -0x648(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x648(%rbp)
jmp    11de <hex_dump+0x8e>
add    $0x650,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_dump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x638,%rsp
mov    %ecx,%r15d
mov    %rdx,0x18(%rsp)
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x330(%rsp),%rdi
mov    $0x308,%edx
xor    %esi,%esi
call   1050 <memset@plt>
cmp    $0x100,%ebx
mov    $0x100,%ebp
cmovl  %ebx,%ebp
lea    0x20(%rsp),%rdi
mov    $0x308,%edx
xor    %esi,%esi
call   1050 <memset@plt>
test   %r14,%r14
je     11b8 <hex_dump+0x68>
lea    0x20(%rsp),%rdi
mov    %r14,%rsi
mov    $0x308,%edx
call   1070 <strlcpy@plt>
mov    %r14,0x10(%rsp)
test   %r15d,%r15d
jle    1279 <hex_dump+0x129>
lea    -0x1(%r15),%eax
mov    %rax,0x8(%rsp)
mov    %r15d,%r15d
mov    $0x1,%r12d
xor    %r14d,%r14d
lea    0x330(%rsp),%r13
lea    0x20(%rsp),%rbx
jmp    11fd <hex_dump+0xad>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
add    $0x1,%r12d
cmp    %r14,%r15
je     1279 <hex_dump+0x129>
mov    0x18(%rsp),%rax
movzbl (%rax,%r14,1),%ecx
mov    %r13,%rdi
mov    $0x308,%esi
lea    0xdea(%rip),%rdx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x308,%edx
call   1060 <strncat@plt>
cmp    %ebp,%r12d
jne    1260 <hex_dump+0x110>
mov    %rbx,%rdi
call   1030 <logd@plt>
xor    %r12d,%r12d
movb   $0x0,0x20(%rsp)
mov    0x10(%rsp),%rsi
test   %rsi,%rsi
je     11f0 <hex_dump+0xa0>
mov    %rbx,%rdi
mov    $0x308,%edx
call   1070 <strlcpy@plt>
jmp    11f0 <hex_dump+0xa0>
nopl   0x0(%rax)
cmp    %r14,0x8(%rsp)
jne    11f0 <hex_dump+0xa0>
test   %r12d,%r12d
je     11f0 <hex_dump+0xa0>
mov    %rbx,%rdi
call   1030 <logd@plt>
jmp    11f0 <hex_dump+0xa0>
add    $0x638,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%2.2x \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 [776 x i8]
%10 = alloca [776 x i8]
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%13 = bitcast [776 x i8]* %9 to i8*
%14 = bitcast [776 x i8]* %10 to i8*
%15 = load i32, i32* %6
%16 = icmp sgt i32 %15, 256
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 256, i32* %6
br label %18
18: ; preds = %17, %4
%19 = getelementptr inbounds [776 x i8], [776 x i8]* %10, i64 0, i64 0
store i8 0, i8* %19
%20 = load i8*, i8** %5
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = getelementptr inbounds [776 x i8], [776 x i8]* %10, i64 0, i64 0
%24 = load i8*, i8** %5
%25 = call i32 @strlcpy(i8* %23, i8* %24, i32 776)
br label %26
26: ; preds = %22, %18
store i32 0, i32* %11
store i32 1, i32* %12
br label %27
27: ; preds = %69, %26
%28 = load i32, i32* %11
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %74
31: ; preds = %27
%32 = getelementptr inbounds [776 x i8], [776 x i8]* %9, i64 0, i64 0
%33 = load i8*, i8** %7
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = call i32 @snprintf(i8* %32, i32 776, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %37)
%39 = getelementptr inbounds [776 x i8], [776 x i8]* %10, i64 0, i64 0
%40 = getelementptr inbounds [776 x i8], [776 x i8]* %9, i64 0, i64 0
%41 = call i32 @strncat(i8* %39, i8* %40, i32 776)
%42 = load i32, i32* %12
%43 = load i32, i32* %6
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %56
45: ; preds = %31
store i32 0, i32* %12
%46 = getelementptr inbounds [776 x i8], [776 x i8]* %10, i64 0, i64 0
%47 = call i32 @logd(i8* %46)
%48 = getelementptr inbounds [776 x i8], [776 x i8]* %10, i64 0, i64 0
store i8 0, i8* %48
%49 = load i8*, i8** %5
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %55
51: ; preds = %45
%52 = getelementptr inbounds [776 x i8], [776 x i8]* %10, i64 0, i64 0
%53 = load i8*, i8** %5
%54 = call i32 @strlcpy(i8* %52, i8* %53, i32 776)
br label %55
55: ; preds = %51, %45
br label %68
56: ; preds = %31
%57 = load i32, i32* %11
%58 = load i32, i32* %8
%59 = sub nsw i32 %58, 1
%60 = icmp eq i32 %57, %59
br i1 %60, label %61, label %67
61: ; preds = %56
%62 = load i32, i32* %12
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = getelementptr inbounds [776 x i8], [776 x i8]* %10, i64 0, i64 0
%66 = call i32 @logd(i8* %65)
br label %67
67: ; preds = %64, %61, %56
br label %68
68: ; preds = %67, %55
br label %69
69: ; preds = %68
%70 = load i32, i32* %11
%71 = add nsw i32 %70, 1
store i32 %71, i32* %11
%72 = load i32, i32* %12
%73 = add nsw i32 %72, 1
store i32 %73, i32* %12
br label %27
74: ; preds = %27
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%2.2x \00"
define void @hex_dump(i8* %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = alloca [776 x i8]
%6 = alloca [776 x i8]
%7 = getelementptr inbounds [776 x i8], [776 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [776 x i8], [776 x i8]* %6, i64 0, i64 0
%9 = icmp slt i32 %1, 256
%10 = select i1 %9, i32 %1, i32 256
%11 = icmp eq i8* %0, null
br i1 %11, label %14, label %12
12: ; preds = %4
%13 = call i32 @strlcpy(i8* %8, i8* %0, i32 776)
br label %14
14: ; preds = %12, %4
%15 = icmp sgt i32 %3, 0
br i1 %15, label %16, label %43
16: ; preds = %14
%17 = add nsw i32 %3, -1
%18 = zext i32 %17 to i64
%19 = zext i32 %3 to i64
br label %20
20: ; preds = %16, %38
%21 = phi i64 [ 0, %16 ], [ %40, %38 ]
%22 = phi i32 [ 1, %16 ], [ %41, %38 ]
%23 = getelementptr inbounds i8, i8* %2, i64 %21
%24 = load i8, i8* %23
%25 = call i32 @snprintf(i8* %7, i32 776, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 zeroext %24)
%26 = call i32 @strncat(i8* %8, i8* %7, i32 776)
%27 = icmp eq i32 %22, %10
br i1 %27, label %28, label %32
28: ; preds = %20
%29 = call i32 @logd(i8* %8)
store i8 0, i8* %8
br i1 %11, label %38, label %30
30: ; preds = %28
%31 = call i32 @strlcpy(i8* %8, i8* %0, i32 776)
br label %38
32: ; preds = %20
%33 = icmp eq i64 %21, %18
%34 = icmp ne i32 %22, 0
%35 = select i1 %33, i1 %34, i1 false
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @logd(i8* %8)
br label %38
38: ; preds = %30, %28, %36, %32
%39 = phi i32 [ 0, %30 ], [ 0, %28 ], [ %22, %36 ], [ %22, %32 ]
%40 = add nuw nsw i64 %21, 1
%41 = add nsw i32 %39, 1
%42 = icmp eq i64 %40, %19
br i1 %42, label %43, label %20
43: ; preds = %38, %14
ret void
}