// File: /workspace/github_cpp_makefile_star2_O2/CominLab[P]QCluster/qcluster.cc
// Function: main
int main(int argc, char **argv)
{
	int num_clusters = 5;  // target number of clusters
	char dist_type = 'e'; // default to L2
	int K = 2;  // k-mer size
	bool normalize_matrix_flag = false; // make columns univariant ("whiten");
		// off by default
	int normalize = 2; // normalize each row. Deafult: method 2
	bool redistribute = true; //Redistribute missing quality by default
	int e_method = 1;
	int p_method = 1;
	double pseudocount = PC; // pseudocount for k-mers
	bool rc_flag = false; // append reverse complement to each sequence;
		// off by default
	unsigned int random_seed = time(NULL); // initial seed
	int num_trials = 0; // later we check if it was specified using "-t" arg
		// and set the correct default if it was not; note that the default 
		// depends on whether consensus clustering is performed
	int verbose_level = 0;
	bool write_flag = false; // write sequences by cluster; off by default
	int default_max_iterations = 1000;

	int opt;
	while((opt = getopt(argc, argv, "c:d:e:k:m:N:nP:p:q:rRsS:t:vwh")) != -1 ){
		switch(opt){
            case 'c':
                num_clusters = atoi(optarg);
                break;
			case 'd':
                dist_type = *optarg;
                break;
			case 'e':
				e_method = atoi(optarg);
				break;
            case 'k':
                K = atoi(optarg);
                break;
			case 'm':
				max_iterations = atoi(optarg);
				//If max_iterations < 2 the default value will be restored
				if (max_iterations<2) max_iterations = default_max_iterations;
				break;
			case 'N':
				normalize = atoi(optarg);
				break;
            case 'n':
                normalize_matrix_flag = true;
                break;
			case 'P':
				p_method = atoi(optarg);
				if (p_method<1 || p_method>3) p_method = 2;
				break;				
			case 'p':
				pseudocount = atof(optarg);
				break;
			case 'R':
				//Do not redistribute quality
				redistribute = false;
				break;
            case 'r':
                rc_flag = true;
                break;
			case 'S':
				random_seed = atoi(optarg);
				break;
            case 't':
                num_trials = atoi(optarg);
                break;
            case 'v':
                ++verbose_level;
                break;
            case 'w':
                write_flag = true;
                break;
            case 'h':
				print_usage(argv[0]);
				return EXIT_SUCCESS;
            case '?':
                print_usage(argv[0]);
                return EXIT_FAILURE;
            default:
                // You won't actually get here
                break;
        }
	}

	if (dist_type != 'a'){
		p_method = 0;//No calculation of expected freq and expected quality
		e_method = 0;
	}

	// if "-t" argument was absent, use the appropriate default
	if (!num_trials) {
		num_trials = 1;
	}

	if(argc != optind + 1){
		cout<<"Missing/extra input file name"<<endl;
		print_usage(argv[0]);
		return EXIT_FAILURE;
	}
	char* fastq_file_name = *(argv + optind );

	// initialize random number generator
	srand(random_seed);

	// initialize constants
	int L = 1; // length of the freq. vector L = NUM_NT**K
	for(int k=0; k<K; ++k){
		L *= NUM_NT;
	}

	// count sequences
	int N = CountReads(fastq_file_name);  // number of sequences
	if (verbose_level>0){
		cerr<<"Found "<<N<<" sequences\n";
	}

	// read sequences and build count matrix
	RecordGenerator rec_gen(fastq_file_name);
	double **freq = new double*[N];
	freq[0] = new double[N * L];
	double **quality = new double*[N];
	for (int i=0; i<N; i++) quality[i] = new double[L];
	
	double **freq_1  = new double*[N];
	freq_1[0] = new double[N * NUM_NT];
	double **quality_1 = new double*[N];
	for (int i=0; i<N; i++) quality_1[i] = new double[NUM_NT];
	
	//Vector for calculus of E(Pxi)2
	double *avg_quality_1 = new double[NUM_NT];
	for(int i=0; i<NUM_NT; i++) avg_quality_1[i] = 0;
	
	//Vector for calculus of E(Pxi)3
	double **avg_quality = new double*[L];
	for (int i=0; i<L; i++) {
		avg_quality[i] = new double[NUM_NT];
		for (int j=0; j<NUM_NT; j++) avg_quality[i][j] = 0;
	}
	
	//For each read we count the number of kmers
	for(int i=0; i<N; ++i){
		SeqRecord rec = rec_gen.next();
		string seq = rc_flag ? rec.seq() + rec.rc().seq() : rec.seq();
		freq[i] = freq[0] + i*L;

		//Calculate frequencies of individual bases
		freq_1[i] = freq_1[0] + i*NUM_NT;
		fill_overlap_count_vector(seq, rec.qual(), 1, freq_1[i], 
								  quality_1[i], false, pseudocount, 
								  avg_quality_1, NULL, NULL, false);
		
		//Calculate frequencies of kmers
		fill_overlap_count_vector(seq, rec.qual(), K, freq[i], quality[i],
								normalize, pseudocount, NULL, avg_quality, 
								freq_1[i], redistribute);
	}
	
	if (verbose_level>0){
		cerr<<"Read counts calculated\n";
	}

	
	//Compute the expected quality of each kmer
	double *expected_qual = NULL;
	if (e_method != 0) {
		expected_qual = new double[L];
		calculate_quality_expected_value(e_method, N, K, L, freq, quality,
						freq_1, avg_quality_1, avg_quality, expected_qual);
	}
	
	//Expected frequancy of each kmer
	double *expected_freq = NULL;
	//Instantiate the vector only if p_method is global (P1G or P2G)
	if (p_method==2 || p_method==3) expected_freq = new double[L];
	
	//P1G Average frequency of every word over the entire dataset
	if (p_method==2)
		expected_frequency_p1global(N, K, L, expected_freq, freq);
	
	//P2G Markovian model based on average frequency of single bases
	if (p_method==3)
		expected_frequency_p2global(N, K, L, expected_freq, freq_1);
	

	
	
	// whiten if requested; in this case reset the distance to euclidean L2
	if (normalize_matrix_flag){
		dist_type = 'e';
		normalize_freq_matrix(freq, quality, N, L);
	}
	if (verbose_level > 0){
		cerr<<"Word frequencies calculated\n";
	}


	// hard EM clustering
	int* assignment = new int[N];
	double* Z = new double[num_clusters * N];
		if (verbose_level > 0) {
			cerr<<"Running regular EM clustering "<<num_trials<<" times "
			"to chose the best partitioning"<<endl;
		}
		num_clusters = hard_em(num_clusters, N, L, freq, quality, expected_qual, 
			quality_1, expected_freq, NUM_NT, freq_1, assignment, Z, num_trials, 
			dist_type, verbose_level);
		
	if (verbose_level > 0){
		cerr<<"Clustering done\n";
	}

	// release memory previously allocated for frequency data
	delete[] freq[0];
	delete[] freq;
	delete[] freq_1[0];
	delete[] freq_1;
	
	for(int i=0; i<N; i++) {
		delete[] quality[i];
		delete[] quality_1[i];
	}
	for(int i=0; i<L; i++)
		delete[] avg_quality[i];
	delete[] quality;
	delete[] quality_1;
	delete[] avg_quality_1;
	delete[] avg_quality;
	if (p_method==2 || p_method==3) delete [] expected_freq;
	if (e_method != 0) delete[] expected_qual;

	// reassign cluster names so that they are sorted 
	// in the descending order of the number of members
	int* num_members = new int[num_clusters];
	int* ix = new int[num_clusters];
	int* rix = new int[num_clusters];
	for (int i=0; i<num_clusters; ++i){
		*(num_members + i) = 0;
		*(ix + i) = i;
	}
	for (int i=0; i<N; ++i){
		num_members[assignment[i]]++;
	}
	for (int i=0; i<num_clusters; ++i){
		int max_pos = i;
		for (int j=i+1; j<num_clusters; ++j){
			if (num_members[ix[j]] > num_members[ix[max_pos]]) {
				max_pos = j;
			}
		}
		int tmp = ix[i];
		ix[i] = ix[max_pos];
		ix[max_pos] = tmp;
	}
	for (int i=0; i<num_clusters; ++i){
		rix[ix[i]] = i;
	}
	for (int i=0; i<N; ++i) {
		*(assignment + i) = *(rix + *(assignment + i));
	}
	delete[] num_members;
	//delete[] ix and rix later

	cout.setf(ios_base::fixed);
	cout.precision(4);

	// output assignment to stdout
	RecordGenerator rec_gen_2(fastq_file_name);
	for(int n=0; n<N; ++n){
		cout<<rec_gen_2.next().id()<<"\t"<<*(assignment+n);
		cout<<endl;
	}
	delete[] ix;
	delete[] rix;

	// write sequences to individual files if requested
	if (write_flag) {
		vector<SeqRecord> rec_vec;
		FastqRead(fastq_file_name, rec_vec);
		int N = rec_vec.size();
		char fname[256];
		for (int i=0; i<num_clusters; ++i){
			sprintf(fname, "part_%i.fastq", i+1);
			ofstream ofs(fname);
			for (int j=0; j<N; ++j) {
				if (*(assignment + j) == i) {
					ofs<<"@"<<rec_vec[j].desc()<<endl;
					ofs<<rec_vec[j].seq()<<endl;
					ofs<<"+"<<endl;
					ofs<<rec_vec[j].qual()<<endl;
				}
			}
		}
	}

	// free allocated memory
	delete[] Z;
	delete[] assignment;
	return EXIT_SUCCESS;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x9b8, %rsp            # imm = 0x9B8
movq %rsi, %rbx
movl %edi, %ebp
movq $0x0, 0xd0(%rsp)
xorl %edi, %edi
callq 0x21c0
movq %rax, 0x10(%rsp)
pushq $0x5
popq %rax
movl %eax, 0x54(%rsp)
movb $0x65, 0x7(%rsp)
pushq $0x2
popq %rdx
movb $0x1, %al
movl %eax, 0x98(%rsp)
pushq $0x1
popq %rcx
movsd 0x49f7(%rip), %xmm0     # 0x7008
movsd %xmm0, 0x28(%rsp)
leaq 0x53cd(%rip), %r13      # 0x79eb
leaq 0x49fb(%rip), %r14      # 0x7020
movq 0x898c(%rip), %r15      # 0xafb8
leaq 0x4a05(%rip), %r12      # 0x7038
movl $0x0, %eax
movq %rax, 0x20(%rsp)
movl $0x0, %eax
movq %rax, 0x78(%rsp)
movq $0x0, 0x80(%rsp)
movq %rcx, 0x70(%rsp)
movl %ecx, 0xc(%rsp)
movl %edx, 0x8c(%rsp)
movq $0x0, 0xd8(%rsp)
movl %edx, 0x40(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x2070
leal -0x63(%rax), %ecx
cmpl $0x14, %ecx
ja 0x269f
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movq (%r15), %rdi
callq 0x22c0
movl %eax, 0x54(%rsp)
jmp 0x2673
leal -0x4e(%rax), %ecx
cmpl $0x5, %ecx
ja 0x27b0
movslq (%r14,%rcx,4), %rax
addq %r14, %rax
jmpq *%rax
movq (%r15), %rdi
callq 0x22c0
movl %eax, 0x8c(%rsp)
jmp 0x2673
movb $0x1, %al
movq %rax, 0xd0(%rsp)
jmp 0x2673
movq 0x20(%rsp), %rax
incl %eax
movq %rax, 0x20(%rsp)
jmp 0x2673
movq (%r15), %rdi
callq 0x22c0
movl %eax, 0xc(%rsp)
jmp 0x2673
movq (%r15), %rdi
callq 0x22c0
cmpl $0x2, %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cmovll %ecx, %eax
leaq 0x8ad1(%rip), %rcx      # 0xb1d8
movl %eax, (%rcx)
jmp 0x2673
movq (%r15), %rax
movb (%rax), %al
movb %al, 0x7(%rsp)
jmp 0x2673
movq (%r15), %rdi
callq 0x22c0
movl %eax, 0x40(%rsp)
jmp 0x2673
movb $0x1, %al
movq %rax, 0x80(%rsp)
jmp 0x2673
movb $0x1, %al
movq %rax, 0xd8(%rsp)
jmp 0x2673
movq (%r15), %rdi
callq 0x2240
movsd %xmm0, 0x28(%rsp)
jmp 0x2673
movq (%r15), %rdi
callq 0x22c0
movq %rax, 0x78(%rsp)
jmp 0x2673
movl $0x0, 0x98(%rsp)
jmp 0x2673
movq (%r15), %rdi
callq 0x22c0
movq %rax, 0x10(%rsp)
jmp 0x2673
movq (%r15), %rdi
callq 0x22c0
leal -0x4(%rax), %ecx
cmpl $-0x3, %ecx
pushq $0x2
popq %rcx
cmovbl %ecx, %eax
movq %rax, 0x70(%rsp)
jmp 0x2673
cmpl $-0x1, %eax
je 0x27d2
cmpl $0x3f, %eax
jne 0x2673
jmp 0x285c
movq (%rbx), %rdi
callq 0x256c
xorl %eax, %eax
jmp 0x2867
xorl %r14d, %r14d
cmpb $0x61, 0x7(%rsp)
movq 0x70(%rsp), %rax
cmovnel %r14d, %eax
movq %rax, 0x70(%rsp)
movl 0xc(%rsp), %eax
cmovnel %r14d, %eax
movl %eax, 0xc(%rsp)
movq 0x78(%rsp), %rdx
cmpl $0x1, %edx
adcl $0x0, %edx
movq 0x87ca(%rip), %rax      # 0xafd0
movslq (%rax), %rax
leal 0x1(%rax), %ecx
cmpl %ebp, %ecx
jne 0x2841
movq %rdx, 0x78(%rsp)
movq (%rbx,%rax,8), %rbx
movq 0x10(%rsp), %rdi
callq 0x21d0
movl 0x40(%rsp), %eax
testl %eax, %eax
cmovgl %eax, %r14d
pushq $0x1
popq %rax
movl %eax, 0x8(%rsp)
subl $0x1, %r14d
jb 0x2879
shll $0x2, 0x8(%rsp)
jmp 0x2834
movq 0x8780(%rip), %rdi      # 0xafc8
leaq 0x51ba(%rip), %rsi      # 0x7a09
callq 0x21e0
movq %rax, %rdi
callq 0x2100
movq (%rbx), %rdi
callq 0x256c
pushq $0x1
popq %rax
addq $0x9b8, %rsp            # imm = 0x9B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x170(%rsp), %rdi
leaq 0x768(%rsp), %rdx
movq %rbx, %rsi
callq 0x35b0
leaq 0x170(%rsp), %rdi
callq 0x5e6c
movq %rax, 0x18(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x20f0
cmpl $0x0, 0x20(%rsp)
jle 0x28e6
movq 0x8732(%rip), %rdi      # 0xaff0
leaq 0x5162(%rip), %rsi      # 0x7a27
callq 0x21e0
movq %rax, %rdi
movq 0x18(%rsp), %rsi
callq 0x2300
leaq 0x5150(%rip), %rsi      # 0x7a2e
movq %rax, %rdi
callq 0x21e0
leaq 0x150(%rsp), %rdi
leaq 0x210(%rsp), %rdx
movq %rbx, %rsi
callq 0x35b0
movq %rbx, 0xc0(%rsp)
leaq 0x768(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x5958
leaq 0x150(%rsp), %rdi
callq 0x20f0
movq 0x18(%rsp), %r15
movslq %r15d, %rax
movq %rax, 0xe0(%rsp)
leaq (,%rax,8), %rbx
testl %r15d, %r15d
pushq $-0x1
popq %r14
cmovsq %r14, %rbx
movq %rbx, %rdi
callq 0x2030
movq %rax, 0x30(%rsp)
movl %r15d, %eax
imull 0x8(%rsp), %eax
cltq
leaq (,%rax,8), %rdi
testl %eax, %eax
cmovsq %r14, %rdi
callq 0x2030
movq 0x30(%rsp), %rcx
movq %rax, (%rcx)
movq %rbx, %rdi
callq 0x2030
movq %rax, 0x48(%rsp)
movl 0x8(%rsp), %eax
movq %rax, 0xc8(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x58(%rsp)
xorl %r14d, %r14d
movq 0x18(%rsp), %rcx
testl %ecx, %ecx
movl $0x0, %eax
cmovgl %ecx, %eax
movq %rax, 0x10(%rsp)
cmpq %r14, 0x10(%rsp)
je 0x29d9
movq 0x58(%rsp), %rdi
callq 0x2030
movq 0x48(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
jmp 0x29ba
movq %rbx, %rdi
callq 0x2030
movq %rax, 0x38(%rsp)
movq 0x18(%rsp), %rcx
leal (,%rcx,4), %eax
movslq %eax, %rdi
shlq $0x3, %rdi
testl %ecx, %ecx
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2030
movq 0x38(%rsp), %rcx
movq %rax, (%rcx)
movq %rbx, %rdi
callq 0x2030
movq %rax, 0x68(%rsp)
xorl %r14d, %r14d
pushq $0x20
popq %rbx
cmpq %r14, 0x10(%rsp)
je 0x2a3f
movq %rbx, %rdi
callq 0x2030
movq 0x68(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
jmp 0x2a22
pushq $0x20
popq %rdi
callq 0x2030
movq %rax, 0x90(%rsp)
xorl %eax, %eax
movq 0x90(%rsp), %rcx
cmpq $0x4, %rax
je 0x2a69
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0x2a59
movq 0x58(%rsp), %rdi
callq 0x2030
movq %rax, 0x60(%rsp)
xorl %r14d, %r14d
pushq $0x20
popq %rbx
cmpq 0xc8(%rsp), %r14
je 0x2ab0
movq %rbx, %rdi
callq 0x2030
movq 0x60(%rsp), %rcx
movq %rax, (%rcx,%r14,8)
xorl %ecx, %ecx
cmpq $0x4, %rcx
je 0x2aab
andq $0x0, (%rax,%rcx,8)
incq %rcx
jmp 0x2a9b
incq %r14
jmp 0x2a7e
movq 0x10(%rsp), %rax
shlq $0x5, %rax
movq %rax, 0xe8(%rsp)
xorl %r12d, %r12d
leaq 0x460(%rsp), %rbp
movzbl 0x98(%rsp), %eax
andl $0x1, %eax
movq %rax, 0x98(%rsp)
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpq %r13, 0xe8(%rsp)
je 0x2cf1
leaq 0x210(%rsp), %rdi
leaq 0x768(%rsp), %rsi
callq 0x59fa
testb $0x1, 0x80(%rsp)
je 0x2b89
leaq 0xf0(%rsp), %rdi
leaq 0x250(%rsp), %rsi
callq 0x2270
leaq 0x568(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x57ee
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x5a8(%rsp), %rsi
callq 0x2270
movq %rbp, %rdi
leaq 0xf0(%rsp), %r14
movq %r14, %rsi
movq %rbx, %rdx
callq 0x35eb
movq %rbx, %rdi
callq 0x20f0
leaq 0x568(%rsp), %rdi
callq 0x5674
movq %r14, %rdi
callq 0x20f0
jmp 0x2b99
movq %rbp, %rdi
leaq 0x250(%rsp), %rsi
callq 0x2270
movq 0x30(%rsp), %rcx
movq (%rcx), %rax
addq %r12, %rax
movq %rax, (%rcx,%r15)
movq 0x38(%rsp), %rcx
movq (%rcx), %rax
addq %r13, %rax
movq %rax, (%rcx,%r15)
leaq 0x1b0(%rsp), %rdi
movq %rbp, %rsi
callq 0x2270
leaq 0x1f0(%rsp), %r14
movq %r14, %rdi
leaq 0x270(%rsp), %rsi
callq 0x2270
movq 0x38(%rsp), %rax
movq (%rax,%r15), %rcx
movq 0x68(%rsp), %rax
movq (%rax,%r15), %r8
subq $0x20, %rsp
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsp)
andl $0x0, 0x18(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, (%rsp)
leaq 0x1d0(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
pushq $0x1
popq %rdx
xorl %r9d, %r9d
movsd 0x48(%rsp), %xmm0
callq 0x4b69
addq $0x20, %rsp
movq %r14, %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x20f0
leaq 0x190(%rsp), %rdi
movq %rbp, %rsi
callq 0x2270
leaq 0x1d0(%rsp), %r14
movq %r14, %rdi
leaq 0x270(%rsp), %rsi
callq 0x2270
movq 0x30(%rsp), %rax
movq (%rax,%r15), %rcx
movq 0x48(%rsp), %rax
movq (%rax,%r15), %r8
leaq 0x190(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movl 0x40(%rsp), %edx
movl 0x8c(%rsp), %r9d
movsd 0x28(%rsp), %xmm0
pushq 0x98(%rsp)
movq 0x40(%rsp), %rax
pushq (%rax,%r15)
pushq 0x70(%rsp)
pushq $0x0
callq 0x4b69
addq $0x20, %rsp
movq %r14, %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x20f0
movq %rbp, %rdi
callq 0x20f0
leaq 0x210(%rsp), %rdi
callq 0x5674
addq $0x20, %r13
addq $0x8, %r15
addq 0x58(%rsp), %r12
jmp 0x2ae5
cmpl $0x0, 0x20(%rsp)
jle 0x2d0b
movq 0x82f1(%rip), %rdi      # 0xaff0
leaq 0x4d34(%rip), %rsi      # 0x7a3a
callq 0x21e0
cmpl $0x0, 0xc(%rsp)
je 0x2d55
movq 0x58(%rsp), %rdi
callq 0x2030
movq %rax, %r13
movl 0xc(%rsp), %edi
movq 0x18(%rsp), %rsi
movl 0x40(%rsp), %edx
movl 0x8(%rsp), %ecx
movq 0x30(%rsp), %r8
movq 0x48(%rsp), %r9
pushq %rax
pushq 0x68(%rsp)
pushq 0xa0(%rsp)
pushq 0x50(%rsp)
callq 0x5027
addq $0x20, %rsp
jmp 0x2d58
xorl %r13d, %r13d
movq 0x70(%rsp), %rax
movl %eax, %ebx
andl $-0x2, %ebx
cmpl $0x2, %ebx
je 0x2d6b
xorl %ebp, %ebp
jmp 0x2d78
movq 0x58(%rsp), %rdi
callq 0x2030
movq %rax, %rbp
movq 0x70(%rsp), %rax
cmpl $0x3, %eax
je 0x2da3
cmpl $0x2, %eax
jne 0x2dbd
movq 0x18(%rsp), %rdi
movl 0x40(%rsp), %esi
movl 0x8(%rsp), %edx
movq %rbp, %rcx
movq 0x30(%rsp), %r8
callq 0x53a4
jmp 0x2dbd
movq 0x18(%rsp), %rdi
movl 0x40(%rsp), %esi
movl 0x8(%rsp), %edx
movq %rbp, %rcx
movq 0x38(%rsp), %r8
callq 0x52d9
testb $0x1, 0xd8(%rsp)
je 0x2de4
movb $0x65, 0x7(%rsp)
movq 0x30(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl 0x8(%rsp), %ecx
callq 0x5407
cmpl $0x0, 0x20(%rsp)
jle 0x2dfe
movq 0x81fe(%rip), %rdi      # 0xaff0
leaq 0x4c59(%rip), %rsi      # 0x7a52
callq 0x21e0
movq 0xe0(%rsp), %rdi
shlq $0x2, %rdi
movq 0x18(%rsp), %r15
testl %r15d, %r15d
pushq $-0x1
popq %r14
cmovsq %r14, %rdi
callq 0x2030
movq %rax, 0x28(%rsp)
movl %r15d, %eax
imull 0x54(%rsp), %eax
cltq
leaq (,%rax,8), %rdi
testl %eax, %eax
cmovsq %r14, %rdi
callq 0x2030
movq %rax, 0x80(%rsp)
cmpl $0x0, 0x20(%rsp)
jle 0x2e87
movq 0x8199(%rip), %rdi      # 0xaff0
leaq 0x4c11(%rip), %rsi      # 0x7a6f
callq 0x21e0
movq %rax, %rdi
movq 0x78(%rsp), %rsi
callq 0x2300
leaq 0x4c17(%rip), %rsi      # 0x7a8e
movq %rax, %rdi
callq 0x21e0
movq %rax, %rdi
callq 0x2100
subq $0x8, %rsp
movsbl 0xf(%rsp), %eax
movl 0x5c(%rsp), %edi
movq 0x20(%rsp), %rsi
movl 0x10(%rsp), %edx
movq 0x38(%rsp), %rcx
movq 0x50(%rsp), %r8
movq %r13, %r9
pushq 0x28(%rsp)
pushq %rax
pushq 0x90(%rsp)
pushq 0xa0(%rsp)
pushq 0x50(%rsp)
pushq 0x68(%rsp)
pushq $0x4
pushq %rbp
pushq 0xb0(%rsp)
callq 0x38e6
addq $0x50, %rsp
movl %eax, %r12d
cmpl $0x0, 0x20(%rsp)
jle 0x2ef5
movq 0x8107(%rip), %rdi      # 0xaff0
leaq 0x4bc4(%rip), %rsi      # 0x7ab4
callq 0x21e0
movq 0x30(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2f07
callq 0x2250
movq 0x30(%rsp), %rdi
callq 0x2250
movq 0x38(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2f23
callq 0x2250
movq 0x38(%rsp), %rdi
callq 0x2250
xorl %r14d, %r14d
cmpq %r14, 0x10(%rsp)
je 0x2f62
movq 0x48(%rsp), %rax
movq (%rax,%r14,8), %rdi
testq %rdi, %rdi
je 0x2f4a
callq 0x2250
movq 0x68(%rsp), %rax
movq (%rax,%r14,8), %rdi
testq %rdi, %rdi
je 0x2f5d
callq 0x2250
incq %r14
jmp 0x2f30
xorl %r14d, %r14d
cmpq %r14, 0xc8(%rsp)
je 0x2f87
movq 0x60(%rsp), %rax
movq (%rax,%r14,8), %rdi
testq %rdi, %rdi
je 0x2f82
callq 0x2250
incq %r14
jmp 0x2f65
movq 0x48(%rsp), %rdi
callq 0x2250
movq 0x68(%rsp), %rdi
callq 0x2250
movq 0x90(%rsp), %rdi
callq 0x2250
movq 0x60(%rsp), %rdi
callq 0x2250
cmpl $0x2, %ebx
jne 0x2fc4
testq %rbp, %rbp
je 0x2fc4
movq %rbp, %rdi
callq 0x2250
cmpl $0x0, 0xc(%rsp)
pushq $-0x1
popq %rbx
je 0x2fdb
testq %r13, %r13
je 0x2fdb
movq %r13, %rdi
callq 0x2250
movl %r12d, %r15d
shlq $0x2, %r15
testl %r12d, %r12d
cmovsq %rbx, %r15
movq %r15, %rdi
callq 0x2030
movq %rax, %r13
movq %r15, %rdi
callq 0x2030
movq %rax, %rbx
movq %r15, %rdi
callq 0x2030
movq %rax, %r15
xorl %eax, %eax
testl %r12d, %r12d
movl $0x0, %r10d
cmovgl %r12d, %r10d
cmpq %rax, %r10
je 0x302c
andl $0x0, (%r13,%rax,4)
movl %eax, (%rbx,%rax,4)
incq %rax
jmp 0x3019
xorl %eax, %eax
cmpq %rax, 0x10(%rsp)
je 0x3048
movq 0x28(%rsp), %rcx
movslq (%rcx,%rax,4), %rcx
incl (%r13,%rcx,4)
incq %rax
jmp 0x302e
pushq $0x1
popq %rax
xorl %ecx, %ecx
cmpq %r10, %rcx
je 0x3092
movq %rax, %rdx
movl %ecx, %esi
movslq %esi, %rdi
cmpl %edx, %r12d
jle 0x307e
movslq (%rbx,%rdx,4), %r8
movl (%r13,%r8,4), %r8d
movslq (%rbx,%rdi,4), %r9
movl %edx, %edi
cmpl (%r13,%r9,4), %r8d
jg 0x3077
movl %esi, %edi
incq %rdx
movl %edi, %esi
jmp 0x3057
movl (%rbx,%rcx,4), %edx
movl (%rbx,%rdi,4), %esi
movl %esi, (%rbx,%rcx,4)
incq %rcx
movl %edx, (%rbx,%rdi,4)
incq %rax
jmp 0x304d
xorl %eax, %eax
cmpq %rax, %r10
je 0x30a6
movslq (%rbx,%rax,4), %rcx
movl %eax, (%r15,%rcx,4)
incq %rax
jmp 0x3094
xorl %eax, %eax
movq 0x28(%rsp), %rdx
cmpq %rax, 0x10(%rsp)
je 0x30c4
movslq (%rdx,%rax,4), %rcx
movl (%r15,%rcx,4), %ecx
movl %ecx, (%rdx,%rax,4)
incq %rax
jmp 0x30ad
movq %r10, 0x40(%rsp)
movq %r13, %rdi
callq 0x2250
movq 0x7ef0(%rip), %rax      # 0xafc8
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
orl $0x4, 0x18(%rax,%rdx)
movq -0x18(%rcx), %rcx
movq $0x4, 0x8(%rax,%rcx)
leaq 0x130(%rsp), %rdi
leaq 0x568(%rsp), %rdx
movq 0xc0(%rsp), %rsi
callq 0x35b0
leaq 0x210(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x5958
leaq 0x130(%rsp), %rdi
callq 0x20f0
xorl %r14d, %r14d
leaq 0x568(%rsp), %r12
leaq 0x460(%rsp), %rbp
movq 0x7e7e(%rip), %r13      # 0xafc8
cmpq %r14, 0x10(%rsp)
je 0x31b4
movq %r12, %rdi
leaq 0x210(%rsp), %rsi
callq 0x59fa
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2270
movq %r13, %rdi
movq %rbp, %rsi
callq 0x21b0
movq %rax, %rdi
leaq 0x4944(%rip), %rsi      # 0x7ac5
callq 0x21e0
movq 0x28(%rsp), %rcx
movl (%rcx,%r14,4), %esi
movq %rax, %rdi
callq 0x2300
movq %rbp, %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x5674
movq %r13, %rdi
callq 0x2100
incq %r14
jmp 0x314a
movq %rbx, %rdi
callq 0x2250
movq %r15, %rdi
callq 0x2250
testb $0x1, 0xd0(%rsp)
je 0x3399
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
andq $0x0, 0xb0(%rsp)
leaq 0x110(%rsp), %rdi
leaq 0x568(%rsp), %rdx
movq 0xc0(%rsp), %rsi
callq 0x35b0
leaq 0x110(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x5d76
leaq 0x110(%rsp), %rdi
callq 0x20f0
movq 0xa8(%rsp), %rcx
subq 0xa0(%rsp), %rcx
shrq $0x7, %rcx
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
movq %rcx, 0x20(%rsp)
leaq 0x568(%rsp), %r12
leaq 0xf0(%rsp), %rbx
xorl %ebp, %ebp
cmpl 0x40(%rsp), %ebp
je 0x338c
leal 0x1(%rbp), %edx
leaq 0x460(%rsp), %r14
movq %r14, %rdi
leaq 0x4851(%rip), %rsi      # 0x7ac7
movl %edx, 0x10(%rsp)
xorl %eax, %eax
callq 0x2050
movq %r12, %rdi
movq %r14, %rsi
pushq $0x10
popq %rdx
callq 0x2220
pushq $0x60
popq %r14
xorl %r13d, %r13d
cmpq %r13, 0x20(%rsp)
je 0x3379
movq 0x28(%rsp), %rax
cmpl %ebp, (%rax,%r13,4)
jne 0x336d
movq %r12, %rdi
leaq 0x481b(%rip), %rsi      # 0x7ad5
callq 0x21e0
movq %rax, %r15
movq 0xa0(%rsp), %rax
leaq (%rax,%r14), %rsi
addq $-0x40, %rsi
movq %rbx, %rdi
callq 0x2270
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21b0
movq %rax, %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x20f0
movq 0xa0(%rsp), %rax
leaq (%rax,%r14), %rsi
addq $-0x20, %rsi
movq %rbx, %rdi
callq 0x2270
movq %r12, %rdi
movq %rbx, %rsi
callq 0x21b0
movq %rax, %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x20f0
movq %r12, %rdi
leaq 0x47a5(%rip), %rsi      # 0x7ad7
callq 0x21e0
movq %rax, %rdi
callq 0x2100
movq 0xa0(%rsp), %rsi
addq %r14, %rsi
movq %rbx, %rdi
callq 0x2270
movq %r12, %rdi
movq %rbx, %rsi
callq 0x21b0
movq %rax, %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x20f0
incq %r13
subq $-0x80, %r14
jmp 0x3296
movq %r12, %rdi
callq 0x22a0
movl 0x10(%rsp), %eax
movl %eax, %ebp
jmp 0x3257
leaq 0xa0(%rsp), %rdi
callq 0x3652
movq 0x80(%rsp), %rdi
callq 0x2250
movq 0x28(%rsp), %rdi
callq 0x2250
leaq 0x210(%rsp), %rdi
callq 0x59d4
leaq 0x768(%rsp), %rdi
callq 0x59d4
jmp 0x27cb
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x20f0
jmp 0x3580
jmp 0x3470
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0x20f0
jmp 0x359a
jmp 0x350e
jmp 0x350e
jmp 0x350e
jmp 0x350e
jmp 0x350e
jmp 0x350e
jmp 0x350e
jmp 0x350e
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
jmp 0x3440
jmp 0x344a
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
callq 0x20f0
jmp 0x35a7
movq %rax, %rbx
jmp 0x35a7
jmp 0x350e
jmp 0x350e
jmp 0x350e
jmp 0x350e
jmp 0x350e
jmp 0x350e
movq %rax, %rbx
jmp 0x3580
jmp 0x347f
movq %rax, %rbx
jmp 0x349c
movq %rax, %rbx
jmp 0x3526
movq %rax, %rbx
jmp 0x34a9
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x20f0
leaq 0x568(%rsp), %rdi
callq 0x5674
leaq 0xf0(%rsp), %rdi
jmp 0x3521
jmp 0x34b5
movq %rax, %rbx
jmp 0x358d
movq %rax, %rbx
jmp 0x3545
movq %rax, %rbx
jmp 0x34dc
jmp 0x350e
movq %rax, %rbx
leaq 0x1d0(%rsp), %rdi
callq 0x20f0
leaq 0x190(%rsp), %rdi
jmp 0x3503
movq %rax, %rbx
jmp 0x34fb
movq %rax, %rbx
leaq 0x1f0(%rsp), %rdi
callq 0x20f0
leaq 0x1b0(%rsp), %rdi
callq 0x20f0
jmp 0x3519
jmp 0x350e
jmp 0x350e
movq %rax, %rbx
jmp 0x359a
movq %rax, %rbx
leaq 0x460(%rsp), %rdi
callq 0x20f0
leaq 0x210(%rsp), %rdi
callq 0x5674
jmp 0x359a
movq %rax, %rbx
leaq 0x460(%rsp), %rdi
callq 0x20f0
leaq 0x568(%rsp), %rdi
callq 0x5674
jmp 0x358d
jmp 0x3570
jmp 0x3570
jmp 0x3570
jmp 0x355e
jmp 0x355e
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x20f0
jmp 0x3573
movq %rax, %rbx
leaq 0x568(%rsp), %rdi
callq 0x22a0
leaq 0xa0(%rsp), %rdi
callq 0x3652
leaq 0x210(%rsp), %rdi
callq 0x59d4
leaq 0x768(%rsp), %rdi
callq 0x59d4
movq %rbx, %rdi
callq 0x2320
nop