#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void cdump(char *name, void *addr, size_t len, FILE *fp) {
  unsigned int i;
  unsigned char buff[17];
  unsigned char *pc = (unsigned char *)addr;
  name = name ? name : "dump";
  fprintf(fp, "const unsigned char %s[] = {", name);
  for (i = 0; i < (unsigned int)len; i++) {
    if ((i % 16) == 0) {
      fprintf(fp, "\n   ");
    } else if ((i % 8) == 0) {
      fprintf(fp, "   ");
    }
    fprintf(fp, " 0x%02x,", pc[i]);
  }
  fprintf(fp, "\n};\n");
}


x86 assembly (clang, -O0):
<cdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1148 <cdump+0x38>
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
jmp    1158 <cdump+0x48>
lea    0xeb1(%rip),%rax
mov    %rax,-0x50(%rbp)
jmp    1158 <cdump+0x48>
mov    -0x50(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    %ecx,%eax
jae    1203 <cdump+0xf3>
mov    -0x24(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    11b2 <cdump+0xa2>
mov    -0x20(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11d8 <cdump+0xc8>
mov    -0x24(%rbp),%eax
and    $0x7,%eax
cmp    $0x0,%eax
jne    11d3 <cdump+0xc3>
mov    -0x20(%rbp),%rdi
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11d8 <cdump+0xc8>
mov    -0x20(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    -0x24(%rbp),%ecx
movzbl (%rax,%rcx,1),%edx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117d <cdump+0x6d>
mov    -0x20(%rbp),%rdi
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r14
test   %rdi,%rdi
lea    0xec2(%rip),%rdx
cmovne %rdi,%rdx
lea    0xebc(%rip),%rsi
mov    %rcx,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
test   %r15d,%r15d
je     11bf <cdump+0x9f>
mov    %r15d,%ebp
lea    0xec0(%rip),%r15
lea    0xebe(%rip),%r12
xor    %r13d,%r13d
jmp    11a0 <cdump+0x80>
xchg   %ax,%ax
mov    $0x4,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %rbx,%rcx
call   1040 <fwrite@plt>
movzbl (%r14,%r13,1),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%rbp
je     11bf <cdump+0x9f>
test   $0xf,%r13b
je     1170 <cdump+0x50>
test   $0x7,%r13b
jne    1185 <cdump+0x65>
mov    $0x3,%esi
mov    $0x1,%edx
lea    0xe66(%rip),%rdi
jmp    117d <cdump+0x5d>
lea    0xe6a(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fwrite@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"dump\00"
@.str.1 = [29 x i8] c"const unsigned char %s[] = {\00"
@.str.2 = [5 x i8] c"\0A \00"
@.str.3 = [4 x i8] c" \00"
@.str.4 = [9 x i8] c" 0x%02x,\00"
@.str.5 = [5 x i8] c"\0A};\0A\00"
define void @cdump(i8* %0, i8* %1, i64 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i32
%10 = alloca [17 x i8]
%11 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32* %3, i32** %8
%12 = load i8*, i8** %6
store i8* %12, i8** %11
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = load i8*, i8** %5
br label %18
17: ; preds = %4
br label %18
18: ; preds = %17, %15
%19 = phi i8* [ %16, %15 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %17 ]
store i8* %19, i8** %5
%20 = load i32*, i32** %8
%21 = load i8*, i8** %5
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %21)
store i32 0, i32* %9
br label %23
23: ; preds = %52, %18
%24 = load i32, i32* %9
%25 = load i64, i64* %7
%26 = trunc i64 %25 to i32
%27 = icmp ult i32 %24, %26
br i1 %27, label %28, label %55
28: ; preds = %23
%29 = load i32, i32* %9
%30 = urem i32 %29, 16
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32*, i32** %8
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %43
35: ; preds = %28
%36 = load i32, i32* %9
%37 = urem i32 %36, 8
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %35
%40 = load i32*, i32** %8
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %39, %35
br label %43
43: ; preds = %42, %32
%44 = load i32*, i32** %8
%45 = load i8*, i8** %11
%46 = load i32, i32* %9
%47 = zext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %43
%53 = load i32, i32* %9
%54 = add i32 %53, 1
store i32 %54, i32* %9
br label %23
55: ; preds = %23
%56 = load i32*, i32** %8
%57 = call i32 (i32*, i8*, ...) @fprintf(i32* %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"dump\00"
@.str.1 = [29 x i8] c"const unsigned char %s[] = {\00"
@.str.2 = [5 x i8] c"\0A \00"
@.str.3 = [4 x i8] c" \00"
@.str.4 = [9 x i8] c" 0x%02x,\00"
@.str.5 = [5 x i8] c"\0A};\0A\00"
define void @cdump(i8* %0, i8* nocapture %1, i64 %2, i32* nocapture %3) {
%5 = icmp eq i8* %0, null
%6 = select i1 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0
%7 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = trunc i64 %2 to i32
%9 = icmp eq i32 %8, 0
br i1 %9, label %31, label %10
10: ; preds = %4
%11 = and i64 %2, 4294967295
br label %12
12: ; preds = %10, %24
%13 = phi i64 [ 0, %10 ], [ %29, %24 ]
%14 = trunc i64 %13 to i32
%15 = and i32 %14, 15
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 4, i64 1, i32* %3)
br label %24
19: ; preds = %12
%20 = and i32 %14, 7
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 3, i64 1, i32* %3)
br label %24
24: ; preds = %19, %22, %17
%25 = getelementptr inbounds i8, i8* %1, i64 %13
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = add nuw nsw i64 %13, 1
%30 = icmp eq i64 %29, %11
br i1 %30, label %31, label %12
31: ; preds = %24, %4
%32 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i64 4, i64 1, i32* %3)
ret void
}