#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*/ char2cchar(char *, char);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int strlen(char *);
void bin2c_table(int size, FILE *in, FILE *out) {
  char buf[1024];
  size_t s = sizeof buf;
  int i, j = 0;
  char elem[16];
  while ((s = fread(buf, 1, s, in))) {
    for (i = 0; i < s; i++) {
      int elemlen;
      if (i % 8 == 0) {
        fputs("\t", out);
      }
      char2cchar(elem, buf[i]);
      elemlen = strlen(elem);
      fputs(elem, out);
      if (j + 1 < size) {
        int k;
        fputs(",", out);
        for (k = 0; k < 4 - elemlen; k++)
          fputs(" ", out);
        if ((j + 1) % 8 == 0) {
          fputs("\n", out);
        }
      } else {
        fputs("\n", out);
      }
      j++;
    }
  }
}


x86 assembly (clang, -O0):
<bin2c_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x400,-0x428(%rbp)
movl   $0x0,-0x430(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
je     12ea <bin2c_table+0x1aa>
movl   $0x0,-0x42c(%rbp)
movslq -0x42c(%rbp),%rax
cmp    -0x428(%rbp),%rax
jae    12e5 <bin2c_table+0x1a5>
mov    -0x42c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11dd <bin2c_table+0x9d>
mov    -0x18(%rbp),%rsi
lea    0xe28(%rip),%rdi
call   1050 <fputs@plt>
lea    -0x440(%rbp),%rdi
movslq -0x42c(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%esi
ff
call   1060 <char2cchar@plt>
lea    -0x440(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x444(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <fputs@plt>
mov    -0x430(%rbp),%eax
add    $0x1,%eax
cmp    -0x4(%rbp),%eax
jge    12b2 <bin2c_table+0x172>
mov    -0x18(%rbp),%rsi
lea    0xdcb(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x0,-0x448(%rbp)
mov    -0x448(%rbp),%eax
mov    $0x4,%ecx
sub    -0x444(%rbp),%ecx
cmp    %ecx,%eax
jge    1283 <bin2c_table+0x143>
mov    -0x18(%rbp),%rsi
lea    0xd9a(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x448(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x448(%rbp)
jmp    1246 <bin2c_table+0x106>
mov    -0x430(%rbp),%eax
add    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12ad <bin2c_table+0x16d>
mov    -0x18(%rbp),%rsi
lea    0xd5e(%rip),%rdi
call   1050 <fputs@plt>
jmp    12c2 <bin2c_table+0x182>
mov    -0x18(%rbp),%rsi
lea    0xd49(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x430(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x430(%rbp)
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    11a2 <bin2c_table+0x62>
jmp    116b <bin2c_table+0x2b>
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bin2c_table>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %rdx,%rbx
mov    %rsi,%rcx
mov    %edi,%r12d
lea    0x30(%rsp),%rdi
mov    $0x400,%edx
mov    $0x1,%esi
mov    %rcx,0x8(%rsp)
call   1030 <fread@plt>
test   %rax,%rax
je     12bb <bin2c_table+0x16b>
mov    %rax,%rbp
xor    %r15d,%r15d
jmp    11cb <bin2c_table+0x7b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rsp),%r15
add    %ebp,%r15d
lea    0x30(%rsp),%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    0x8(%rsp),%rcx
call   1030 <fread@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12bb <bin2c_table+0x16b>
xor    %r14d,%r14d
mov    %r15,0x10(%rsp)
mov    %r15d,%eax
mov    %r15d,0x4(%rsp)
mov    %rbp,0x18(%rsp)
jmp    1206 <bin2c_table+0xb6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
add    $0x1,%r14
cmp    %rbp,%r14
je     11a0 <bin2c_table+0x50>
mov    %rbp,%r15
mov    %r12d,%ebp
test   $0x7,%r14b
jne    121f <bin2c_table+0xcf>
mov    $0x9,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
movsbl 0x30(%rsp,%r14,1),%esi
lea    0x20(%rsp),%r12
mov    %r12,%rdi
call   1060 <char2cchar@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%r13d
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    0x4(%rsp),%eax
add    $0x1,%eax
mov    %ebp,%r12d
mov    %eax,0x4(%rsp)
cmp    %ebp,%eax
mov    %r15,%rbp
jge    11f0 <bin2c_table+0xa0>
mov    %r12d,%ebp
mov    $0x2c,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
cmp    $0x3,%r13d
jg     12a3 <bin2c_table+0x153>
mov    $0x4,%r12d
sub    %r13d,%r12d
cmp    $0x2,%r12d
mov    $0x1,%eax
cmovl  %eax,%r12d
nopl   0x0(%rax)
mov    $0x20,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
add    $0xffffffff,%r12d
jne    1290 <bin2c_table+0x140>
testb  $0x7,0x4(%rsp)
mov    %ebp,%r12d
mov    0x18(%rsp),%rbp
jne    11fd <bin2c_table+0xad>
jmp    11f0 <bin2c_table+0xa0>
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\09\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @bin2c_table(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca [16 x i8]
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i64 1024, i64* %8
store i32 0, i32* %10
br label %14
14: ; preds = %81, %3
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%16 = load i64, i64* %8
%17 = load i32*, i32** %5
%18 = call i64 @fread(i8* %15, i32 1, i64 %16, i32* %17)
store i64 %18, i64* %8
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %82
20: ; preds = %14
store i32 0, i32* %9
br label %21
21: ; preds = %78, %20
%22 = load i32, i32* %9
%23 = sext i32 %22 to i64
%24 = load i64, i64* %8
%25 = icmp ult i64 %23, %24
br i1 %25, label %26, label %81
26: ; preds = %21
%27 = load i32, i32* %9
%28 = srem i32 %27, 8
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32*, i32** %6
%32 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32* %31)
br label %33
33: ; preds = %30, %26
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %36
%38 = load i8, i8* %37
%39 = call i32 @char2cchar(i8* %34, i8 signext %38)
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
store i32 %41, i32* %12
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%43 = load i32*, i32** %6
%44 = call i32 @fputs(i8* %42, i32* %43)
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
%47 = load i32, i32* %4
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %72
49: ; preds = %33
%50 = load i32*, i32** %6
%51 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32* %50)
store i32 0, i32* %13
br label %52
52: ; preds = %60, %49
%53 = load i32, i32* %13
%54 = load i32, i32* %12
%55 = sub nsw i32 4, %54
%56 = icmp slt i32 %53, %55
br i1 %56, label %57, label %63
57: ; preds = %52
%58 = load i32*, i32** %6
%59 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32* %58)
br label %60
60: ; preds = %57
%61 = load i32, i32* %13
%62 = add nsw i32 %61, 1
store i32 %62, i32* %13
br label %52
63: ; preds = %52
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
%66 = srem i32 %65, 8
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %63
%69 = load i32*, i32** %6
%70 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32* %69)
br label %71
71: ; preds = %68, %63
br label %75
72: ; preds = %33
%73 = load i32*, i32** %6
%74 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32* %73)
br label %75
75: ; preds = %72, %71
%76 = load i32, i32* %10
%77 = add nsw i32 %76, 1
store i32 %77, i32* %10
br label %78
78: ; preds = %75
%79 = load i32, i32* %9
%80 = add nsw i32 %79, 1
store i32 %80, i32* %9
br label %21
81: ; preds = %21
br label %14
82: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @bin2c_table(i32 %0, i32* nocapture %1, i32* nocapture %2) {
%4 = alloca [1024 x i8]
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%8 = call i64 @fread(i8* %6, i32 1, i64 1024, i32* %1)
%9 = icmp eq i64 %8, 0
br i1 %9, label %52, label %14
10: ; preds = %49
%11 = add i32 %16, %17
%12 = call i64 @fread(i8* %6, i32 1, i64 %15, i32* %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %52, label %14
14: ; preds = %3, %10
%15 = phi i64 [ %12, %10 ], [ %8, %3 ]
%16 = phi i32 [ %11, %10 ], [ 0, %3 ]
%17 = trunc i64 %15 to i32
br label %18
18: ; preds = %14, %49
%19 = phi i64 [ 0, %14 ], [ %50, %49 ]
%20 = phi i32 [ %16, %14 ], [ %31, %49 ]
%21 = and i64 %19, 7
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = call i32 @fputc(i32 9, i32* %2)
br label %25
25: ; preds = %23, %18
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %19
%27 = load i8, i8* %26
%28 = call i32 @char2cchar(i8* %7, i8 signext %27)
%29 = call i32 @strlen(i8* %7)
%30 = call i32 @fputs(i8* %7, i32* %2)
%31 = add nsw i32 %20, 1
%32 = icmp slt i32 %31, %0
br i1 %32, label %33, label %47
33: ; preds = %25
%34 = call i32 @fputc(i32 44, i32* %2)
%35 = icmp slt i32 %29, 4
br i1 %35, label %36, label %44
36: ; preds = %33
%37 = sub i32 4, %29
%38 = call i32 @llvm.smax.i32(i32 %37, i32 1)
br label %39
39: ; preds = %36, %39
%40 = phi i32 [ %42, %39 ], [ 0, %36 ]
%41 = call i32 @fputc(i32 32, i32* %2)
%42 = add nuw nsw i32 %40, 1
%43 = icmp eq i32 %42, %38
br i1 %43, label %44, label %39
44: ; preds = %39, %33
%45 = and i32 %31, 7
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %25, %44
%48 = call i32 @fputc(i32 10, i32* %2)
br label %49
49: ; preds = %47, %44
%50 = add nuw i64 %19, 1
%51 = icmp eq i64 %50, %15
br i1 %51, label %10, label %18
52: ; preds = %10, %3
ret void
}