// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/tools/bin2c.cc
// Function: main
int main(int argc, const char * const argv[])
{
    bool showusage = false;
    string sourcefile;
    string symbol("bin2cdata");
    bool textmode = false;

    if (argc < 2) {
        showusage = true;
    } else {
        int    anonparam = 0;
        string opt;

        for (int i = 1; i < argc; ++i) {
            if (argv[i][0] == '-') {
                opt = string(argv[i]).substr(1);
                if (opt == "text") {
                    textmode = true;
                } else {
                    cerr << "error: unrecognised option -" << opt << endl;
                    showusage = true;
                }
            } else {
                opt = string(argv[i]);
                switch (anonparam) {
                    case 0:
                        sourcefile = opt;
                        break;
                    case 1:
                        symbol = opt;
                        break;
                    default:
                        cerr << "warning: too many parameters passed" << endl;
                        break;
                }
                anonparam++;
            }
        }
    }

    if (showusage) {
        usage();
        return 1;
    } else {
        ifstream sourcefs(sourcefile.c_str(), ios::in | ios::binary);
        int bytecount = 0;
        char chr;

        if (!sourcefs.is_open()) {
            cerr << "error: could not open " << sourcefile << " for reading." << endl;
            return 1;
        }
        cout << "// Generated by bin2c. Do not edit directly.\n\n";
        if (!textmode) {
            cout << "const unsigned char " << symbol << "[] =";
            cout << hex << setfill('0');
            cout << " {\n";
            while (sourcefs.get(chr)) {
                if ((bytecount & 15) == 0) {
                    cout << "    ";
                } else {
                    cout << " ";
                }
                cout << "0x" << setw(2) << (unsigned)(unsigned char)chr << ",";
                bytecount++;
                if ((bytecount & 15) == 0) {
                    cout << "\n";
                }
            }
            if ((bytecount & 15) > 0) {
                cout << "\n";
            }
            cout << "};\n";
        } else {
            int charcount = 0;

            cout << "const char " << symbol << "[] =";
            cout << "\n";
            while (sourcefs.get(chr)) {
                bytecount++;
                if (charcount == 0) {
                    cout << "    \"";
                }
                charcount++;
                switch (chr) {
                    case '\0':
                        cout << "\\0";
                        break;
                    case '"':
                        cout << "\\\"";
                        break;
                    case '\t':
                        cout << "\\t";
                        break;
                    case '\r':
                        cout << "\\r";
                        break;
                    case '\n':
                        cout << "\\n\"\n";
                        charcount = 0;
                        break;
                    default:
                        if (chr < 32 || chr >= 127) {
                            cout << "\\x" << hex << chr;
                        } else {
                            cout << chr;
                        }
                        break;
                }
            }
            if (charcount != 0) {
                cout << "\"\n";
            }
            cout << ";\n";
        }

        cout << "\nconst int " << symbol << "_size = " << dec << bytecount << ";\n";

        sourcefs.close();
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2a8, %rsp            # imm = 0x2A8
movq %rsi, 0x18(%rsp)
movl %edi, %ebp
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xd78(%rip), %rsi       # 0x3127
leaq 0x20(%rsp), %rdi
leaq 0xa0(%rsp), %rdx
callq 0x294a
cmpl $0x2, %ebp
jl 0x251c
leaq 0xb0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl %ebp, %r14d
movl $0x0, 0x10(%rsp)
pushq $0x1
popq %r15
leaq 0x80(%rsp), %r12
leaq 0x40(%rsp), %rbp
leaq 0xa0(%rsp), %r13
xorl %ebx, %ebx
movl $0x0, 0x14(%rsp)
cmpq %r15, %r14
je 0x2508
movq 0x18(%rsp), %rax
movq (%rax,%r15,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x247a
movq %r12, %rdi
leaq 0xf(%rsp), %rdx
callq 0x294a
movq %rbp, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
pushq $-0x1
popq %rcx
callq 0x2110
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2130
movq %rbp, %rdi
callq 0x2080
movq %r12, %rdi
callq 0x2080
movq %r13, %rdi
leaq 0xccb(%rip), %rsi       # 0x3131
callq 0x2985
testb %al, %al
je 0x24b5
movb $0x1, %al
movl %eax, 0x10(%rsp)
jmp 0x2500
movq %rbp, %rdi
movq %r12, %rdx
callq 0x294a
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2130
movq %rbp, %rdi
callq 0x2080
leaq 0x60(%rsp), %rdi
testl %ebx, %ebx
je 0x24ab
cmpl $0x1, %ebx
jne 0x24e3
leaq 0x20(%rsp), %rdi
movq %r13, %rsi
callq 0x20a0
jmp 0x24fe
movq 0x2b34(%rip), %rdi      # 0x4ff0
leaq 0xc73(%rip), %rsi       # 0x3136
callq 0x2100
movq %rax, %rdi
movq %r13, %rsi
callq 0x20f0
movb $0x1, %cl
movl %ecx, 0x14(%rsp)
movq %rax, %rdi
callq 0x2090
jmp 0x2500
movq 0x2b06(%rip), %rdi      # 0x4ff0
leaq 0xc62(%rip), %rsi       # 0x3153
callq 0x2100
movq %rax, %rdi
callq 0x2090
incl %ebx
incq %r15
jmp 0x240c
leaq 0xa0(%rsp), %rdi
callq 0x2080
testb $0x1, 0x14(%rsp)
je 0x2529
callq 0x22dc
pushq $0x1
popq %rbx
jmp 0x28bb
movq 0x60(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
pushq $0xc
popq %rdx
callq 0x21a0
leaq 0x118(%rsp), %rdi
callq 0x2040
testb %al, %al
je 0x269b
movq 0x2a76(%rip), %rdi      # 0x4fd0
leaq 0xc3b(%rip), %rsi       # 0x319c
callq 0x2100
testb $0x1, 0x10(%rsp)
je 0x26da
movq 0x2a58(%rip), %rdi      # 0x4fd0
leaq 0xc78(%rip), %rsi       # 0x31f7
callq 0x2100
leaq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x20f0
leaq 0xc48(%rip), %rsi       # 0x31e0
movq %rax, %rdi
callq 0x2100
movq 0x2a29(%rip), %r14      # 0x4fd0
leaq 0xc1b(%rip), %rsi       # 0x31c9
movq %r14, %rdi
callq 0x2100
xorl %ebx, %ebx
leaq 0xa0(%rsp), %r15
leaq 0x40(%rsp), %r12
leaq 0xc37(%rip), %r13       # 0x3203
xorl %ebp, %ebp
movq %r15, %rdi
movq %r12, %rsi
callq 0x2140
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x27eb
testl %ebp, %ebp
jne 0x25fa
movq %r14, %rdi
movq %r13, %rsi
callq 0x2100
incl %ebp
movzbl 0x40(%rsp), %ecx
cmpl $0x22, %ecx
je 0x2685
cmpl $0x9, %ecx
je 0x2660
cmpl $0xa, %ecx
je 0x2672
cmpl $0xd, %ecx
je 0x2669
leaq 0xbed(%rip), %rsi       # 0x3209
testl %ecx, %ecx
je 0x268c
leal -0x7f(%rcx), %edx
movq %r14, %rax
cmpb $-0x60, %dl
ja 0x2653
movq %r14, %rdi
leaq 0xbe5(%rip), %rsi       # 0x321a
callq 0x2100
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movb 0x40(%rsp), %cl
movsbl %cl, %esi
movq %rax, %rdi
callq 0x2120
jmp 0x2694
leaq 0xba8(%rip), %rsi       # 0x320f
jmp 0x268c
leaq 0xba2(%rip), %rsi       # 0x3212
jmp 0x268c
xorl %ebp, %ebp
movq %r14, %rdi
leaq 0xb97(%rip), %rsi       # 0x3215
callq 0x2100
jmp 0x2694
leaq 0xb80(%rip), %rsi       # 0x320c
movq %r14, %rdi
callq 0x2100
incl %ebx
jmp 0x25ce
movq 0x294e(%rip), %rdi      # 0x4ff0
leaq 0xace(%rip), %rsi       # 0x3177
callq 0x2100
leaq 0x60(%rsp), %rsi
movq %rax, %rdi
callq 0x20f0
leaq 0xacc(%rip), %rsi       # 0x318e
movq %rax, %rdi
callq 0x2100
movq %rax, %rdi
callq 0x2090
pushq $0x1
popq %rbx
jmp 0x28ae
movq 0x28ef(%rip), %rbx      # 0x4fd0
leaq 0xae3(%rip), %rsi       # 0x31cb
movq %rbx, %rdi
callq 0x2100
leaq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x20f0
leaq 0xadc(%rip), %rsi       # 0x31e0
movq %rax, %rdi
callq 0x2100
movq (%rbx), %rax
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, 0x18(%rbx,%rax)
pushq $0x30
popq %rsi
movq %rbx, %rdi
callq 0x2160
movq 0x289d(%rip), %rdi      # 0x4fd0
leaq 0xaab(%rip), %rsi       # 0x31e5
callq 0x2100
xorl %ebx, %ebx
leaq 0xa0(%rsp), %r14
leaq 0x40(%rsp), %r15
movq 0x287b(%rip), %r12      # 0x4fd0
leaq 0xa92(%rip), %r13       # 0x31ee
leaq 0xa8e(%rip), %rbp       # 0x31f1
movq %r14, %rdi
movq %r15, %rsi
callq 0x2140
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2817
testb $0xf, %bl
leaq 0xa62(%rip), %rsi       # 0x31ec
leaq 0xa58(%rip), %rax       # 0x31e9
cmoveq %rax, %rsi
movq %r12, %rdi
callq 0x2100
movq %r12, %rdi
movq %r13, %rsi
callq 0x2100
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0x2, 0x10(%rax,%rcx)
movzbl 0x40(%rsp), %esi
movq %rax, %rdi
callq 0x20b0
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2100
incl %ebx
testb $0xf, %bl
jne 0x2763
movq %r12, %rdi
leaq 0x9e8(%rip), %rsi       # 0x31c9
callq 0x2100
jmp 0x2763
testl %ebp, %ebp
je 0x2802
movq 0x27da(%rip), %rdi      # 0x4fd0
leaq 0xa1a(%rip), %rsi       # 0x3217
callq 0x2100
movq 0x27c7(%rip), %rdi      # 0x4fd0
leaq 0x9e4(%rip), %rsi       # 0x31f4
callq 0x2100
jmp 0x2842
testb $0xf, %bl
je 0x282f
movq 0x27ad(%rip), %rdi      # 0x4fd0
leaq 0x99f(%rip), %rsi       # 0x31c9
callq 0x2100
movq 0x279a(%rip), %rdi      # 0x4fd0
leaq 0x9b6(%rip), %rsi       # 0x31f3
callq 0x2100
movq 0x2787(%rip), %rdi      # 0x4fd0
leaq 0x9cd(%rip), %rsi       # 0x321d
callq 0x2100
leaq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x20f0
leaq 0x9c0(%rip), %rsi       # 0x3229
movq %rax, %rdi
callq 0x2100
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
movl %ebx, %esi
callq 0x2170
leaq 0x95d(%rip), %rsi       # 0x31f4
movq %rax, %rdi
callq 0x2100
xorl %ebx, %ebx
leaq 0xa0(%rsp), %rdi
callq 0x2030
leaq 0xa0(%rsp), %rdi
callq 0x2050
leaq 0x20(%rsp), %rdi
callq 0x2080
leaq 0x60(%rsp), %rdi
callq 0x2080
movl %ebx, %eax
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x28e7
jmp 0x290b
movq %rax, %rbx
jmp 0x292d
movq %rax, %rbx
jmp 0x2937
jmp 0x290b
jmp 0x290b
jmp 0x291d
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x2080
jmp 0x2920
jmp 0x291d
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x2050
jmp 0x292d
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x2080
leaq 0x20(%rsp), %rdi
callq 0x2080
leaq 0x60(%rsp), %rdi
callq 0x2080
movq %rbx, %rdi
callq 0x2180
nop