#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fread(unsigned char *, unsigned long, int,
                         int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
unsigned long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(unsigned long);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  FILE *input;
  unsigned long size, csize, i, n = 0;
  unsigned char *data, *cdata;
  int usezlib = 0;
  usezlib = 0;
  if (argc < 2) {
    fprintf(stderr, "Usage: bin2c <input> [--no-zlib] > output\n");
    exit(1);
  }
  if ((input = fopen(argv[1], "rb")) == NULL) {
    fprintf(stderr, "Unable to open input file '%s'\n", argv[1]);
    exit(2);
  }
  if (fseek(input, 0, SEEK_END) != 0) {
    fprintf(stderr, "Unable to seek to end of file\n");
    fclose(input);
    exit(3);
  }
  if (argc > 2 && !(strcmp(argv[2], "--no-zlib")))
    usezlib = 0;
  size = ftell(input);
  fseek(input, 0, SEEK_SET);
  data = (unsigned char *)malloc(size);
  cdata = (unsigned char *)malloc(size);
  fread(data, size, 1, input);
  fclose(input);
  csize = size;
  memcpy(cdata, data, size);
  printf("{\nstatic unsigned char __LUA_CDATA[] = {\n");
  for (i = 0; i <= csize; i++) {
    printf("%3d, ", cdata[i]);
    if (n++ == 20) {
      putchar('\n');
      n = 0;
    }
  }
  printf("\n};\n\n");
  printf("lua_dobuffer( L, (const char *)__LUA_CDATA, %d, \"%s\" );\n", size,
         argv[1]);
  printf("}\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x4c(%rbp)
movl   $0x0,-0x4c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1217 <main+0x57>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe05(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1262 <main+0xa2>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d7b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
cmp    $0x0,%rax
je     12aa <main+0xea>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    $0x3,%edi
call   10e0 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jle    12d8 <main+0x118>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdaa(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    12d8 <main+0x118>
movl   $0x0,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2ce0(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   10a0 <memcpy@plt>
lea    0xd25(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
ja     13ca <main+0x20a>
mov    -0x48(%rbp),%rax
mov    -0x30(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
cmp    $0x14,%rax
jne    13b4 <main+0x1f4>
mov    $0xa,%edi
call   1030 <putchar@plt>
movq   $0x0,-0x38(%rbp)
jmp    13b9 <main+0x1f9>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1361 <main+0x1a1>
lea    0xcd6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xcc2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xced(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    1302 <main+0x142>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe49(%rip),%rsi
call   10d0 <fopen@plt>
test   %rax,%rax
je     1323 <main+0x163>
mov    %rax,%r15
mov    %rbx,(%rsp)
mov    0x2dea(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
test   %rax,%rax
jne    1348 <main+0x188>
mov    %r15,%rdi
call   1090 <ftell@plt>
mov    %rax,%r12
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   10c0 <fseek@plt>
mov    %r12,%rdi
call   10b0 <malloc@plt>
mov    %rax,%r13
mov    %r12,%rdi
call   10b0 <malloc@plt>
mov    %rax,%r14
mov    %r13,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %r15,%rcx
call   1050 <fread@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   10a0 <memcpy@plt>
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
lea    0xdea(%rip),%r15
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    12a5 <main+0xe5>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %ebp,%ebp
add    $0x1,%rbx
cmp    %r12,%rbx
ja     12c0 <main+0x100>
movzbl (%r14,%rbx,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0x14,%rbp
je     1290 <main+0xd0>
add    $0x1,%rbp
jmp    129c <main+0xdc>
lea    0xe0e(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rax
mov    0x8(%rax),%rdx
lea    0xd98(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdee(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
lea    0xcee(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbx),%rdx
lea    0xcf7(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
lea    0xcf6(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    $0x3,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"Usage: bin2c <input> [--no-zlib] > output\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [32 x i8] c"Unable to open input file '%s'\0A\00"
@SEEK_END = global i32 0
@.str.3 = [31 x i8] c"Unable to seek to end of file\0A\00"
@.str.4 = [10 x i8] c"--no-zlib\00"
@SEEK_SET = global i32 0
@.str.5 = [42 x i8] c"{\0Astatic unsigned char __LUA_CDATA[] = {\0A\00"
@.str.6 = [6 x i8] c"%3d, \00"
@.str.7 = [6 x i8] c"\0A};\0A\0A\00"
@.str.8 = [57 x i8] c"lua_dobuffer( L, (const char *)__LUA_CDATA, %d, \22%s\22 );\0A\00"
@.str.9 = [3 x i8] c"}\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %10
store i32 0, i32* %13
store i32 0, i32* %13
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 2
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %33
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 2)
unreachable
33: ; preds = %20
%34 = load i32*, i32** %6
%35 = load i32, i32* @SEEK_END
%36 = call i64 @fseek(i32* %34, i32 0, i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %33
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32*, i32** %6
%42 = call i32 @fclose(i32* %41)
%43 = call i32 @exit(i32 3)
unreachable
44: ; preds = %33
%45 = load i32, i32* %4
%46 = icmp sgt i32 %45, 2
br i1 %46, label %47, label %54
47: ; preds = %44
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call i32 @strcmp(i8* %50, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%52 = icmp ne i32 %51, 0
br i1 %52, label %54, label %53
53: ; preds = %47
store i32 0, i32* %13
br label %54
54: ; preds = %53, %47, %44
%55 = load i32*, i32** %6
%56 = call i64 @ftell(i32* %55)
store i64 %56, i64* %7
%57 = load i32*, i32** %6
%58 = load i32, i32* @SEEK_SET
%59 = call i64 @fseek(i32* %57, i32 0, i32 %58)
%60 = load i64, i64* %7
%61 = call i64 @malloc(i64 %60)
%62 = inttoptr i64 %61 to i8*
store i8* %62, i8** %11
%63 = load i64, i64* %7
%64 = call i64 @malloc(i64 %63)
%65 = inttoptr i64 %64 to i8*
store i8* %65, i8** %12
%66 = load i8*, i8** %11
%67 = load i64, i64* %7
%68 = load i32*, i32** %6
%69 = call i32 @fread(i8* %66, i64 %67, i32 1, i32* %68)
%70 = load i32*, i32** %6
%71 = call i32 @fclose(i32* %70)
%72 = load i64, i64* %7
store i64 %72, i64* %8
%73 = load i8*, i8** %12
%74 = load i8*, i8** %11
%75 = load i64, i64* %7
%76 = call i32 @memcpy(i8* %73, i8* %74, i64 %75)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
store i64 0, i64* %9
br label %78
78: ; preds = %95, %54
%79 = load i64, i64* %9
%80 = load i64, i64* %8
%81 = icmp ule i64 %79, %80
br i1 %81, label %82, label %98
82: ; preds = %78
%83 = load i8*, i8** %12
%84 = load i64, i64* %9
%85 = getelementptr inbounds i8, i8* %83, i64 %84
%86 = load i8, i8* %85
%87 = zext i8 %86 to i32
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %87)
%89 = load i64, i64* %10
%90 = add i64 %89, 1
store i64 %90, i64* %10
%91 = icmp eq i64 %89, 20
br i1 %91, label %92, label %94
92: ; preds = %82
%93 = call i32 @putchar(i8 signext 10)
store i64 0, i64* %10
br label %94
94: ; preds = %92, %82
br label %95
95: ; preds = %94
%96 = load i64, i64* %9
%97 = add i64 %96, 1
store i64 %97, i64* %9
br label %78
98: ; preds = %78
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%100 = load i64, i64* %7
%101 = load i8**, i8*** %5
%102 = getelementptr inbounds i8*, i8** %101, i64 1
%103 = load i8*, i8** %102
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.8, i64 0, i64 0), i64 %100, i8* %103)
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"Usage: bin2c <input> [--no-zlib] > output\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [32 x i8] c"Unable to open input file '%s'\0A\00"
@SEEK_END = global i32 0
@.str.3 = [31 x i8] c"Unable to seek to end of file\0A\00"
@SEEK_SET = global i32 0
@.str.6 = [6 x i8] c"%3d, \00"
@.str.8 = [57 x i8] c"lua_dobuffer( L, (const char *)__LUA_CDATA, %d, \22%s\22 );\0A\00"
@str = [41 x i8] c"{\0Astatic unsigned char __LUA_CDATA[] = {\00"
@str.10 = [5 x i8] c"\0A};\0A\00"
@str.11 = [2 x i8] c"}\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %9
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = tail call i32 @exit(i32 2)
unreachable
18: ; preds = %8
%19 = load i32, i32* @SEEK_END
%20 = tail call i64 @fseek(i32* %11, i32 0, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%25 = tail call i32 @fclose(i32* %11)
%26 = tail call i32 @exit(i32 3)
unreachable
27: ; preds = %18
%28 = tail call i64 @ftell(i32* %11)
%29 = load i32, i32* @SEEK_SET
%30 = tail call i64 @fseek(i32* %11, i32 0, i32 %29)
%31 = tail call i64 @malloc(i64 %28)
%32 = inttoptr i64 %31 to i8*
%33 = tail call i64 @malloc(i64 %28)
%34 = inttoptr i64 %33 to i8*
%35 = tail call i32 @fread(i8* %32, i64 %28, i32 1, i32* %11)
%36 = tail call i32 @fclose(i32* %11)
%37 = tail call i32 @memcpy(i8* %34, i8* %32, i64 %28)
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %39
39: ; preds = %27, %50
%40 = phi i64 [ 0, %27 ], [ %52, %50 ]
%41 = phi i64 [ 0, %27 ], [ %51, %50 ]
%42 = getelementptr inbounds i8, i8* %34, i64 %40
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i32 %44)
%46 = add i64 %41, 1
%47 = icmp eq i64 %41, 20
br i1 %47, label %48, label %50
48: ; preds = %39
%49 = tail call i32 @putchar(i8 signext 10)
br label %50
50: ; preds = %39, %48
%51 = phi i64 [ 0, %48 ], [ %46, %39 ]
%52 = add i64 %40, 1
%53 = icmp ugt i64 %52, %28
br i1 %53, label %54, label %39
54: ; preds = %50
%55 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.10, i64 0, i64 0))
%56 = load i8*, i8** %9
%57 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.8, i64 0, i64 0), i64 %28, i8* %56)
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.11, i64 0, i64 0))
ret i32 0
}