// File: /workspace/github_cpp_makefile_star2_O3/corecodec[P]coremake/coremake.c
// Function: main
int main(int argc, char** argv)
{
	int n;
	int dumppost = 0;
	int dump = 0;
	item* i;
	char path[MAX_PATH];
	char root_forced = 0;

	item* root = item_get(NULL,"ROOT",0);
	getconfig(root);

    getcwd(proj_root,sizeof(proj_root));
    pathunix(proj_root);
    addendpath(proj_root);
    proj_root_len = strlen(proj_root);

	for (n=1;n<argc;++n)
	{
		if (argv[n][0]=='-')
		{
			switch (argv[n][1])
			{
			case 'v':
				verbose = 1;
				break;
			case 'h':
				usage();
				return 0;
			case 'd':
				dump = 1;
				break;
			case 'p':
				dumppost = 1;
				break;
			case 'f':
				strcpy(proj,argv[++n]);
				root_forced = 1;
				break;
            case 'r':
                strcpy(src_root,argv[++n]);
                pathunix(src_root);
                if (!ispathabs(src_root))
                {
                    strins(src_root,proj_root,NULL);
                    simplifypath(src_root,0);
                }
                addendpath(src_root);
                src_root_len = strlen(src_root);
                break;
			}
		}
		else
		if (platform[0]==0)
			strcpy(platform,argv[n]);
	}

	strcpy(path,src_root);
    addendpath(path);
	strcat(path,proj);

    if (!src_root_len)
    {
        strcpy(src_root, proj_root);
        src_root_len = proj_root_len;
    }

    if (!load_file(root,path,FLAG_PATH_SOURCE,NULL) && !root_forced)
	{
        // try <directory>.proj
		strcpy(proj,src_root);
        delendpath(proj);
        truncfilename(proj);
		strcat(proj,".proj");
        strins(proj,src_root,NULL);
		if (!load_file(root,proj,FLAG_PATH_SOURCE,NULL))
        {
            // search for *.proj
			DIR* dir = opendir(src_root);
			if (dir)
			{
                int found = 0;
				struct dirent* entry;
				while ((entry = readdir(dir)) != NULL)
					if (entry->d_name[0]!='.' && strrchr(entry->d_name,'.') &&
                        stricmp(strrchr(entry->d_name,'.'),".proj")==0 && load_file(root,entry->d_name,FLAG_PATH_SOURCE,NULL))
                    {
                        found = 1;
                        strcpy(proj,entry->d_name);
                        pathunix(proj);
                        truncfilename(proj);
                        break;
                    }

				closedir(dir);
                if (!found)
                {
                    printf("No root .proj file found !");
                    exit(1);
                }
			}
        }
	}

    if (!getvalue(item_find(root,"workspace")))
    {
        // add default workspace
        item* w = item_get(root,"workspace",0);
        item* i = NULL;
        i=default_workspace(w,i,item_find(root,"exe"));
        i=default_workspace(w,i,item_find(root,"dll"));
        i=default_workspace(w,i,item_find(root,"con"));
        i=default_workspace(w,i,item_find(root,"exe_android"));
    }

	preprocess_project(item_find(root,"project"));

	if (dump)
		dumpitem(root,1);

	if (!platform[0])
	{
		if (!dump)
			usage();
		return 1;
	}

	item_get(item_get(root,"platformname",1),platform,1);

    i = item_get(root,"rootpath",1);
	i = item_get(i,src_root,1);
    set_path_type(i,FLAG_PATH_SOURCE);

    i = item_get(root,"builddir",1);
	i = item_get(i,proj_root,1);
    set_path_type(i,FLAG_PATH_GENERATED);

	sprintf(path,"%srelease/%s/",proj_root,platform);
    i = item_get(root,"outputpath",1);
	i = item_get(i,path,1);
    set_path_type(i,FLAG_PATH_GENERATED);

	sprintf(path,"%sbuild/%s/",proj_root,platform);
    i = item_get(root,"buildpath",1);
	i = item_get(i,path,1);
    set_path_type(i,FLAG_PATH_GENERATED);

	i = getvalue(getroot(root,"platform_files"));
	if (i)
	{
		if (ispathabs(i->value) || !ispathabs(src_root))
			strcpy(coremake_root,i->value);
		else
		{
			strcpy(coremake_root,src_root);
			strcat(coremake_root,i->value);
		}
		simplifypath(coremake_root,1);
	}
	else
    {
#ifdef _WIN32
        HMODULE this1 = GetModuleHandleA("coremake.exe");
        if (this1)
        {
            GetModuleFileNameA(this1,coremake_root,MAX_PATH);
            FreeLibrary(this1);
            pathunix(coremake_root);
            getfilename(coremake_root)[0] = 0;
            strcat(coremake_root,"coremake");
        }
#else
        /// \todo this shouldn't work on UNIX platforms
        ///       since the platform files should be in a dir like /usr/share
        ///       and the argv most likely doesn't contain the path to the exe
        ///       We probably need a --prefix during compilation to hardcode that /usr/share path
        strcpy(coremake_root,"/usr/local/share/coremake");
#endif
        i = item_get(root,"platform_files",1);
        i = item_get(i,coremake_root,1);
        set_path_type(i,FLAG_PATH_COREMAKE);
        strcpy(coremake_root,i->value);
    }
	addendpath(coremake_root);
    coremake_root_len = strlen(coremake_root);

    strcpy(path,coremake_root);
	strcat(path,platform);
	strcat(path,".build");

	strcpy(buildpath[0],proj_root); //safety
    buildflags[0] = FLAG_PATH_GENERATED;
	build = NULL;
	build_file(root,path,FLAG_PATH_COREMAKE);
	if (build)
	{
		fclose(build);
		file_finalize(buildpath[curr_build]);
	}

	if (dumppost)
		dumpitem(root,1);

	item_delete(root);
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %rsi, %r14
movl %edi, %ebp
leaq 0x1d4e(%rip), %rsi      # 0x12456
xorl %edi, %edi
xorl %edx, %edx
callq 0x270b
movq %rax, %rbx
movq %rax, %rdi
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x10714
leaq 0x9aa(%rip), %rsi       # 0x110d1
xorl %edx, %edx
callq 0x270b
leaq 0x62cb(%rip), %r15      # 0x16a00
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdi
callq 0x2180
movzbl (%r15), %eax
cmpl $0x5c, %eax
je 0x10751
testl %eax, %eax
jne 0x10755
jmp 0x1075a
movb $0x2f, (%r15)
incq %r15
jmp 0x10742
leaq 0x629f(%rip), %r15      # 0x16a00
movq %r15, %rdi
callq 0x3dcf
movq %r15, %rdi
callq 0x2120
movq %rax, 0x6a90(%rip)      # 0x17208
xorl %r15d, %r15d
cmpl $0x2, %ebp
jl 0x10916
movq %rbx, 0x18(%rsp)
movl $0x1, %r12d
leaq 0x8b2(%rip), %rbx       # 0x11048
leaq 0x5a33(%rip), %r13      # 0x161d0
movl $0x0, 0xc(%rsp)
movl $0x0, 0x10(%rsp)
movslq %r12d, %rax
movq (%r14,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x107e1
movsbl 0x1(%rsi), %ecx
addl $-0x64, %ecx
rorl %ecx
cmpl $0x9, %ecx
ja 0x108e8
movslq (%rbx,%rcx,4), %rcx
addq %rbx, %rcx
jmpq *%rcx
movl $0x1, 0xc(%rsp)
jmp 0x108e8
cmpb $0x0, 0x6a38(%rip)      # 0x17220
jne 0x108e8
leaq 0x6a2b(%rip), %rdi      # 0x17220
callq 0x20b0
jmp 0x108e8
movl $0x1, 0x5de7(%rip)      # 0x165f0
jmp 0x108e8
leal 0x1(%rax), %r12d
movq 0x8(%r14,%rax,8), %rsi
movq %r13, %rdi
callq 0x20b0
movb $0x1, %al
movl %eax, 0x10(%rsp)
jmp 0x108e8
leal 0x1(%rax), %r12d
movq 0x8(%r14,%rax,8), %rsi
leaq 0x5dc6(%rip), %rdi      # 0x16600
callq 0x20b0
leaq 0x5dba(%rip), %rbx      # 0x16600
movq %rbx, %rax
movzbl (%rax), %ecx
cmpl $0x5c, %ecx
je 0x10857
testl %ecx, %ecx
jne 0x1085a
jmp 0x1085f
movb $0x2f, (%rax)
incq %rax
jmp 0x10849
movq %rbx, %rdi
callq 0x3ff4
testl %eax, %eax
jne 0x108c2
leaq 0x618e(%rip), %rdi      # 0x16a00
callq 0x2120
movl %r15d, 0x14(%rsp)
movq %rax, %r15
leaq (%rbx,%rax), %r13
movq %rbx, %rdi
callq 0x2120
leaq 0x1(%rax), %rdx
movq %r13, %rdi
leaq 0x5937(%rip), %r13      # 0x161d0
movq %rbx, %rsi
callq 0x22c0
movq %rbx, %rdi
leaq 0x6155(%rip), %rsi      # 0x16a00
movq %r15, %rdx
movl 0x14(%rsp), %r15d
callq 0x2240
movq %rbx, %rdi
xorl %esi, %esi
callq 0x43fb
movq %rbx, %rdi
callq 0x3dcf
movq %rbx, %rdi
callq 0x2120
movq %rax, 0x6927(%rip)      # 0x17200
leaq 0x768(%rip), %rbx       # 0x11048
jmp 0x108e8
movl $0x1, %r15d
incl %r12d
cmpl %ebp, %r12d
jl 0x107ad
cmpb $0x0, 0x10(%rsp)
setne %al
cmpl $0x0, 0xc(%rsp)
sete %r12b
testl %r15d, %r15d
sete %r13b
movl %eax, %r15d
movq 0x18(%rsp), %rbx
jmp 0x1091c
movb $0x1, %r12b
movb $0x1, %r13b
leaq 0x5cdd(%rip), %rsi      # 0x16600
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x20b0
movq %r14, %rdi
callq 0x3dcf
leaq 0x5891(%rip), %rsi      # 0x161d0
movq %r14, %rdi
callq 0x2300
cmpq $0x0, 0x68b1(%rip)      # 0x17200
jne 0x10972
leaq 0x5ca8(%rip), %rdi      # 0x16600
leaq 0x60a1(%rip), %rsi      # 0x16a00
callq 0x20b0
movq 0x689d(%rip), %rax      # 0x17208
movq %rax, 0x688e(%rip)      # 0x17200
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x5afd
testl %eax, %eax
setne %al
orb %r15b, %al
testb $0x1, %al
jne 0x10b31
movb %r12b, 0xc(%rsp)
movl %r13d, %ebp
leaq 0x582b(%rip), %r14      # 0x161d0
leaq 0x5c54(%rip), %rsi      # 0x16600
movq %r14, %rdi
callq 0x20b0
cmpb $0x0, 0x5815(%rip)      # 0x161d0
je 0x109d3
movq %r14, %rdi
callq 0x2120
cmpb $0x2f, -0x1(%rax,%r14)
jne 0x109d3
movb $0x0, -0x1(%rax,%r14)
movq %r14, %rdi
callq 0x3c01
movq %r14, %rdi
callq 0x2120
movl $0x6f72702e, (%rax,%r14) # imm = 0x6F72702E
movw $0x6a, 0x4(%rax,%r14)
leaq 0x5c06(%rip), %r15      # 0x16600
movq %r15, %rdi
callq 0x2120
movq %rax, %r12
leaq (%r14,%rax), %r13
movq %r14, %rdi
callq 0x2120
leaq 0x1(%rax), %rdx
movq %r13, %rdi
movq %r14, %rsi
callq 0x22c0
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2240
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x5afd
testl %eax, %eax
movl %ebp, %r13d
movb 0xc(%rsp), %r12b
jne 0x10b31
leaq 0x5ba9(%rip), %rdi      # 0x16600
callq 0x2100
testq %rax, %rax
je 0x10b31
movq %rax, %r15
movq %rax, %rdi
callq 0x2250
testq %rax, %rax
je 0x10ad2
movq %rax, %r12
leaq 0x817(%rip), %r13       # 0x11296
cmpb $0x2e, 0x13(%r12)
je 0x10ac2
addq $0x13, %r12
movq %r12, %rdi
movl $0x2e, %esi
callq 0x2150
testq %rax, %rax
je 0x10ac2
movq %rax, %rdi
movq %r13, %rsi
callq 0x2070
testl %eax, %eax
jne 0x10ac2
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x5afd
testl %eax, %eax
jne 0x10af2
movq %r15, %rdi
callq 0x2250
movq %rax, %r12
testq %rax, %rax
jne 0x10a7f
movq %r15, %rdi
callq 0x2190
leaq 0x197a(%rip), %rdi      # 0x1245b
xorl %eax, %eax
callq 0x2140
movl $0x1, %edi
callq 0x2320
movq %r14, %rdi
movq %r12, %rsi
callq 0x20b0
movl %ebp, %r13d
movb 0xc(%rsp), %r12b
movzbl (%r14), %eax
cmpl $0x5c, %eax
je 0x10b14
testl %eax, %eax
jne 0x10b18
jmp 0x10b1d
movb $0x2f, (%r14)
incq %r14
jmp 0x10b05
leaq 0x56ac(%rip), %rdi      # 0x161d0
callq 0x3c01
movq %r15, %rdi
callq 0x2190
leaq 0x786(%rip), %rsi       # 0x112be
movq %rbx, %rdi
callq 0x2694
testq %rax, %rax
je 0x10b65
movq 0x18(%rax), %rcx
movq 0x20(%rax), %rax
cmpq %rax, %rcx
je 0x10b65
movq (%rcx), %rdx
testb $0x40, 0x30(%rdx)
je 0x10bf5
addq $0x8, %rcx
jmp 0x10b4d
leaq 0x752(%rip), %rsi       # 0x112be
movq %rbx, %rdi
xorl %edx, %edx
callq 0x270b
movq %rax, %r14
leaq 0x159e(%rip), %rsi      # 0x1211e
movq %rbx, %rdi
callq 0x2694
movq %r14, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x1065a
movq %rax, %r15
leaq 0x15de(%rip), %rsi      # 0x1217d
movq %rbx, %rdi
callq 0x2694
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1065a
movq %rax, %r15
leaq 0x15b3(%rip), %rsi      # 0x12172
movq %rbx, %rdi
callq 0x2694
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1065a
movq %rax, %r15
leaq 0x550(%rip), %rsi       # 0x1112f
movq %rbx, %rdi
callq 0x2694
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x1065a
leaq 0x9cf(%rip), %rsi       # 0x115cb
movq %rbx, %rdi
callq 0x2694
movq %rax, %rdi
callq 0xaf12
testb %r12b, %r12b
je 0x10c29
cmpb $0x0, 0x6608(%rip)      # 0x17220
jne 0x10c48
callq 0x5e43
movl $0x1, %ebp
jmp 0x10ee6
movl $0x1, %ebp
movq %rbx, %rdi
movl $0x1, %esi
callq 0x5daf
cmpb $0x0, 0x65de(%rip)      # 0x17220
je 0x10ee6
leaq 0x1827(%rip), %rsi      # 0x12476
movq %rbx, %rdi
movl $0x1, %edx
callq 0x270b
leaq 0x65bd(%rip), %r14      # 0x17220
movq %rax, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x270b
leaq 0x1809(%rip), %rsi      # 0x12483
movq %rbx, %rdi
movl $0x1, %edx
callq 0x270b
leaq 0x5972(%rip), %rsi      # 0x16600
movq %rax, %rdi
movl $0x1, %edx
callq 0x270b
movl 0x30(%rax), %ecx
andl $-0x10, %ecx
incl %ecx
movl %ecx, 0x30(%rax)
leaq 0x17df(%rip), %rsi      # 0x1248c
movq %rbx, %rdi
movl $0x1, %edx
callq 0x270b
leaq 0x5d3f(%rip), %r15      # 0x16a00
movq %rax, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x270b
movl 0x30(%rax), %ecx
andl $-0x10, %ecx
orl $0x2, %ecx
movl %ecx, 0x30(%rax)
leaq 0x17b1(%rip), %rsi      # 0x12495
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x2310
leaq 0x97d(%rip), %rsi       # 0x1167d
movq %rbx, %rdi
movl $0x1, %edx
callq 0x270b
movq %rax, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x270b
movl 0x30(%rax), %ecx
andl $-0x10, %ecx
orl $0x2, %ecx
movl %ecx, 0x30(%rax)
leaq 0x1773(%rip), %rsi      # 0x124a3
movq %r12, %rdi
movq %r15, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x2310
leaq 0x1768(%rip), %rsi      # 0x124af
movq %rbx, %rdi
movl $0x1, %edx
callq 0x270b
movq %rax, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x270b
movl 0x30(%rax), %ecx
andl $-0x10, %ecx
orl $0x2, %ecx
movl %ecx, 0x30(%rax)
movq %rbx, %r15
movq %rbx, %rdi
movq 0x10(%rbx), %rbx
testq %rbx, %rbx
jne 0x10d73
leaq 0x57c(%rip), %rsi       # 0x11302
xorl %edx, %edx
callq 0x270b
testq %rax, %rax
je 0x10db2
movq 0x18(%rax), %rcx
movq 0x20(%rax), %rax
cmpq %rax, %rcx
je 0x10db2
movq (%rcx), %rbx
testb $0x40, 0x30(%rbx)
je 0x10efa
addq $0x8, %rcx
jmp 0x10d9a
movups 0x170a(%rip), %xmm0     # 0x124c3
movups %xmm0, 0x604a(%rip)     # 0x16e0a
movups 0x16f2(%rip), %xmm0     # 0x124b9
movaps %xmm0, 0x6032(%rip)     # 0x16e00
leaq 0x602b(%rip), %r14      # 0x16e00
leaq 0x526(%rip), %rsi       # 0x11302
movq %r15, %rbx
movq %r15, %rdi
movl $0x1, %edx
callq 0x270b
movq %rax, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x270b
movl 0x30(%rax), %ecx
andl $-0x10, %ecx
orl $0x3, %ecx
movl %ecx, 0x30(%rax)
movq (%rax), %rsi
movq %r14, %rdi
callq 0x20b0
leaq 0x5fe6(%rip), %r14      # 0x16e00
movq %r14, %rdi
callq 0x3dcf
movq %r14, %rdi
callq 0x2120
movq %rax, 0x63df(%rip)      # 0x17210
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x20b0
leaq 0x63d8(%rip), %rsi      # 0x17220
movq %r15, %rdi
callq 0x2300
movq %r15, %rdi
callq 0x2120
movl $0x6975622e, 0x20(%rsp,%rax) # imm = 0x6975622E
movl $0x646c69, 0x23(%rsp,%rax) # imm = 0x646C69
leaq 0x67c1(%rip), %r14      # 0x17630
leaq 0x5b8a(%rip), %rsi      # 0x16a00
movq %r14, %rdi
callq 0x20b0
movl $0x2, 0x87a8(%rip)      # 0x19630
movq $0x0, 0x87bd(%rip) # 0x19650
movq %rbx, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq 0x10589
movq 0x87a6(%rip), %rdi      # 0x19650
testq %rdi, %rdi
je 0x10eca
callq 0x20f0
movslq 0x6765(%rip), %rax      # 0x17620
shlq $0xa, %rax
addq %rax, %r14
movq %r14, %rdi
callq 0x61be
testb %r13b, %r13b
jne 0x10edc
movq %rbx, %rdi
movl $0x1, %esi
callq 0x5daf
movq %rbx, %rdi
callq 0x2d5b
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %r14
movq %r14, %rdi
callq 0x3ff4
testl %eax, %eax
je 0x10f1a
leaq 0x5ef0(%rip), %rdi      # 0x16e00
movq %r14, %rsi
callq 0x20b0
jmp 0x10f4b
leaq 0x56df(%rip), %rdi      # 0x16600
callq 0x3ff4
testl %eax, %eax
je 0x10f09
leaq 0x5ecf(%rip), %r14      # 0x16e00
leaq 0x56c8(%rip), %rsi      # 0x16600
movq %r14, %rdi
callq 0x20b0
movq (%rbx), %rsi
movq %r14, %rdi
callq 0x2300
movq %r15, %rbx
leaq 0x5eab(%rip), %rdi      # 0x16e00
movl $0x1, %esi
callq 0x43fb
jmp 0x10e13
callq 0x5e43
jmp 0x10ee4