#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 uint16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void dump_data(FILE *fp, const char *name, uint16_t *val, int n_val) {
  int i;
  fprintf(fp, "uint16_t %s[] = {\n", name);
  for (i = 0; i < n_val - 1; i++) {
    if ((i % 8) == 0) {
      fprintf(fp, "  ");
    }
    fprintf(fp, "0x%04X, ", val[i]);
    if ((i % 8) == 7) {
      fprintf(fp, "\n");
    }
  }
  fprintf(fp, "0x%04X\n};\n", val[i]);
  fprintf(fp, "int %s_len = %d;\n", name, i + 1);
}


x86 assembly (clang, -O0):
<dump_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xeca(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d1 <dump_data+0xc1>
mov    -0x20(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117b <dump_data+0x6b>
mov    -0x8(%rbp),%rdi
lea    0xe9f(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x20(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x7,%edx
jne    11be <dump_data+0xae>
mov    -0x8(%rbp),%rdi
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11c3 <dump_data+0xb3>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1144 <dump_data+0x34>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe38(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeaf(%rip),%rsi
xor    %ebp,%ebp
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    $0x2,%r12d
jl     11fb <dump_data+0xcb>
mov    %r14,0x10(%rsp)
add    $0xffffffff,%r12d
mov    %r12d,0xc(%rsp)
mov    %r12d,%r14d
lea    0xe97(%rip),%rbp
xor    %r12d,%r12d
jmp    11c3 <dump_data+0x93>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe72(%rip),%rdi
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    (%r15,%r12,4),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%r12
cmp    %r12,%r14
je     11f2 <dump_data+0xc2>
mov    %r12d,%r13d
and    $0x7,%r13d
je     1190 <dump_data+0x60>
mov    (%r15,%r12,4),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    $0x7,%r13d
jne    11ba <dump_data+0x8a>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1030 <fputc@plt>
jmp    11ba <dump_data+0x8a>
mov    0xc(%rsp),%ebp
mov    0x10(%rsp),%r14
mov    %ebp,%eax
mov    (%r15,%rax,4),%edx
lea    0xe17(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%ebp
lea    0xe0e(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>

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

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