// File: /workspace/github_cpp_makefile_star2_O2/corecodec[P]coremake/corerc.c
// Function: main
int main(int argc, char** argv)
{
    FILE *f = NULL;
    FILE *e = stdout;
    char filename[256];
    char varname[256];
    char name[256];
    char align[32];
    int writeable=0;
    int corec=0;
    int n;
    
    if (argc<=1)
    {
        printf("usage: %s [-a <num>] [-w] [-corec] [-n <name>] <infile.bin> [<outfile.c>]\n",argv[0]);
        return 1;
    }

    align[0]=0;
    varname[0]=0;

    for (n=1;n<argc;++n)
    {
        if (argv[n][0]=='-')
        {
            if (argv[n][1]=='c')
                corec=1;
            else
            if (argv[n][1]=='w')
                writeable = 1;
            else
            if (argv[n][1]=='a')
                sprintf(align,"__attribute__((aligned(%d)))",atoi(argv[++n]));
            else
            if (argv[n][1]=='n')
                strcpy(varname,argv[++n]);
        }
        else
        {
            if (!f)
            {
                strcpy(name,argv[n]);
                f = fopen(argv[n],"rb");
                if (!f)
                    return 1;
            }
            else
            {
                e = fopen(argv[n],"w+");
            }
        }
    }

    pathunix(name);
    strcpy(filename,getfilename(name));
    truncfilename(name);

    if (!varname[0])
        strcpy(varname,name);

    fprintf(f,"/* DO NOT EDIT, FILE GENERATED BY CORERC */\n\n");

    if (corec)
    {
        fprintf(e,"#include \"resource/resource.h\"\n\n");
        fprintf(e,"static %s uint8_t Data[] %s = {",writeable?"":"const",align);
    }
    else
    {
        fseek(f,0,SEEK_END);
        fprintf(e,"%s int %s_size = %d;\n",writeable?"":"const",varname,(int)ftell(f));
        fseek(f,0,SEEK_SET);
        fprintf(e,"%s char %s[] %s = {",writeable?"":"const",varname,align);
    }

    for (n=0;;++n)
    {
        int ch = fgetc(f);
        if (feof(f))
            break;

        if (n)
            fprintf(e,",");
        if ((n%32)==0)
            fprintf(e,"\n");
        fprintf(e,"0x%02X",(unsigned char)ch);
    }

    fprintf(e,"};\n\n");

    if (corec)
    {
        fprintf(e,"META_START(Resource_%s_Class,0)\n"
                  "META_PARAM(STRING,NODE_NAME,T(\"%s\"))\n"
                  "META_PARAM(CUSTOM,RESOURCEDATA_SIZE,sizeof(Data))\n"
                  "META_PARAM(CUSTOM,RESOURCEDATA_PTR,Data)\n"
                  "META_END(RESOURCEDATA_ID)\n",name,filename);
    }

    fclose(f);
    if (e != stdout)
        fclose(e);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x338, %rsp            # imm = 0x338
movq %rsi, %r15
cmpl $0x1, %edi
jg 0x12d2
movq (%r15), %rsi
leaq 0xd41(%rip), %rdi       # 0x2004
xorl %eax, %eax
callq 0x1060
pushq $0x1
popq %rbp
jmp 0x158e
movl %edi, %r12d
movq 0x2d04(%rip), %rax      # 0x3fe0
movq (%rax), %rbx
xorl %eax, %eax
leaq 0x10(%rsp), %rcx
movb %al, (%rcx)
leaq 0x30(%rsp), %rcx
movb %al, (%rcx)
pushq $0x1
popq %rbp
xorl %r14d, %r14d
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
cmpl %r12d, %ebp
jge 0x13d2
movslq %ebp, %rax
movq (%r15,%rax,8), %r13
cmpb $0x2d, (%r13)
jne 0x1349
movzbl 0x1(%r13), %ecx
cmpl $0x61, %ecx
je 0x13aa
cmpl $0x63, %ecx
je 0x138e
cmpl $0x6e, %ecx
je 0x1397
cmpl $0x77, %ecx
jne 0x13cb
pushq $0x1
popq %rax
movl %eax, 0xc(%rsp)
jmp 0x13cb
testq %r14, %r14
je 0x1362
movq %r13, %rdi
leaq 0xd17(%rip), %rsi       # 0x206f
callq 0x10f0
movq %rax, %rbx
jmp 0x13cb
leaq 0x130(%rsp), %rdi
movq %r13, %rsi
callq 0x1030
movq %r13, %rdi
leaq 0xcf0(%rip), %rsi       # 0x206c
callq 0x10f0
movq %rax, %r14
testq %rax, %rax
jne 0x13cb
jmp 0x12ca
pushq $0x1
popq %rax
movl %eax, 0x8(%rsp)
jmp 0x13cb
incl %ebp
movq 0x8(%r15,%rax,8), %rsi
leaq 0x30(%rsp), %rdi
callq 0x1030
jmp 0x13cb
incl %ebp
movq 0x8(%r15,%rax,8), %rdi
callq 0x1100
leaq 0x10(%rsp), %rdi
leaq 0xc8d(%rip), %rsi       # 0x204f
movl %eax, %edx
xorl %eax, %eax
callq 0x1110
incl %ebp
jmp 0x1305
leaq 0x130(%rsp), %r15
movq %r15, %rdi
callq 0x122c
movq %r15, %rdi
callq 0x1243
leaq 0x230(%rsp), %rdi
movq %rax, %rsi
callq 0x1030
movq %r15, %rdi
callq 0x125f
cmpb $0x0, 0x30(%rsp)
jne 0x141b
leaq 0x30(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x1030
leaq 0xc50(%rip), %rdi       # 0x2072
pushq $0x2d
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x1120
cmpl $0x0, 0xc(%rsp)
leaq 0xca5(%rip), %rax       # 0x20e1
leaq 0xc7d(%rip), %r15       # 0x20c0
cmoveq %rax, %r15
cmpl $0x0, 0x8(%rsp)
je 0x147e
leaq 0xc4b(%rip), %rdi       # 0x20a0
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x1120
leaq 0xc57(%rip), %rsi       # 0x20c1
leaq 0x10(%rsp), %rcx
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x10a0
jmp 0x14da
pushq $0x2
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x10d0
movq %r14, %rdi
callq 0x10b0
leaq 0xc4d(%rip), %rsi       # 0x20e7
leaq 0x30(%rsp), %r12
movq %rbx, %rdi
movq %r15, %rdx
movq %r12, %rcx
movl %eax, %r8d
xorl %eax, %eax
callq 0x10a0
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x10d0
leaq 0xc38(%rip), %rsi       # 0x20fd
leaq 0x10(%rsp), %r8
movq %rbx, %rdi
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x10a0
leaq 0xc30(%rip), %r15       # 0x2111
pushq $0x2c
popq %r12
xorl %ebp, %ebp
movq %r14, %rdi
callq 0x1080
movl %eax, %r13d
movq %r14, %rdi
callq 0x10c0
testl %eax, %eax
jne 0x1533
testl %ebp, %ebp
je 0x1513
movl %r12d, %edi
movq %rbx, %rsi
callq 0x1090
testb $0x1f, %bpl
jne 0x151e
pushq $0xa
popq %rdi
movq %rbx, %rsi
callq 0x1090
movzbl %r13b, %edx
movq %rbx, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x10a0
incl %ebp
jmp 0x14e7
leaq 0xbde(%rip), %rdi       # 0x2118
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x1120
cmpl $0x0, 0x8(%rsp)
je 0x1570
leaq 0xbc7(%rip), %rsi       # 0x211d
leaq 0x130(%rsp), %rdx
leaq 0x230(%rsp), %rcx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x10a0
movq %r14, %rdi
callq 0x1040
xorl %ebp, %ebp
movq 0x2a5f(%rip), %rax      # 0x3fe0
cmpq (%rax), %rbx
je 0x158e
movq %rbx, %rdi
callq 0x1040
movl %ebp, %eax
addq $0x338, %rsp            # imm = 0x338
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq