// File: /workspace/github_cpp_makefile_star2_O1/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 0x2a9d(%rip), %rsi      # 0x1345b
xorl %edi, %edi
xorl %edx, %edx
callq 0x2745
movq %rax, %rbx
movq %rax, %rdi
movq 0x10(%rax), %rax
testq %rax, %rax
jne 0x109ca
leaq 0x16f4(%rip), %rsi      # 0x120d1
xorl %edx, %edx
callq 0x2745
leaq 0x7015(%rip), %r15      # 0x17a00
movl $0x400, %esi            # imm = 0x400
movq %r15, %rdi
callq 0x2190
movzbl (%r15), %eax
cmpl $0x5c, %eax
je 0x10a07
testl %eax, %eax
jne 0x10a0b
jmp 0x10a10
movb $0x2f, (%r15)
incq %r15
jmp 0x109f8
leaq 0x6fe9(%rip), %r15      # 0x17a00
movq %r15, %rdi
callq 0x3df1
movq %r15, %rdi
callq 0x2120
movq %rax, 0x77da(%rip)      # 0x18208
xorl %r15d, %r15d
cmpl $0x2, %ebp
jl 0x10bcc
movq %rbx, 0x18(%rsp)
movl $0x1, %r12d
leaq 0x15fc(%rip), %rbx      # 0x12048
leaq 0x677d(%rip), %r13      # 0x171d0
movl $0x0, 0xc(%rsp)
movl $0x0, 0x10(%rsp)
movslq %r12d, %rax
movq (%r14,%rax,8), %rsi
cmpb $0x2d, (%rsi)
jne 0x10a97
movsbl 0x1(%rsi), %ecx
addl $-0x64, %ecx
rorl %ecx
cmpl $0x9, %ecx
ja 0x10b9e
movslq (%rbx,%rcx,4), %rcx
addq %rbx, %rcx
jmpq *%rcx
movl $0x1, 0xc(%rsp)
jmp 0x10b9e
cmpb $0x0, 0x7782(%rip)      # 0x18220
jne 0x10b9e
leaq 0x7775(%rip), %rdi      # 0x18220
callq 0x20b0
jmp 0x10b9e
movl $0x1, 0x6b31(%rip)      # 0x175f0
jmp 0x10b9e
leal 0x1(%rax), %r12d
movq 0x8(%r14,%rax,8), %rsi
movq %r13, %rdi
callq 0x20b0
movb $0x1, %al
movl %eax, 0x10(%rsp)
jmp 0x10b9e
leal 0x1(%rax), %r12d
movq 0x8(%r14,%rax,8), %rsi
leaq 0x6b10(%rip), %rdi      # 0x17600
callq 0x20b0
leaq 0x6b04(%rip), %rbx      # 0x17600
movq %rbx, %rax
movzbl (%rax), %ecx
cmpl $0x5c, %ecx
je 0x10b0d
testl %ecx, %ecx
jne 0x10b10
jmp 0x10b15
movb $0x2f, (%rax)
incq %rax
jmp 0x10aff
movq %rbx, %rdi
callq 0x4016
testl %eax, %eax
jne 0x10b78
leaq 0x6ed8(%rip), %rdi      # 0x17a00
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 0x6681(%rip), %r13      # 0x171d0
movq %rbx, %rsi
callq 0x22d0
movq %rbx, %rdi
leaq 0x6e9f(%rip), %rsi      # 0x17a00
movq %r15, %rdx
movl 0x14(%rsp), %r15d
callq 0x2240
movq %rbx, %rdi
xorl %esi, %esi
callq 0x437e
movq %rbx, %rdi
callq 0x3df1
movq %rbx, %rdi
callq 0x2120
movq %rax, 0x7671(%rip)      # 0x18200
leaq 0x14b2(%rip), %rbx      # 0x12048
jmp 0x10b9e
movl $0x1, %r15d
incl %r12d
cmpl %ebp, %r12d
jl 0x10a63
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 0x10bd2
movb $0x1, %r12b
movb $0x1, %r13b
leaq 0x6a27(%rip), %rsi      # 0x17600
leaq 0x20(%rsp), %r14
movq %r14, %rdi
callq 0x20b0
movq %r14, %rdi
callq 0x3df1
leaq 0x65db(%rip), %rsi      # 0x171d0
movq %r14, %rdi
callq 0x2310
cmpq $0x0, 0x75fb(%rip)      # 0x18200
jne 0x10c28
leaq 0x69f2(%rip), %rdi      # 0x17600
leaq 0x6deb(%rip), %rsi      # 0x17a00
callq 0x20b0
movq 0x75e7(%rip), %rax      # 0x18208
movq %rax, 0x75d8(%rip)      # 0x18200
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x5ac2
testl %eax, %eax
setne %al
orb %r15b, %al
testb $0x1, %al
jne 0x10de7
movb %r12b, 0xc(%rsp)
movl %r13d, %ebp
leaq 0x6575(%rip), %r14      # 0x171d0
leaq 0x699e(%rip), %rsi      # 0x17600
movq %r14, %rdi
callq 0x20b0
cmpb $0x0, 0x655f(%rip)      # 0x171d0
je 0x10c89
movq %r14, %rdi
callq 0x2120
cmpb $0x2f, -0x1(%rax,%r14)
jne 0x10c89
movb $0x0, -0x1(%rax,%r14)
movq %r14, %rdi
callq 0x3c23
movq %r14, %rdi
callq 0x2120
movl $0x6f72702e, (%rax,%r14) # imm = 0x6F72702E
movw $0x6a, 0x4(%rax,%r14)
leaq 0x6950(%rip), %r15      # 0x17600
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 0x22d0
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2240
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x5ac2
testl %eax, %eax
movl %ebp, %r13d
movb 0xc(%rsp), %r12b
jne 0x10de7
leaq 0x68f3(%rip), %rdi      # 0x17600
callq 0x2100
testq %rax, %rax
je 0x10de7
movq %rax, %r15
movq %rax, %rdi
callq 0x2250
testq %rax, %rax
je 0x10d88
movq %rax, %r12
leaq 0x155f(%rip), %r13      # 0x12294
cmpb $0x2e, 0x13(%r12)
je 0x10d78
addq $0x13, %r12
movq %r12, %rdi
movl $0x2e, %esi
callq 0x2150
testq %rax, %rax
je 0x10d78
movq %rax, %rdi
movq %r13, %rsi
callq 0x2070
testl %eax, %eax
jne 0x10d78
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x5ac2
testl %eax, %eax
jne 0x10da8
movq %r15, %rdi
callq 0x2250
movq %rax, %r12
testq %rax, %rax
jne 0x10d35
movq %r15, %rdi
callq 0x21a0
leaq 0x26c9(%rip), %rdi      # 0x13460
xorl %eax, %eax
callq 0x2140
movl $0x1, %edi
callq 0x2330
movq %r14, %rdi
movq %r12, %rsi
callq 0x20b0
movl %ebp, %r13d
movb 0xc(%rsp), %r12b
movzbl (%r14), %eax
cmpl $0x5c, %eax
je 0x10dca
testl %eax, %eax
jne 0x10dce
jmp 0x10dd3
movb $0x2f, (%r14)
incq %r14
jmp 0x10dbb
leaq 0x63f6(%rip), %rdi      # 0x171d0
callq 0x3c23
movq %r15, %rdi
callq 0x21a0
leaq 0x14ce(%rip), %rsi      # 0x122bc
movq %rbx, %rdi
callq 0x26b0
testq %rax, %rax
je 0x10e27
movq 0x18(%rax), %rdx
movq 0x20(%rax), %rsi
cmpq %rsi, %rdx
sete %cl
je 0x10e22
movq (%rdx), %rax
testb $0x40, 0x30(%rax)
je 0x10e22
addq $0x8, %rdx
cmpq %rsi, %rdx
sete %cl
jne 0x10e0b
jmp 0x10e22
testb $0x1, %cl
je 0x10e29
xorl %eax, %eax
testq %rax, %rax
jne 0x10ec2
leaq 0x1483(%rip), %rsi      # 0x122bc
movq %rbx, %rdi
xorl %edx, %edx
callq 0x2745
movq %rax, %r14
leaq 0x22cf(%rip), %rsi      # 0x1311c
movq %rbx, %rdi
callq 0x26b0
movq %r14, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x10910
movq %rax, %r15
leaq 0x230f(%rip), %rsi      # 0x1317b
movq %rbx, %rdi
callq 0x26b0
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x10910
movq %rax, %r15
leaq 0x22e4(%rip), %rsi      # 0x13170
movq %rbx, %rdi
callq 0x26b0
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x10910
movq %rax, %r15
leaq 0x1283(%rip), %rsi      # 0x1212f
movq %rbx, %rdi
callq 0x26b0
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x10910
leaq 0x1700(%rip), %rsi      # 0x125c9
movq %rbx, %rdi
callq 0x26b0
movq %rax, %rdi
callq 0xaf5c
testb %r12b, %r12b
jne 0x10eeb
movq %rbx, %rdi
movl $0x1, %esi
callq 0x5d5f
cmpb $0x0, 0x732e(%rip)      # 0x18220
je 0x11069
leaq 0x257c(%rip), %rsi      # 0x1347b
movq %rbx, %rdi
movl $0x1, %edx
callq 0x2745
leaq 0x730d(%rip), %r14      # 0x18220
movq %rax, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x2745
leaq 0x255e(%rip), %rsi      # 0x13488
movq %rbx, %rdi
movl $0x1, %edx
callq 0x2745
leaq 0x66c2(%rip), %rsi      # 0x17600
movq %rax, %rdi
movl $0x1, %edx
callq 0x2745
movl 0x30(%rax), %ecx
andl $-0x10, %ecx
incl %ecx
movl %ecx, 0x30(%rax)
leaq 0x2534(%rip), %rsi      # 0x13491
movq %rbx, %rdi
movl $0x1, %edx
callq 0x2745
leaq 0x6a8f(%rip), %r15      # 0x17a00
movq %rax, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x2745
movl 0x30(%rax), %ecx
andl $-0x10, %ecx
orl $0x2, %ecx
movl %ecx, 0x30(%rax)
leaq 0x2506(%rip), %rsi      # 0x1349a
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x2320
leaq 0x16cb(%rip), %rsi      # 0x1267b
movq %rbx, %rdi
movl $0x1, %edx
callq 0x2745
movq %rax, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x2745
movl 0x30(%rax), %ecx
andl $-0x10, %ecx
orl $0x2, %ecx
movl %ecx, 0x30(%rax)
leaq 0x24c8(%rip), %rsi      # 0x134a8
movq %r12, %rdi
movq %r15, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x2320
leaq 0x24bd(%rip), %rsi      # 0x134b4
movq %rbx, %rdi
movl $0x1, %edx
callq 0x2745
movq %rax, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x2745
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 0x11023
leaq 0x12ca(%rip), %rsi      # 0x12300
xorl %edx, %edx
callq 0x2745
testq %rax, %rax
je 0x11085
movq 0x18(%rax), %rcx
movq 0x20(%rax), %rdx
cmpq %rdx, %rcx
sete %al
je 0x11081
movq (%rcx), %rbx
testb $0x40, 0x30(%rbx)
je 0x11081
addq $0x8, %rcx
cmpq %rdx, %rcx
sete %al
jne 0x11052
jmp 0x11081
movl $0x1, %ebx
testb %r12b, %r12b
je 0x1122e
callq 0x5df3
jmp 0x1122e
testb $0x1, %al
je 0x11087
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x110af
movq (%rbx), %r14
movq %r14, %rdi
callq 0x4016
testl %eax, %eax
je 0x11112
leaq 0x6d5e(%rip), %rdi      # 0x17e00
movq %r14, %rsi
callq 0x20b0
jmp 0x11147
movups 0x2412(%rip), %xmm0     # 0x134c8
movups %xmm0, 0x6d4d(%rip)     # 0x17e0a
movups 0x23fa(%rip), %xmm0     # 0x134be
movaps %xmm0, 0x6d35(%rip)     # 0x17e00
leaq 0x6d2e(%rip), %r14      # 0x17e00
leaq 0x1227(%rip), %rsi      # 0x12300
movq %r15, %rbx
movq %r15, %rdi
movl $0x1, %edx
callq 0x2745
movq %rax, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x2745
movl 0x30(%rax), %ecx
andl $-0x10, %ecx
orl $0x3, %ecx
movl %ecx, 0x30(%rax)
movq (%rax), %rsi
movq %r14, %rdi
callq 0x20b0
jmp 0x1115b
leaq 0x64e7(%rip), %rdi      # 0x17600
callq 0x4016
testl %eax, %eax
je 0x1109b
leaq 0x6cd3(%rip), %r14      # 0x17e00
leaq 0x64cc(%rip), %rsi      # 0x17600
movq %r14, %rdi
callq 0x20b0
movq (%rbx), %rsi
movq %r14, %rdi
callq 0x2310
leaq 0x6cb2(%rip), %rdi      # 0x17e00
movl $0x1, %esi
callq 0x437e
movq %r15, %rbx
leaq 0x6c9e(%rip), %r14      # 0x17e00
movq %r14, %rdi
callq 0x3df1
movq %r14, %rdi
callq 0x2120
movq %rax, 0x7097(%rip)      # 0x18210
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x20b0
leaq 0x7090(%rip), %rsi      # 0x18220
movq %r15, %rdi
callq 0x2310
movq %r15, %rdi
callq 0x2120
movl $0x6975622e, 0x20(%rsp,%rax) # imm = 0x6975622E
movl $0x646c69, 0x23(%rsp,%rax) # imm = 0x646C69
leaq 0x7479(%rip), %r14      # 0x18630
leaq 0x6842(%rip), %rsi      # 0x17a00
movq %r14, %rdi
callq 0x20b0
movl $0x2, 0x9460(%rip)      # 0x1a630
movq $0x0, 0x9475(%rip) # 0x1a650
movq %rbx, %rdi
movq %r15, %rsi
movl $0x3, %edx
callq 0x10840
movq 0x945e(%rip), %rdi      # 0x1a650
testq %rdi, %rdi
je 0x11212
callq 0x20f0
movslq 0x741d(%rip), %rax      # 0x18620
shlq $0xa, %rax
addq %rax, %r14
movq %r14, %rdi
callq 0x616e
testb %r13b, %r13b
jne 0x11224
movq %rbx, %rdi
movl $0x1, %esi
callq 0x5d5f
movq %rbx, %rdi
callq 0x2da0
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5df3
jmp 0x1122c