#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 count_run(int, int, int);
int /*<<< orphan*/ printf(char *, ...);
void gen_run_length_table(bool header, int val, char *name) {
  int i, j;
  if (header)
    printf("extern ");
  printf("const uint8_t %s [8][256]", name);
  if (header) {
    printf(";\n");
    return;
  }
  printf(" =\n");
  printf("{\n");
  for (i = 0; i < 8; i++) {
    printf("  {\n");
    for (j = 0; j < 256; j++) {
      if ((j & 15) == 0)
        printf("  ");
      printf("%d", count_run(j, i, val));
      if (j != 0xff)
        printf(",");
      if ((j & 15) == 15)
        printf("\n");
      else
        printf(" ");
    }
    printf("  }");
    if (i != 7)
      printf(",");
    printf("\n");
  }
  printf("};\n");
}


x86 assembly (clang, -O0):
<gen_run_length_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     114a <gen_run_length_table+0x2a>
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x4(%rbp)
je     1179 <gen_run_length_table+0x59>
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12b1 <gen_run_length_table+0x191>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    12a3 <gen_run_length_table+0x183>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x100,-0x18(%rbp)
jge    1261 <gen_run_length_table+0x141>
mov    -0x18(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    11e5 <gen_run_length_table+0xc5>
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1030 <count_run@plt>
mov    %eax,%esi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0xff,-0x18(%rbp)
je     121e <gen_run_length_table+0xfe>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
and    $0xf,%eax
cmp    $0xf,%eax
jne    1240 <gen_run_length_table+0x120>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    124e <gen_run_length_table+0x12e>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1253 <gen_run_length_table+0x133>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bb <gen_run_length_table+0x9b>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x7,-0x14(%rbp)
je     1287 <gen_run_length_table+0x167>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119c <gen_run_length_table+0x7c>
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_run_length_table>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbp
test   %edi,%edi
je     117d <gen_run_length_table+0x3d>
lea    0xea7(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xea1(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xeb8(%rip),%rdi
jmp    1290 <gen_run_length_table+0x150>
mov    %esi,%ebx
lea    0xe82(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe95(%rip),%rdi
call   1040 <puts@plt>
lea    0xe91(%rip),%rdi
call   1040 <puts@plt>
lea    0xe76(%rip),%r12
mov    $0xa,%r13d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
xor    %r14d,%r14d
jmp    11f2 <gen_run_length_table+0xb2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
call   1030 <putchar@plt>
add    $0x1,%r14d
cmp    $0x100,%r14d
je     1250 <gen_run_length_table+0x110>
mov    %r14d,%r15d
and    $0xf,%r15d
jne    1209 <gen_run_length_table+0xc9>
lea    0xe20(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1050 <count_run@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
cmp    $0xff,%r14d
je     11e0 <gen_run_length_table+0xa0>
mov    $0x2c,%edi
call   1030 <putchar@plt>
cmp    $0xf,%r15d
mov    $0x20,%edi
cmove  %r13d,%edi
jmp    11e0 <gen_run_length_table+0xa0>
nopl   0x0(%rax,%rax,1)
lea    0xdd1(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x7,%ebp
je     127f <gen_run_length_table+0x13f>
mov    $0x2c,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%ebp
jmp    11c0 <gen_run_length_table+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xd9f(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"extern \00"
@.str.1 = [26 x i8] c"const uint8_t %s [8][256]\00"
@.str.2 = [3 x i8] c";\0A\00"
@.str.3 = [4 x i8] c" =\0A\00"
@.str.4 = [3 x i8] c"{\0A\00"
@.str.5 = [5 x i8] c" {\0A\00"
@.str.6 = [3 x i8] c" \00"
@.str.7 = [3 x i8] c"%d\00"
@.str.8 = [2 x i8] c",\00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [2 x i8] c" \00"
@.str.11 = [4 x i8] c" }\00"
@.str.12 = [4 x i8] c"};\0A\00"
define void @gen_run_length_table(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %3
%14 = load i8*, i8** %6
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %72
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %7
br label %23
23: ; preds = %67, %20
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 8
br i1 %25, label %26, label %70
26: ; preds = %23
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %8
br label %28
28: ; preds = %56, %26
%29 = load i32, i32* %8
%30 = icmp slt i32 %29, 256
br i1 %30, label %31, label %59
31: ; preds = %28
%32 = load i32, i32* %8
%33 = and i32 %32, 15
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
%38 = load i32, i32* %8
%39 = load i32, i32* %7
%40 = load i32, i32* %5
%41 = call i32 @count_run(i32 %38, i32 %39, i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %41)
%43 = load i32, i32* %8
%44 = icmp ne i32 %43, 255
br i1 %44, label %45, label %47
45: ; preds = %37
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %47
47: ; preds = %45, %37
%48 = load i32, i32* %8
%49 = and i32 %48, 15
%50 = icmp eq i32 %49, 15
br i1 %50, label %51, label %53
51: ; preds = %47
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %55
53: ; preds = %47
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %55
55: ; preds = %53, %51
br label %56
56: ; preds = %55
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
store i32 %58, i32* %8
br label %28
59: ; preds = %28
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%61 = load i32, i32* %7
%62 = icmp ne i32 %61, 7
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
br label %65
65: ; preds = %63, %59
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %67
67: ; preds = %65
%68 = load i32, i32* %7
%69 = add nsw i32 %68, 1
store i32 %69, i32* %7
br label %23
70: ; preds = %23
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0))
br label %72
72: ; preds = %70, %18
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"extern \00"
@.str.1 = [26 x i8] c"const uint8_t %s [8][256]\00"
@.str.6 = [3 x i8] c" \00"
@.str.7 = [3 x i8] c"%d\00"
@.str.11 = [4 x i8] c" }\00"
@str = [3 x i8] c" =\00"
@str.13 = [2 x i8] c"{\00"
@str.14 = [3 x i8] c"};\00"
@str.15 = [4 x i8] c" {\00"
@str.16 = [2 x i8] c";\00"
define void @gen_run_length_table(i32 %0, i32 %1, i8* %2) {
%4 = icmp eq i32 %0, 0
br i1 %4, label %8, label %5
5: ; preds = %3
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %43
8: ; preds = %3
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.13, i64 0, i64 0))
br label %12
12: ; preds = %37, %8
%13 = phi i32 [ 0, %8 ], [ %40, %37 ]
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.15, i64 0, i64 0))
br label %15
15: ; preds = %12, %29
%16 = phi i32 [ 0, %12 ], [ %32, %29 ]
%17 = and i32 %16, 15
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = tail call i32 @count_run(i32 %16, i32 %13, i32 %1)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i32 %22)
%24 = icmp eq i32 %16, 255
br i1 %24, label %29, label %25
25: ; preds = %21
%26 = tail call i32 @putchar(i32 44)
%27 = icmp eq i32 %17, 15
%28 = select i1 %27, i32 10, i32 32
br label %29
29: ; preds = %25, %21
%30 = phi i32 [ 10, %21 ], [ %28, %25 ]
%31 = tail call i32 @putchar(i32 %30)
%32 = add nuw nsw i32 %16, 1
%33 = icmp eq i32 %32, 256
br i1 %33, label %34, label %15
34: ; preds = %29
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%36 = icmp eq i32 %13, 7
br i1 %36, label %41, label %37
37: ; preds = %34
%38 = tail call i32 @putchar(i32 44)
%39 = tail call i32 @putchar(i32 10)
%40 = add nuw nsw i32 %13, 1
br label %12
41: ; preds = %34
%42 = tail call i32 @putchar(i32 10)
br label %43
43: ; preds = %41, %5
%44 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @str.14, i64 0, i64 0), %41 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.16, i64 0, i64 0), %5 ]
%45 = tail call i32 @puts(i8* dereferenceable(1) %44)
ret void
}