#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(const char *name, void *addr, size_t len, FILE *fp) {
  unsigned int i;
  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    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1148 <cdump+0x38>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1158 <cdump+0x48>
lea    0xeb1(%rip),%rax
mov    %rax,-0x38(%rbp)
jmp    1158 <cdump+0x48>
mov    -0x38(%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    -0x30(%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    $0x40,%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 i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32* %3, i32** %8
%11 = load i8*, i8** %6
store i8* %11, i8** %10
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = load i8*, i8** %5
br label %17
16: ; preds = %4
br label %17
17: ; preds = %16, %14
%18 = phi i8* [ %15, %14 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %16 ]
store i8* %18, i8** %5
%19 = load i32*, i32** %8
%20 = load i8*, i8** %5
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32 0, i32* %9
br label %22
22: ; preds = %51, %17
%23 = load i32, i32* %9
%24 = load i64, i64* %7
%25 = trunc i64 %24 to i32
%26 = icmp ult i32 %23, %25
br i1 %26, label %27, label %54
27: ; preds = %22
%28 = load i32, i32* %9
%29 = urem i32 %28, 16
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32*, i32** %8
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %42
34: ; preds = %27
%35 = load i32, i32* %9
%36 = urem i32 %35, 8
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32*, i32** %8
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %41
41: ; preds = %38, %34
br label %42
42: ; preds = %41, %31
%43 = load i32*, i32** %8
%44 = load i8*, i8** %10
%45 = load i32, i32* %9
%46 = zext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %43, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %42
%52 = load i32, i32* %9
%53 = add i32 %52, 1
store i32 %53, i32* %9
br label %22
54: ; preds = %22
%55 = load i32*, i32** %8
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %55, 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
}