// File: /workspace/github_cpp_makefile_star2_O3/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 $0x348, %rsp            # imm = 0x348
movq %rsi, %r12
cmpl $0x1, %edi
jg 0x12e6
movq (%r12), %rsi
leaq 0xd2f(%rip), %rdi       # 0x2004
xorl %eax, %eax
callq 0x1060
movl $0x1, %ebp
jmp 0x15f7
movl %edi, %ebp
movq 0x2cf1(%rip), %rax      # 0x3fe0
movq (%rax), %rax
movq %rax, 0x10(%rsp)
xorl %eax, %eax
leaq 0x20(%rsp), %rcx
movb %al, (%rcx)
leaq 0x40(%rsp), %rcx
movb %al, (%rcx)
movl $0x1, %ebx
leaq 0x140(%rsp), %r15
movl $0x0, 0xc(%rsp)
movl $0x0, 0x1c(%rsp)
xorl %r14d, %r14d
movslq %ebx, %rax
movq (%r12,%rax,8), %r13
cmpb $0x2d, (%r13)
jne 0x135a
movzbl 0x1(%r13), %ecx
cmpl $0x6d, %ecx
jg 0x1375
cmpl $0x61, %ecx
je 0x13b0
cmpl $0x63, %ecx
jne 0x13e6
movl $0x1, 0xc(%rsp)
jmp 0x13e6
testq %r14, %r14
je 0x1389
movq %r13, %rdi
leaq 0xd06(%rip), %rsi       # 0x206f
callq 0x10f0
movq %rax, 0x10(%rsp)
jmp 0x13e6
cmpl $0x6e, %ecx
je 0x13d4
cmpl $0x77, %ecx
jne 0x13e6
movl $0x1, 0x1c(%rsp)
jmp 0x13e6
movq %r15, %rdi
movq %r13, %rsi
callq 0x1030
movq %r13, %rdi
leaq 0xcce(%rip), %rsi       # 0x206c
callq 0x10f0
movq %rax, %r14
testq %rax, %rax
jne 0x13e6
jmp 0x12dc
leal 0x1(%rax), %ebx
movq 0x8(%r12,%rax,8), %rdi
callq 0x1100
leaq 0x20(%rsp), %rdi
leaq 0xc86(%rip), %rsi       # 0x204f
movl %eax, %edx
xorl %eax, %eax
callq 0x1110
jmp 0x13e6
leal 0x1(%rax), %ebx
movq 0x8(%r12,%rax,8), %rsi
leaq 0x40(%rsp), %rdi
callq 0x1030
incl %ebx
cmpl %ebp, %ebx
jl 0x1327
movq 0x10(%rsp), %r12
movzbl (%r15), %eax
cmpl $0x5c, %eax
je 0x1404
testl %eax, %eax
jne 0x1408
jmp 0x140d
movb $0x2f, (%r15)
incq %r15
jmp 0x13f5
leaq 0x140(%rsp), %r15
movq %r15, %rdi
movl $0x2f, %esi
callq 0x1070
leaq 0x1(%rax), %rsi
testq %rax, %rax
cmoveq %r15, %rsi
leaq 0x240(%rsp), %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1261
cmpb $0x0, 0x40(%rsp)
jne 0x145b
leaq 0x40(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x1030
leaq 0xc10(%rip), %rdi       # 0x2072
movl $0x2d, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x1120
cmpl $0x0, 0x1c(%rsp)
leaq 0xc61(%rip), %rax       # 0x20e1
leaq 0xc39(%rip), %r15       # 0x20c0
cmoveq %rax, %r15
cmpl $0x0, 0xc(%rsp)
je 0x14c6
leaq 0xc07(%rip), %rdi       # 0x20a0
movl $0x20, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x1120
leaq 0xc0f(%rip), %rsi       # 0x20c1
leaq 0x20(%rsp), %rcx
movq %r12, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x10a0
jmp 0x152d
movq %r14, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x10d0
movq %r14, %rdi
callq 0x10b0
leaq 0xc03(%rip), %rsi       # 0x20e7
leaq 0x40(%rsp), %r12
movq 0x10(%rsp), %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 0xbec(%rip), %rsi       # 0x20fd
leaq 0x20(%rsp), %r8
movq 0x10(%rsp), %rdi
movq %r15, %rdx
movq %r12, %rcx
movq 0x10(%rsp), %r12
xorl %eax, %eax
callq 0x10a0
movq %r14, %rdi
callq 0x1080
movl %eax, %ebp
movq %r14, %rdi
callq 0x10c0
testl %eax, %eax
jne 0x1598
leaq 0xbc7(%rip), %r15       # 0x2111
xorl %ebx, %ebx
testl %ebx, %ebx
je 0x1562
movl $0x2c, %edi
movq %r12, %rsi
callq 0x1090
testb $0x1f, %bl
jne 0x156f
movl $0xa, %edi
movq %r12, %rsi
callq 0x1090
movzbl %bpl, %edx
movq %r12, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x10a0
incl %ebx
movq %r14, %rdi
callq 0x1080
movl %eax, %ebp
movq %r14, %rdi
callq 0x10c0
testl %eax, %eax
je 0x154c
leaq 0xb79(%rip), %rdi       # 0x2118
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x1120
cmpl $0x0, 0xc(%rsp)
je 0x15d9
leaq 0xb5e(%rip), %rsi       # 0x211d
leaq 0x140(%rsp), %rdx
leaq 0x240(%rsp), %rcx
movq %r12, %rdi
xorl %eax, %eax
callq 0x10a0
movq %r14, %rdi
callq 0x1040
xorl %ebp, %ebp
movq 0x29f6(%rip), %rax      # 0x3fe0
cmpq (%rax), %r12
je 0x15f7
movq %r12, %rdi
callq 0x1040
movl %ebp, %eax
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq