// File: WeiqiangZhou[P]BIRD/source/create_library_main.cpp
// Function: main
int main(int argc, char *argv[])
{
	char infile[255]="./par_file.txt";
	char outfile[255]="./model_file.bin";
	
    if (argc == 5 && strcmp(argv[1], "-i") == 0 && strcmp(argv[3], "-o") == 0)
	{
		strcpy(infile, argv[2]);
		strcpy(outfile, argv[4]);
	}
    else if (argc == 2 && strcmp(argv[1], "-h") == 0)
    {
                std::cout << "Usage: BIRD_build_library -i par_file.txt -o model_file.bin" << std::endl;
                std::cout << "-i Specify input file which contains the required parameters and files list." << std::endl;
                std::cout << "-o Specify output name of the model file to be used by BIRD." << std::endl;
                return 1;
    }
	else
	{
		std::cout << "Please input the correct parameters." << std::endl;
		std::cout << "Example: BIRD_build_library -i par_file.txt -o model_file.bin" << std::endl;
		return 1;
	}

	FILE * p_out;
	int param[8];
	int num_loci, num_gene, cluster_size, bin_size, num_var, DH_num1, DH_num2, DH_num3;
	char **filelist = new char *[18];
	for (int i = 0; i < 18; i++)
	{
		filelist[i] = new char[255];
	}

	if (ReadParam(infile, param, filelist)){ return 1; }

	num_loci = param[0];
	num_gene = param[1];
	cluster_size = param[2];
	bin_size = param[3];
	num_var = param[4];
	DH_num1 = param[5];
	DH_num2 = param[6];
	DH_num3 = param[7];

	double *uw_quantile = new double[num_gene];
	double *exon_mean = new double[num_gene];
	double *exon_sd = new double[num_gene];
	double *DNase_mean = new double[num_loci];
	double *DNase_sd = new double[num_loci];
	int *cluster_idx = new int[num_gene];

	double **coef = new double *[num_var];
	for (int j = 0; j < num_var; j++)
	{
		coef[j] = new double[num_loci]();
	}

	double **dis_matrix = new double *[3];
	for (int j = 0; j < 3; j++)
	{
		dis_matrix[j] = new double[num_loci]();
	}

	double **DH_coef1 = new double *[num_var];
	for (int j = 0; j < num_var; j++)
	{
		DH_coef1[j] = new double[DH_num1]();
	}

	double **DH_coef2 = new double *[num_var];
	for (int j = 0; j < num_var; j++)
	{
		DH_coef2[j] = new double[DH_num2]();
	}

	double **DH_coef3 = new double *[num_var];
	for (int j = 0; j < num_var; j++)
	{
		DH_coef3[j] = new double[DH_num3]();
	}

	int **pre_idx = new int *[num_var];
	for (int j = 0; j < num_var; j++)
	{
		pre_idx[j] = new int[num_loci]();
	}

	int **DH_pre_idx1 = new int *[num_var];
	for (int j = 0; j < num_var; j++)
	{
		DH_pre_idx1[j] = new int[DH_num1]();
	}

	int **DH_pre_idx2 = new int *[num_var];
	for (int j = 0; j < num_var; j++)
	{
		DH_pre_idx2[j] = new int[DH_num2]();
	}

	int **DH_pre_idx3 = new int *[num_var];
	for (int j = 0; j < num_var; j++)
	{
		DH_pre_idx3[j] = new int[DH_num3]();
	}

	int **DH_cluster = new int *[3];
	for (int j = 0; j < 3; j++)
	{
		DH_cluster[j] = new int[num_loci]();
	}

	char **select_loci = new char *[num_loci];
	for (int j = 0; j < num_loci; j++)
	{
		select_loci[j] = new char[30];
	}

	char **row_name = new char *[num_gene];
	for (int j = 0; j < num_gene; j++)
	{
		row_name[j] = new char[30];
	}

        //read in all required files
	if (ReadVector_d(filelist[0], uw_quantile)){ return 1; }
	if (ReadVector_d(filelist[1], exon_mean)){ return 1; }
	if (ReadVector_d(filelist[2], exon_sd)){ return 1; }
	if (ReadVector_i(filelist[3], cluster_idx)){ return 1; }
	if (ReadVector_d(filelist[4], DNase_mean)){ return 1; }
	if (ReadVector_d(filelist[5], DNase_sd)){ return 1; }
	if (ReadMatrix_d(filelist[6], coef)){ return 1; }
	if (ReadMatrix_i(filelist[7], pre_idx)){ return 1; }
	if (ReadName(filelist[8], select_loci)){ return 1; }
	if (ReadName(filelist[9], row_name)){ return 1; }
	if (ReadMatrix_d(filelist[10], dis_matrix)){ return 1; }
	if (ReadMatrix_i(filelist[11], DH_cluster)){ return 1; }
	if (ReadMatrix_d(filelist[12], DH_coef1)){ return 1; }
	if (ReadMatrix_d(filelist[13], DH_coef2)){ return 1; }
	if (ReadMatrix_d(filelist[14], DH_coef3)){ return 1; }
	if (ReadMatrix_i(filelist[15], DH_pre_idx1)){ return 1; }
	if (ReadMatrix_i(filelist[16], DH_pre_idx2)){ return 1; }
	if (ReadMatrix_i(filelist[17], DH_pre_idx3)){ return 1; }

        //combine all information into one binary file
	p_out = fopen(outfile, "wb");
	if (p_out != NULL)
	{
		std::cout << "Writing " << outfile << "..." << std::endl;
		fwrite(param, sizeof(int), 8, p_out);
		fwrite(uw_quantile, sizeof(double), num_gene, p_out);
		fwrite(exon_mean, sizeof(double), num_gene, p_out);
		fwrite(exon_sd, sizeof(double), num_gene, p_out);
		for (int k = 0; k < num_var; k++)
		{
			fwrite(coef[k], sizeof(double), num_loci, p_out);
		}
		fwrite(DNase_mean, sizeof(double), num_loci, p_out);
		fwrite(DNase_sd, sizeof(double), num_loci, p_out);
		for (int k = 0; k < num_var; k++)
		{
			fwrite(pre_idx[k], sizeof(int), num_loci, p_out);
		}
		fwrite(cluster_idx, sizeof(int), num_gene, p_out);
		for (int k = 0; k < num_loci; k++)
		{
			fwrite(select_loci[k], sizeof(char), 30, p_out);
		}
		for (int k = 0; k < num_gene; k++)
		{
			fwrite(row_name[k], sizeof(char), 30, p_out);
		}
		for (int k = 0; k < 3; k++)
		{
			fwrite(dis_matrix[k], sizeof(double), num_loci, p_out);
		}
		for (int k = 0; k < 3; k++)
		{
			fwrite(DH_cluster[k], sizeof(int), num_loci, p_out);
		}
		for (int k = 0; k < num_var; k++)
		{
			fwrite(DH_coef1[k], sizeof(double), DH_num1, p_out);
		}
		for (int k = 0; k < num_var; k++)
		{
			fwrite(DH_coef2[k], sizeof(double), DH_num2, p_out);
		}
		for (int k = 0; k < num_var; k++)
		{
			fwrite(DH_coef3[k], sizeof(double), DH_num3, p_out);
		}
		for (int k = 0; k < num_var; k++)
		{
			fwrite(DH_pre_idx1[k], sizeof(int), DH_num1, p_out);
		}
		for (int k = 0; k < num_var; k++)
		{
			fwrite(DH_pre_idx2[k], sizeof(int), DH_num2, p_out);
		}
		for (int k = 0; k < num_var; k++)
		{
			fwrite(DH_pre_idx3[k], sizeof(int), DH_num3, p_out);
		}
		fclose(p_out);
		std::cout << "Successfully generated library file." << std::endl;
	}
	else
	{
		std::cout << "Error! Cannot write " << outfile << std::endl;
		return 1;
	}

	

	//Release memory
	delete[] uw_quantile;
	delete[] exon_mean;
	delete[] exon_sd;
	delete[] DNase_mean;
	delete[] DNase_sd;
	delete[] cluster_idx;
	for (int j = 0; j < 3; j++)
	{
		delete[] dis_matrix[j];
		delete[] DH_cluster[j];
	}
	for (int j = 0; j < num_var; j++)
	{
		delete[] coef[j];
		delete[] pre_idx[j];
		delete[] DH_coef1[j];
		delete[] DH_coef2[j];
		delete[] DH_coef3[j];
		delete[] DH_pre_idx1[j];
		delete[] DH_pre_idx2[j];
		delete[] DH_pre_idx3[j];
	}
	delete[] coef;
	delete[] pre_idx;
	delete[] DH_coef1;
	delete[] DH_coef2;
	delete[] DH_coef3;
	delete[] DH_pre_idx1;
	delete[] DH_pre_idx2;
	delete[] DH_pre_idx3;
	delete[] dis_matrix;
	delete[] DH_cluster;

	return 0;


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x510, %rsp            # imm = 0x510
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x110(%rbp), %rdi
leaq 0x3c19(%rip), %rsi      # 0x6010
movl $0xff, %edx
callq 0x20c0
leaq -0x210(%rbp), %rdi
leaq 0x3d01(%rip), %rsi      # 0x6110
movl $0xff, %edx
callq 0x20c0
cmpl $0x5, -0x8(%rbp)
jne 0x247e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x3de1(%rip), %rsi      # 0x620f
callq 0x2170
cmpl $0x0, %eax
jne 0x247e
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0x3dcb(%rip), %rsi      # 0x6212
callq 0x2170
cmpl $0x0, %eax
jne 0x247e
leaq -0x110(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x20e0
leaq -0x210(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x20e0
jmp 0x2563
cmpl $0x2, -0x8(%rbp)
jne 0x2513
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x3d7e(%rip), %rsi      # 0x6215
callq 0x2170
cmpl $0x0, %eax
jne 0x2513
movq 0x5b30(%rip), %rdi      # 0x7fd8
leaq 0x3d69(%rip), %rsi      # 0x6218
callq 0x20f0
movq %rax, %rdi
movq 0x5b0a(%rip), %rsi      # 0x7fc8
callq 0x2110
movq 0x5b0e(%rip), %rdi      # 0x7fd8
leaq 0x3d83(%rip), %rsi      # 0x6254
callq 0x20f0
movq %rax, %rdi
movq 0x5ae8(%rip), %rsi      # 0x7fc8
callq 0x2110
movq 0x5aec(%rip), %rdi      # 0x7fd8
leaq 0x3dae(%rip), %rsi      # 0x62a1
callq 0x20f0
movq %rax, %rdi
movq 0x5ac6(%rip), %rsi      # 0x7fc8
callq 0x2110
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq 0x5abe(%rip), %rdi      # 0x7fd8
leaq 0x3dbd(%rip), %rsi      # 0x62de
callq 0x20f0
movq %rax, %rdi
movq 0x5a98(%rip), %rsi      # 0x7fc8
callq 0x2110
movq 0x5a9c(%rip), %rdi      # 0x7fd8
leaq 0x3dc0(%rip), %rsi      # 0x6303
callq 0x20f0
movq %rax, %rdi
movq 0x5a76(%rip), %rsi      # 0x7fc8
callq 0x2110
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movl $0x90, %edi
callq 0x2030
movq %rax, -0x268(%rbp)
movl $0x0, -0x26c(%rbp)
cmpl $0x12, -0x26c(%rbp)
jge 0x25b7
movl $0xff, %edi
callq 0x2030
movq %rax, %rdx
movq -0x268(%rbp), %rax
movslq -0x26c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x26c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x26c(%rbp)
jmp 0x257e
leaq -0x110(%rbp), %rdi
leaq -0x240(%rbp), %rsi
movq -0x268(%rbp), %rdx
callq 0x3bb0
cmpl $0x0, %eax
je 0x25e2
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movl -0x240(%rbp), %eax
movl %eax, -0x244(%rbp)
movl -0x23c(%rbp), %eax
movl %eax, -0x248(%rbp)
movl -0x238(%rbp), %eax
movl %eax, -0x24c(%rbp)
movl -0x234(%rbp), %eax
movl %eax, -0x250(%rbp)
movl -0x230(%rbp), %eax
movl %eax, -0x254(%rbp)
movl -0x22c(%rbp), %eax
movl %eax, -0x258(%rbp)
movl -0x228(%rbp), %eax
movl %eax, -0x25c(%rbp)
movl -0x224(%rbp), %eax
movl %eax, -0x260(%rbp)
movslq -0x248(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x278(%rbp)
movslq -0x248(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x280(%rbp)
movslq -0x248(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x288(%rbp)
movslq -0x244(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x290(%rbp)
movslq -0x244(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x298(%rbp)
movslq -0x248(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x2a0(%rbp)
movslq -0x254(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x2a8(%rbp)
movl $0x0, -0x2ac(%rbp)
movl -0x2ac(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x2814
movslq -0x244(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x3a8(%rbp)
callq 0x2030
movq -0x3a8(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x3a0(%rbp)
xorl %esi, %esi
callq 0x2090
movq -0x3a0(%rbp), %rdx
movq -0x2a8(%rbp), %rax
movslq -0x2ac(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x2ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2ac(%rbp)
jmp 0x2795
movl $0x18, %edi
callq 0x2030
movq %rax, -0x2b8(%rbp)
movl $0x0, -0x2bc(%rbp)
cmpl $0x3, -0x2bc(%rbp)
jge 0x28a9
movslq -0x244(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x3b8(%rbp)
callq 0x2030
movq -0x3b8(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x3b0(%rbp)
xorl %esi, %esi
callq 0x2090
movq -0x3b0(%rbp), %rdx
movq -0x2b8(%rbp), %rax
movslq -0x2bc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x2bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2bc(%rbp)
jmp 0x282f
movslq -0x254(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x2c8(%rbp)
movl $0x0, -0x2cc(%rbp)
movl -0x2cc(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x2961
movslq -0x258(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x3c8(%rbp)
callq 0x2030
movq -0x3c8(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x3c0(%rbp)
xorl %esi, %esi
callq 0x2090
movq -0x3c0(%rbp), %rdx
movq -0x2c8(%rbp), %rax
movslq -0x2cc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x2cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2cc(%rbp)
jmp 0x28e2
movslq -0x254(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x2d8(%rbp)
movl $0x0, -0x2dc(%rbp)
movl -0x2dc(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x2a19
movslq -0x25c(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x3d8(%rbp)
callq 0x2030
movq -0x3d8(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x3d0(%rbp)
xorl %esi, %esi
callq 0x2090
movq -0x3d0(%rbp), %rdx
movq -0x2d8(%rbp), %rax
movslq -0x2dc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x2dc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2dc(%rbp)
jmp 0x299a
movslq -0x254(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x2e8(%rbp)
movl $0x0, -0x2ec(%rbp)
movl -0x2ec(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x2ad1
movslq -0x260(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x3e8(%rbp)
callq 0x2030
movq -0x3e8(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x3e0(%rbp)
xorl %esi, %esi
callq 0x2090
movq -0x3e0(%rbp), %rdx
movq -0x2e8(%rbp), %rax
movslq -0x2ec(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x2ec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2ec(%rbp)
jmp 0x2a52
movslq -0x254(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x2f8(%rbp)
movl $0x0, -0x2fc(%rbp)
movl -0x2fc(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x2b89
movslq -0x244(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x3f8(%rbp)
callq 0x2030
movq -0x3f8(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x3f0(%rbp)
xorl %esi, %esi
callq 0x2090
movq -0x3f0(%rbp), %rdx
movq -0x2f8(%rbp), %rax
movslq -0x2fc(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x2fc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2fc(%rbp)
jmp 0x2b0a
movslq -0x254(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x308(%rbp)
movl $0x0, -0x30c(%rbp)
movl -0x30c(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x2c41
movslq -0x258(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x408(%rbp)
callq 0x2030
movq -0x408(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x400(%rbp)
xorl %esi, %esi
callq 0x2090
movq -0x400(%rbp), %rdx
movq -0x308(%rbp), %rax
movslq -0x30c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x30c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30c(%rbp)
jmp 0x2bc2
movslq -0x254(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x318(%rbp)
movl $0x0, -0x31c(%rbp)
movl -0x31c(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x2cf9
movslq -0x25c(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x418(%rbp)
callq 0x2030
movq -0x418(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x410(%rbp)
xorl %esi, %esi
callq 0x2090
movq -0x410(%rbp), %rdx
movq -0x318(%rbp), %rax
movslq -0x31c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x31c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x31c(%rbp)
jmp 0x2c7a
movslq -0x254(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x328(%rbp)
movl $0x0, -0x32c(%rbp)
movl -0x32c(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x2db1
movslq -0x260(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x428(%rbp)
callq 0x2030
movq -0x428(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x420(%rbp)
xorl %esi, %esi
callq 0x2090
movq -0x420(%rbp), %rdx
movq -0x328(%rbp), %rax
movslq -0x32c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x32c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x32c(%rbp)
jmp 0x2d32
movl $0x18, %edi
callq 0x2030
movq %rax, -0x338(%rbp)
movl $0x0, -0x33c(%rbp)
cmpl $0x3, -0x33c(%rbp)
jge 0x2e46
movslq -0x244(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x438(%rbp)
callq 0x2030
movq -0x438(%rbp), %rdx
movq %rax, %rdi
movq %rdi, -0x430(%rbp)
xorl %esi, %esi
callq 0x2090
movq -0x430(%rbp), %rdx
movq -0x338(%rbp), %rax
movslq -0x33c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x33c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x33c(%rbp)
jmp 0x2dcc
movslq -0x244(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x348(%rbp)
movl $0x0, -0x34c(%rbp)
movl -0x34c(%rbp), %eax
cmpl -0x244(%rbp), %eax
jge 0x2ebd
movl $0x1e, %edi
callq 0x2030
movq %rax, %rdx
movq -0x348(%rbp), %rax
movslq -0x34c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x34c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34c(%rbp)
jmp 0x2e7f
movslq -0x248(%rbp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, -0x358(%rbp)
movl $0x0, -0x35c(%rbp)
movl -0x35c(%rbp), %eax
cmpl -0x248(%rbp), %eax
jge 0x2f34
movl $0x1e, %edi
callq 0x2030
movq %rax, %rdx
movq -0x358(%rbp), %rax
movslq -0x35c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x35c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x35c(%rbp)
jmp 0x2ef6
movq -0x268(%rbp), %rax
movq (%rax), %rdi
movq -0x278(%rbp), %rsi
callq 0x45f0
cmpl $0x0, %eax
je 0x2f5b
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x280(%rbp), %rsi
callq 0x45f0
cmpl $0x0, %eax
je 0x2f83
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x288(%rbp), %rsi
callq 0x45f0
cmpl $0x0, %eax
je 0x2fab
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x2a0(%rbp), %rsi
callq 0x4720
cmpl $0x0, %eax
je 0x2fd3
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x290(%rbp), %rsi
callq 0x45f0
cmpl $0x0, %eax
je 0x2ffb
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x298(%rbp), %rsi
callq 0x45f0
cmpl $0x0, %eax
je 0x3023
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x2a8(%rbp), %rsi
callq 0x4850
cmpl $0x0, %eax
je 0x304b
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x2f8(%rbp), %rsi
callq 0x4bb0
cmpl $0x0, %eax
je 0x3073
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x348(%rbp), %rsi
callq 0x4f10
cmpl $0x0, %eax
je 0x309b
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x358(%rbp), %rsi
callq 0x4f10
cmpl $0x0, %eax
je 0x30c3
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x2b8(%rbp), %rsi
callq 0x4850
cmpl $0x0, %eax
je 0x30eb
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x338(%rbp), %rsi
callq 0x4bb0
cmpl $0x0, %eax
je 0x3113
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x2c8(%rbp), %rsi
callq 0x4850
cmpl $0x0, %eax
je 0x313b
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x68(%rax), %rdi
movq -0x2d8(%rbp), %rsi
callq 0x4850
cmpl $0x0, %eax
je 0x3163
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x70(%rax), %rdi
movq -0x2e8(%rbp), %rsi
callq 0x4850
cmpl $0x0, %eax
je 0x318b
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x78(%rax), %rdi
movq -0x308(%rbp), %rsi
callq 0x4bb0
cmpl $0x0, %eax
je 0x31b3
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x80(%rax), %rdi
movq -0x318(%rbp), %rsi
callq 0x4bb0
cmpl $0x0, %eax
je 0x31de
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x268(%rbp), %rax
movq 0x88(%rax), %rdi
movq -0x328(%rbp), %rsi
callq 0x4bb0
cmpl $0x0, %eax
je 0x3209
movl $0x1, -0x4(%rbp)
jmp 0x3b98
leaq -0x210(%rbp), %rdi
leaq 0x312a(%rip), %rsi      # 0x6341
callq 0x2120
movq %rax, -0x218(%rbp)
cmpq $0x0, -0x218(%rbp)
je 0x374e
movq 0x4da0(%rip), %rdi      # 0x7fd8
leaq 0x3105(%rip), %rsi      # 0x6344
callq 0x20f0
movq %rax, %rdi
leaq -0x210(%rbp), %rsi
callq 0x20f0
movq %rax, %rdi
leaq 0x30f0(%rip), %rsi      # 0x634d
callq 0x20f0
movq %rax, %rdi
movq 0x4d5c(%rip), %rsi      # 0x7fc8
callq 0x2110
leaq -0x240(%rbp), %rdi
movq -0x218(%rbp), %rcx
movl $0x4, %esi
movl $0x8, %edx
callq 0x2240
movq -0x278(%rbp), %rdi
movslq -0x248(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x8, %esi
callq 0x2240
movq -0x280(%rbp), %rdi
movslq -0x248(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x8, %esi
callq 0x2240
movq -0x288(%rbp), %rdi
movslq -0x248(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x8, %esi
callq 0x2240
movl $0x0, -0x360(%rbp)
movl -0x360(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x333e
movq -0x2a8(%rbp), %rax
movslq -0x360(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x244(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x8, %esi
callq 0x2240
movl -0x360(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x360(%rbp)
jmp 0x32f5
movq -0x290(%rbp), %rdi
movslq -0x244(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x8, %esi
callq 0x2240
movq -0x298(%rbp), %rdi
movslq -0x244(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x8, %esi
callq 0x2240
movl $0x0, -0x364(%rbp)
movl -0x364(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x33cf
movq -0x2f8(%rbp), %rax
movslq -0x364(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x244(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x4, %esi
callq 0x2240
movl -0x364(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x364(%rbp)
jmp 0x3386
movq -0x2a0(%rbp), %rdi
movslq -0x248(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x4, %esi
callq 0x2240
movl $0x0, -0x368(%rbp)
movl -0x368(%rbp), %eax
cmpl -0x244(%rbp), %eax
jge 0x343f
movq -0x348(%rbp), %rax
movslq -0x368(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x218(%rbp), %rcx
movl $0x1, %esi
movl $0x1e, %edx
callq 0x2240
movl -0x368(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x368(%rbp)
jmp 0x33f8
movl $0x0, -0x36c(%rbp)
movl -0x36c(%rbp), %eax
cmpl -0x248(%rbp), %eax
jge 0x3490
movq -0x358(%rbp), %rax
movslq -0x36c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x218(%rbp), %rcx
movl $0x1, %esi
movl $0x1e, %edx
callq 0x2240
movl -0x36c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x36c(%rbp)
jmp 0x3449
movl $0x0, -0x370(%rbp)
cmpl $0x3, -0x370(%rbp)
jge 0x34de
movq -0x2b8(%rbp), %rax
movslq -0x370(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x244(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x8, %esi
callq 0x2240
movl -0x370(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x370(%rbp)
jmp 0x349a
movl $0x0, -0x374(%rbp)
cmpl $0x3, -0x374(%rbp)
jge 0x352c
movq -0x338(%rbp), %rax
movslq -0x374(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x244(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x4, %esi
callq 0x2240
movl -0x374(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x374(%rbp)
jmp 0x34e8
movl $0x0, -0x378(%rbp)
movl -0x378(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x357f
movq -0x2c8(%rbp), %rax
movslq -0x378(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x258(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x8, %esi
callq 0x2240
movl -0x378(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x378(%rbp)
jmp 0x3536
movl $0x0, -0x37c(%rbp)
movl -0x37c(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x35d2
movq -0x2d8(%rbp), %rax
movslq -0x37c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x25c(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x8, %esi
callq 0x2240
movl -0x37c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x37c(%rbp)
jmp 0x3589
movl $0x0, -0x380(%rbp)
movl -0x380(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x3625
movq -0x2e8(%rbp), %rax
movslq -0x380(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x260(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x8, %esi
callq 0x2240
movl -0x380(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x380(%rbp)
jmp 0x35dc
movl $0x0, -0x384(%rbp)
movl -0x384(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x3678
movq -0x308(%rbp), %rax
movslq -0x384(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x258(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x4, %esi
callq 0x2240
movl -0x384(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x384(%rbp)
jmp 0x362f
movl $0x0, -0x388(%rbp)
movl -0x388(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x36cb
movq -0x318(%rbp), %rax
movslq -0x388(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x25c(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x4, %esi
callq 0x2240
movl -0x388(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x388(%rbp)
jmp 0x3682
movl $0x0, -0x38c(%rbp)
movl -0x38c(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x371e
movq -0x328(%rbp), %rax
movslq -0x38c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x260(%rbp), %rdx
movq -0x218(%rbp), %rcx
movl $0x4, %esi
callq 0x2240
movl -0x38c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38c(%rbp)
jmp 0x36d5
movq -0x218(%rbp), %rdi
callq 0x2100
movq 0x48a7(%rip), %rdi      # 0x7fd8
leaq 0x2c19(%rip), %rsi      # 0x6351
callq 0x20f0
movq %rax, %rdi
movq 0x4881(%rip), %rsi      # 0x7fc8
callq 0x2110
jmp 0x378b
movq 0x4883(%rip), %rdi      # 0x7fd8
leaq 0x2c1a(%rip), %rsi      # 0x6376
callq 0x20f0
movq %rax, %rdi
leaq -0x210(%rbp), %rsi
callq 0x20f0
movq %rax, %rdi
movq 0x484e(%rip), %rsi      # 0x7fc8
callq 0x2110
movl $0x1, -0x4(%rbp)
jmp 0x3b98
movq -0x278(%rbp), %rax
movq %rax, -0x440(%rbp)
cmpq $0x0, %rax
je 0x37ab
movq -0x440(%rbp), %rdi
callq 0x2150
movq -0x280(%rbp), %rax
movq %rax, -0x448(%rbp)
cmpq $0x0, %rax
je 0x37cb
movq -0x448(%rbp), %rdi
callq 0x2150
movq -0x288(%rbp), %rax
movq %rax, -0x450(%rbp)
cmpq $0x0, %rax
je 0x37eb
movq -0x450(%rbp), %rdi
callq 0x2150
movq -0x290(%rbp), %rax
movq %rax, -0x458(%rbp)
cmpq $0x0, %rax
je 0x380b
movq -0x458(%rbp), %rdi
callq 0x2150
movq -0x298(%rbp), %rax
movq %rax, -0x460(%rbp)
cmpq $0x0, %rax
je 0x382b
movq -0x460(%rbp), %rdi
callq 0x2150
movq -0x2a0(%rbp), %rax
movq %rax, -0x468(%rbp)
cmpq $0x0, %rax
je 0x384b
movq -0x468(%rbp), %rdi
callq 0x2150
movl $0x0, -0x390(%rbp)
cmpl $0x3, -0x390(%rbp)
jge 0x38c7
movq -0x2b8(%rbp), %rax
movslq -0x390(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x470(%rbp)
cmpq $0x0, %rax
je 0x3889
movq -0x470(%rbp), %rdi
callq 0x2150
movq -0x338(%rbp), %rax
movslq -0x390(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x478(%rbp)
cmpq $0x0, %rax
je 0x38b4
movq -0x478(%rbp), %rdi
callq 0x2150
jmp 0x38b6
movl -0x390(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x390(%rbp)
jmp 0x3855
movl $0x0, -0x394(%rbp)
movl -0x394(%rbp), %eax
cmpl -0x254(%rbp), %eax
jge 0x3a51
movq -0x2a8(%rbp), %rax
movslq -0x394(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x480(%rbp)
cmpq $0x0, %rax
je 0x390e
movq -0x480(%rbp), %rdi
callq 0x2150
movq -0x2f8(%rbp), %rax
movslq -0x394(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x488(%rbp)
cmpq $0x0, %rax
je 0x3939
movq -0x488(%rbp), %rdi
callq 0x2150
movq -0x2c8(%rbp), %rax
movslq -0x394(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x490(%rbp)
cmpq $0x0, %rax
je 0x3964
movq -0x490(%rbp), %rdi
callq 0x2150
movq -0x2d8(%rbp), %rax
movslq -0x394(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x498(%rbp)
cmpq $0x0, %rax
je 0x398f
movq -0x498(%rbp), %rdi
callq 0x2150
movq -0x2e8(%rbp), %rax
movslq -0x394(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x4a0(%rbp)
cmpq $0x0, %rax
je 0x39ba
movq -0x4a0(%rbp), %rdi
callq 0x2150
movq -0x308(%rbp), %rax
movslq -0x394(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x4a8(%rbp)
cmpq $0x0, %rax
je 0x39e5
movq -0x4a8(%rbp), %rdi
callq 0x2150
movq -0x318(%rbp), %rax
movslq -0x394(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x4b0(%rbp)
cmpq $0x0, %rax
je 0x3a10
movq -0x4b0(%rbp), %rdi
callq 0x2150
movq -0x328(%rbp), %rax
movslq -0x394(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x4b8(%rbp)
cmpq $0x0, %rax
je 0x3a3b
movq -0x4b8(%rbp), %rdi
callq 0x2150
jmp 0x3a3d
movl -0x394(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x394(%rbp)
jmp 0x38d1
movq -0x2a8(%rbp), %rax
movq %rax, -0x4c0(%rbp)
cmpq $0x0, %rax
je 0x3a71
movq -0x4c0(%rbp), %rdi
callq 0x2150
movq -0x2f8(%rbp), %rax
movq %rax, -0x4c8(%rbp)
cmpq $0x0, %rax
je 0x3a91
movq -0x4c8(%rbp), %rdi
callq 0x2150
movq -0x2c8(%rbp), %rax
movq %rax, -0x4d0(%rbp)
cmpq $0x0, %rax
je 0x3ab1
movq -0x4d0(%rbp), %rdi
callq 0x2150
movq -0x2d8(%rbp), %rax
movq %rax, -0x4d8(%rbp)
cmpq $0x0, %rax
je 0x3ad1
movq -0x4d8(%rbp), %rdi
callq 0x2150
movq -0x2e8(%rbp), %rax
movq %rax, -0x4e0(%rbp)
cmpq $0x0, %rax
je 0x3af1
movq -0x4e0(%rbp), %rdi
callq 0x2150
movq -0x308(%rbp), %rax
movq %rax, -0x4e8(%rbp)
cmpq $0x0, %rax
je 0x3b11
movq -0x4e8(%rbp), %rdi
callq 0x2150
movq -0x318(%rbp), %rax
movq %rax, -0x4f0(%rbp)
cmpq $0x0, %rax
je 0x3b31
movq -0x4f0(%rbp), %rdi
callq 0x2150
movq -0x328(%rbp), %rax
movq %rax, -0x4f8(%rbp)
cmpq $0x0, %rax
je 0x3b51
movq -0x4f8(%rbp), %rdi
callq 0x2150
movq -0x2b8(%rbp), %rax
movq %rax, -0x500(%rbp)
cmpq $0x0, %rax
je 0x3b71
movq -0x500(%rbp), %rdi
callq 0x2150
movq -0x338(%rbp), %rax
movq %rax, -0x508(%rbp)
cmpq $0x0, %rax
je 0x3b91
movq -0x508(%rbp), %rdi
callq 0x2150
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x510, %rsp            # imm = 0x510
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop