// File: akdess[P]BAFExtract/src/main.cpp
// Function: main
int main(int argc, char* argv[])
{
	if (argc < 3)
	{
		fprintf(stderr, "USAGE: %s [Options] [Arguments]\n\
Options:\n\
	-preprocess_FASTA [FASTA file path] [Output firectory]\n\
	-generate_compressed_pileup_per_SAM [SAM file path (\"stdin\" for piping from samtools)] [Chromosome Ids/lengths file path] [Output directory] [Minimum mapping quality] [Minimum base quality]\n\
	-get_SNVs_per_pileup [chromosome info file path] [Pileup directory] [Binary sequences directory] [Min coverage per SNV (20)] [Min MAF covg per SNV (4)] [Min MAF (0.2)] [Output file path]\n", argv[0]);
		exit(0);
	}

	if (strcmp(argv[1], "-preprocess_FASTA") == 0)
	{
		if (argc != 4)
		{
			fprintf(stderr, "USAGE: %s -preprocess_FASTA [FASTA file path] [Output firectory]\n", argv[0]);
			exit(0);
		}

		char* fasta_fp = argv[2];
		char* bin_dir = argv[3];

		printf("Binarizing %s.\n", fasta_fp);
		FILE* f_fasta = open_f(fasta_fp, "r");

		char* cur_line = NULL;
		int buff_len = 2000 * 1000 * 1000;
		char* cur_entry_buffer = new char[buff_len];
		int cur_entry_i = 1;
		char cur_entry_id[1000];

		char chr_ids_fp[1000];
		sprintf(chr_ids_fp, "%s/chr_ids.txt", bin_dir);
		FILE* f_chr_ids = open_f(chr_ids_fp, "w");

		while (1)
		{
			// Process the current buffer.
			cur_line = getline(f_fasta);

			if (cur_line == NULL)
			{
				// File ended, dump the last entry if there are values in it.
				if (cur_entry_i > 1)
				{
					char cur_entry_bin_fp[1000];
					normalize_chr_id(cur_entry_id);
					sprintf(cur_entry_bin_fp, "%s/%s.bin", bin_dir, cur_entry_id);

					fprintf(f_chr_ids, "%s\n", cur_entry_id);

					FILE* f_bin = open_f(cur_entry_bin_fp, "wb");

					// Open the new binary file.
					fprintf(stderr, "Dumping %s (%d)\n", cur_entry_id, cur_entry_i);

					// Dump the sequence buffer.
					fwrite(&cur_entry_i, sizeof(int), 1, f_bin);
					fwrite(cur_entry_buffer, sizeof(char), cur_entry_i, f_bin);

					// Close current file.
					fclose(f_bin);
				}
				break;
			}
			else if (cur_line[0] == '>')
			{
				if (cur_entry_i > 1)
				{
					char cur_entry_bin_fp[1000];
					normalize_chr_id(cur_entry_id);
					sprintf(cur_entry_bin_fp, "%s/%s.bin", bin_dir, cur_entry_id);

					fprintf(f_chr_ids, "%s\n", cur_entry_id);

					FILE* f_bin = open_f(cur_entry_bin_fp, "wb");

					// Open the new binary file.
					fprintf(stderr, "Dumping %s (%d)\n", cur_entry_id, cur_entry_i);

					// Dump the sequence buffer.
					fwrite(&cur_entry_i, sizeof(int), 1, f_bin);
					fwrite(cur_entry_buffer, sizeof(char), cur_entry_i, f_bin);

					// Close current file.
					fclose(f_bin);
				}

				// Update the id, reset the counter.
				strcpy(cur_entry_id, &(cur_line[1]));
				cur_entry_i = 1;
			}
			else
			{
				// Concatenate the current sequence line.
				int l_cur_line = t_string::string_length(cur_line);
				for (int i = 0; i < l_cur_line; i++)
				{
					cur_entry_buffer[cur_entry_i] = cur_line[i];
					cur_entry_i++;
				} // i loop.
			}

			delete[] cur_line;
		} // file reading loop.

		fclose(f_fasta);
		fclose(f_chr_ids);
		delete[] cur_entry_buffer;
	} // -preprocess_FASTA option.	
	else if (t_string::compare_strings(argv[1], "-generate_compressed_pileup_per_SAM"))
	{
		if (argc != 7)
		{
			fprintf(stderr, "USAGE: %s -generate_compressed_pileup_per_SAM [SAM file path (\"stdin\" for piping from samtools)] [Chromosome Ids/lengths file path] [Output directory] [Minimum mapping quality] [Minimum base quality]\n", argv[0]);
			exit(0);
		}

		char* sam_fp = argv[2];
		char* chr_ids_lengths_list_fp = argv[3];
		char* op_dir = argv[4];
		int min_mapp_qual = atoi(argv[5]);
		int min_base_qual = atoi(argv[6]);

		vector<char*>* chr_ids = new vector<char*>();
		vector<int>* chr_lengths = new vector<int>();
		load_chromosome_lengths_per_tabbed_file(chr_ids_lengths_list_fp, chr_ids, chr_lengths);

		int n_processed_reads = 0;
		dump_nucleotide_pileup_per_SAM_file(sam_fp, chr_ids, chr_lengths, op_dir, min_mapp_qual, min_base_qual, n_processed_reads);
	} // -generate_compressed_pileup_per_SAM	
	else if (t_string::compare_strings(argv[1], "-get_SNVs_per_pileup"))
	{
		if (argc != 9)
		{
			fprintf(stderr, "USAGE: %s -get_SNVs_per_pileup [chromosome info file path] [Pileup directory] [Binary sequences directory] [Min coverage per SNV (20)] [Min MAF covg per SNV (4)] [Min MAF (0.2)] [Output file path]\n", argv[0]);
			exit(0);
		}

		char* chr_info_fp = argv[2];
		char* pileup_dir = argv[3];
		char* bin_seq_dir = argv[4];
		int min_covg = atoi(argv[5]);
		int min_alternate_covg = atoi(argv[6]);
		double min_alternate_freq = atof(argv[7]);
		char* op_fp = argv[8];

		fprintf(stderr, "Calling SNVs with minimum %d total and %d alternate read coverage and %.3f min alternate frequency.\n", min_covg, min_alternate_covg, min_alternate_freq);

		vector<char*>* chr_ids = new vector<char*>();
		vector<int>* chr_lengths = new vector<int>();

		int* nuc_2_num_array = get_per_char_as_nuc_2_num_coding_array();
		load_chromosome_lengths_per_tabbed_file(chr_info_fp, chr_ids, chr_lengths);

		FILE* f_op = open_f(op_fp, "w");
		for (int i_chr = 0; i_chr < chr_ids->size(); i_chr++)
		{
			fprintf(stderr, "Procesing %s\n", chr_ids->at(i_chr));

			int l_cur_chr_seq = 0;
			char cur_chr_bin_fp[1000];
			sprintf(cur_chr_bin_fp, "%s/%s.bin", bin_seq_dir, chr_ids->at(i_chr));
			char* cur_chr_seq = load_binary_sequence_file(cur_chr_bin_fp, l_cur_chr_seq);

			char cur_chr_pileup_fp[1000];
			sprintf(cur_chr_pileup_fp, "%s/%s_allele_counts.bin", pileup_dir, chr_ids->at(i_chr));
			if (!check_file(cur_chr_pileup_fp))
			{
				sprintf(cur_chr_pileup_fp, "%s/%s_allele_counts.bin.gz", pileup_dir, chr_ids->at(i_chr));
				if (!check_file(cur_chr_pileup_fp))
				{
					fprintf(stderr, "Could not find %s.\n", cur_chr_pileup_fp);
					exit(0);
				}
			}

			int l_pileup = 0;
			unsigned short** cur_chr_pileup = load_compressed_pileups(cur_chr_pileup_fp, l_pileup);
			fprintf(stderr, "Loaded %d long pileup.\n", l_pileup);

			char per_num_nucs[] = "ACGTN";

			for (int i = 1; i <= l_pileup; i++)
			{
				int cur_total_covg = 0;
				int max_alternate_cnt = 0;
				int max_alt_allele_i = -1;
				for (int i_all = 0; i_all < 4; i_all++)
				{
					cur_total_covg += cur_chr_pileup[i_all][i];

					bool is_alternate_allele = (nuc_2_num_array[cur_chr_seq[i]] != i_all);
					if (is_alternate_allele &&
						cur_chr_pileup[i_all][i] > min_alternate_covg &&
						max_alternate_cnt < cur_chr_pileup[i_all][i])
					{
						max_alternate_cnt = cur_chr_pileup[i_all][i];
						max_alt_allele_i = i_all;
					}
				} // i_all loop.

				if (cur_total_covg < min_covg)
				{
					continue;
				}

				double cur_alternate_freq = (double)(max_alternate_cnt) / (double)(cur_total_covg);
				if (cur_alternate_freq < min_alternate_freq)
				{
					continue;
				}

				fprintf(f_op, "%s\t%d\t%c\t%c\t%d\t%d\n", chr_ids->at(i_chr), i,
					cur_chr_seq[i], per_num_nucs[max_alt_allele_i],
					max_alternate_cnt, cur_total_covg);
			} // i loop.

			  // Free memory.
			delete_pileup(cur_chr_pileup);

			// Free sequence memory.
			delete[] cur_chr_seq;
		} // i_chr loop.

		fclose(f_op);
	} // -get_SNVs_per_pileup option.
}

// Assembly:
subq $0x1958, %rsp           # imm = 0x1958
movl $0x0, 0x1954(%rsp)
movl %edi, 0x1950(%rsp)
movq %rsi, 0x1948(%rsp)
cmpl $0x3, 0x1950(%rsp)
jge 0x41d5
movq 0x16e2e(%rip), %rax     # 0x1afe0
movq (%rax), %rdi
movq 0x1948(%rsp), %rax
movq (%rax), %rdx
leaq 0x10299(%rip), %rsi     # 0x14460
movb $0x0, %al
callq 0x2240
xorl %edi, %edi
callq 0x21d0
movq 0x1948(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x10455(%rip), %rsi     # 0x1463d
callq 0x2220
cmpl $0x0, %eax
jne 0x461f
cmpl $0x4, 0x1950(%rsp)
je 0x422a
movq 0x16dd9(%rip), %rax     # 0x1afe0
movq (%rax), %rdi
movq 0x1948(%rsp), %rax
movq (%rax), %rdx
leaq 0x10433(%rip), %rsi     # 0x1464f
movb $0x0, %al
callq 0x2240
xorl %edi, %edi
callq 0x21d0
movq 0x1948(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x1940(%rsp)
movq 0x1948(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x1938(%rsp)
movq 0x1940(%rsp), %rsi
leaq 0x10430(%rip), %rdi     # 0x14691
movb $0x0, %al
callq 0x2050
movq 0x1940(%rsp), %rdi
leaq 0xfd93(%rip), %rsi      # 0x1400a
callq 0x6f40
movq %rax, 0x1930(%rsp)
movq $0x0, 0x1928(%rsp)
movl $0x77359400, 0x1924(%rsp) # imm = 0x77359400
movslq 0x1924(%rsp), %rdi
callq 0x2040
movq %rax, 0x1918(%rsp)
movl $0x1, 0x1914(%rsp)
leaq 0x1130(%rsp), %rdi
movq 0x1938(%rsp), %rdx
leaq 0x103cf(%rip), %rsi     # 0x146a1
movb $0x0, %al
callq 0x2070
leaq 0x1130(%rsp), %rdi
leaq 0x103c8(%rip), %rsi     # 0x146b0
callq 0x6f40
movq %rax, 0x1128(%rsp)
movq 0x1930(%rsp), %rdi
callq 0x6cd0
movq %rax, 0x1928(%rsp)
cmpq $0x0, 0x1928(%rsp)
jne 0x440e
cmpl $0x1, 0x1914(%rsp)
jle 0x4409
leaq 0x1520(%rsp), %rdi
callq 0x25b0
leaq 0xd40(%rsp), %rdi
movq 0x1938(%rsp), %rdx
leaq 0x1520(%rsp), %rcx
leaq 0x1035f(%rip), %rsi     # 0x146b2
movb $0x0, %al
callq 0x2070
movq 0x1128(%rsp), %rdi
leaq 0x1520(%rsp), %rdx
leaq 0x1005d(%rip), %rsi     # 0x143ce
movb $0x0, %al
callq 0x2240
leaq 0xd40(%rsp), %rdi
leaq 0xfd19(%rip), %rsi      # 0x140a0
callq 0x6f40
movq %rax, 0xd38(%rsp)
movq 0x16c45(%rip), %rax     # 0x1afe0
movq (%rax), %rdi
leaq 0x1520(%rsp), %rdx
movl 0x1914(%rsp), %ecx
leaq 0x10308(%rip), %rsi     # 0x146bc
movb $0x0, %al
callq 0x2240
movq 0xd38(%rsp), %rcx
leaq 0x1914(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x2310
movq 0x1918(%rsp), %rdi
movslq 0x1914(%rsp), %rdx
movq 0xd38(%rsp), %rcx
movl $0x1, %esi
callq 0x2310
movq 0xd38(%rsp), %rdi
callq 0x2170
jmp 0x45dd
movq 0x1928(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x3e, %eax
jne 0x4538
cmpl $0x1, 0x1914(%rsp)
jle 0x4512
leaq 0x1520(%rsp), %rdi
callq 0x25b0
leaq 0x950(%rsp), %rdi
movq 0x1938(%rsp), %rdx
leaq 0x1520(%rsp), %rcx
leaq 0x10256(%rip), %rsi     # 0x146b2
movb $0x0, %al
callq 0x2070
movq 0x1128(%rsp), %rdi
leaq 0x1520(%rsp), %rdx
leaq 0xff54(%rip), %rsi      # 0x143ce
movb $0x0, %al
callq 0x2240
leaq 0x950(%rsp), %rdi
leaq 0xfc10(%rip), %rsi      # 0x140a0
callq 0x6f40
movq %rax, 0x948(%rsp)
movq 0x16b3c(%rip), %rax     # 0x1afe0
movq (%rax), %rdi
leaq 0x1520(%rsp), %rdx
movl 0x1914(%rsp), %ecx
leaq 0x101ff(%rip), %rsi     # 0x146bc
movb $0x0, %al
callq 0x2240
movq 0x948(%rsp), %rcx
leaq 0x1914(%rsp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x2310
movq 0x1918(%rsp), %rdi
movslq 0x1914(%rsp), %rdx
movq 0x948(%rsp), %rcx
movl $0x1, %esi
callq 0x2310
movq 0x948(%rsp), %rdi
callq 0x2170
leaq 0x1520(%rsp), %rdi
movq 0x1928(%rsp), %rsi
addq $0x1, %rsi
callq 0x2150
movl $0x1, 0x1914(%rsp)
jmp 0x45b3
movq 0x1928(%rsp), %rdi
callq 0x87e0
movl %eax, 0x944(%rsp)
movl $0x0, 0x940(%rsp)
movl 0x940(%rsp), %eax
cmpl 0x944(%rsp), %eax
jge 0x45b1
movq 0x1928(%rsp), %rax
movslq 0x940(%rsp), %rcx
movb (%rax,%rcx), %dl
movq 0x1918(%rsp), %rax
movslq 0x1914(%rsp), %rcx
movb %dl, (%rax,%rcx)
movl 0x1914(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1914(%rsp)
movl 0x940(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x940(%rsp)
jmp 0x4557
jmp 0x45b3
jmp 0x45b5
movq 0x1928(%rsp), %rax
movq %rax, 0x90(%rsp)
cmpq $0x0, %rax
je 0x45d8
movq 0x90(%rsp), %rdi
callq 0x2200
jmp 0x42f5
movq 0x1930(%rsp), %rdi
callq 0x2170
movq 0x1128(%rsp), %rdi
callq 0x2170
movq 0x1918(%rsp), %rax
movq %rax, 0x88(%rsp)
cmpq $0x0, %rax
je 0x461a
movq 0x88(%rsp), %rdi
callq 0x2200
jmp 0x4e53
movq 0x1948(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x1009b(%rip), %rsi     # 0x146cd
callq 0x8e50
testb $0x1, %al
jne 0x4640
jmp 0x47c1
cmpl $0x7, 0x1950(%rsp)
je 0x4674
movq 0x1698f(%rip), %rax     # 0x1afe0
movq (%rax), %rdi
movq 0x1948(%rsp), %rax
movq (%rax), %rdx
leaq 0x1008b(%rip), %rsi     # 0x146f1
movb $0x0, %al
callq 0x2240
xorl %edi, %edi
callq 0x21d0
movq 0x1948(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x938(%rsp)
movq 0x1948(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x930(%rsp)
movq 0x1948(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x928(%rsp)
movq 0x1948(%rsp), %rax
movq 0x28(%rax), %rdi
callq 0x2280
movl %eax, 0x924(%rsp)
movq 0x1948(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0x2280
movl %eax, 0x920(%rsp)
movl $0x18, %edi
callq 0x2180
movq %rax, %rdi
movq %rdi, 0x78(%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq 0x78(%rsp), %rdi
callq 0x4fd0
movq 0x78(%rsp), %rax
movq %rax, 0x918(%rsp)
movl $0x18, %edi
callq 0x2180
movq %rax, %rdi
movq %rdi, 0x80(%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq 0x80(%rsp), %rdi
callq 0x4fe0
movq 0x80(%rsp), %rax
movq %rax, 0x910(%rsp)
movq 0x930(%rsp), %rdi
movq 0x918(%rsp), %rsi
movq 0x910(%rsp), %rdx
callq 0x2640
movl $0x0, 0x90c(%rsp)
movq 0x938(%rsp), %rdi
movq 0x918(%rsp), %rsi
movq 0x910(%rsp), %rdx
movq 0x928(%rsp), %rcx
movl 0x924(%rsp), %r8d
movl 0x920(%rsp), %r9d
leaq 0x90c(%rsp), %rax
movq %rax, (%rsp)
callq 0x3450
jmp 0x4e51
movq 0x1948(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0xffe6(%rip), %rsi      # 0x147ba
callq 0x8e50
testb $0x1, %al
jne 0x47e2
jmp 0x4e4f
cmpl $0x9, 0x1950(%rsp)
je 0x4816
movq 0x167ed(%rip), %rax     # 0x1afe0
movq (%rax), %rdi
movq 0x1948(%rsp), %rax
movq (%rax), %rdx
leaq 0xffc7(%rip), %rsi      # 0x147cf
movb $0x0, %al
callq 0x2240
xorl %edi, %edi
callq 0x21d0
movq 0x1948(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x900(%rsp)
movq 0x1948(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x8f8(%rsp)
movq 0x1948(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x8f0(%rsp)
movq 0x1948(%rsp), %rax
movq 0x28(%rax), %rdi
callq 0x2280
movl %eax, 0x8ec(%rsp)
movq 0x1948(%rsp), %rax
movq 0x30(%rax), %rdi
callq 0x2280
movl %eax, 0x8e8(%rsp)
movq 0x1948(%rsp), %rax
movq 0x38(%rax), %rdi
callq 0x21f0
movsd %xmm0, 0x8e0(%rsp)
movq 0x1948(%rsp), %rax
movq 0x40(%rax), %rax
movq %rax, 0x8d8(%rsp)
movq 0x16729(%rip), %rax     # 0x1afe0
movq (%rax), %rdi
movl 0x8ec(%rsp), %edx
movl 0x8e8(%rsp), %ecx
movsd 0x8e0(%rsp), %xmm0
leaq 0xffbd(%rip), %rsi      # 0x14895
movb $0x1, %al
callq 0x2240
movl $0x18, %edi
callq 0x2180
movq %rax, %rdi
movq %rdi, 0x68(%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq 0x68(%rsp), %rdi
callq 0x4fd0
movq 0x68(%rsp), %rax
movq %rax, 0x8d0(%rsp)
movl $0x18, %edi
callq 0x2180
movq %rax, %rdi
movq %rdi, 0x70(%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq 0x70(%rsp), %rdi
callq 0x4fe0
movq 0x70(%rsp), %rax
movq %rax, 0x8c8(%rsp)
callq 0x24c0
movq %rax, 0x8c0(%rsp)
movq 0x900(%rsp), %rdi
movq 0x8d0(%rsp), %rsi
movq 0x8c8(%rsp), %rdx
callq 0x2640
movq 0x8d8(%rsp), %rdi
leaq 0xfd2e(%rip), %rsi      # 0x146b0
callq 0x6f40
movq %rax, 0x8b8(%rsp)
movl $0x0, 0x8b4(%rsp)
movslq 0x8b4(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x8d0(%rsp), %rdi
callq 0x4f10
movq %rax, %rcx
movq 0x60(%rsp), %rax
cmpq %rcx, %rax
jae 0x4e42
movq 0x16614(%rip), %rax     # 0x1afe0
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x8d0(%rsp), %rdi
movslq 0x8b4(%rsp), %rsi
callq 0x4f70
movq 0x38(%rsp), %rdi
movq (%rax), %rdx
leaq 0xff02(%rip), %rsi      # 0x148fa
movb $0x0, %al
callq 0x2240
movl $0x0, 0x8b0(%rsp)
leaq 0x4c0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x8f0(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x8d0(%rsp), %rdi
movslq 0x8b4(%rsp), %rsi
callq 0x4f70
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rdx
movq (%rax), %rcx
leaq 0xfc65(%rip), %rsi      # 0x146b2
movb $0x0, %al
callq 0x2070
leaq 0x4c0(%rsp), %rdi
leaq 0x8b0(%rsp), %rsi
callq 0x4070
movq %rax, 0x4b8(%rsp)
leaq 0xd0(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x8f8(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x8d0(%rsp), %rdi
movslq 0x8b4(%rsp), %rsi
callq 0x4f70
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rdx
movq (%rax), %rcx
leaq 0xf7cb(%rip), %rsi      # 0x1427f
movb $0x0, %al
callq 0x2070
leaq 0xd0(%rsp), %rdi
callq 0x6e70
testb $0x1, %al
jne 0x4b54
leaq 0xd0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x8f8(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x8d0(%rsp), %rdi
movslq 0x8b4(%rsp), %rsi
callq 0x4f70
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rdx
movq (%rax), %rcx
leaq 0xfdf5(%rip), %rsi      # 0x14908
movb $0x0, %al
callq 0x2070
leaq 0xd0(%rsp), %rdi
callq 0x6e70
testb $0x1, %al
jne 0x4b52
movq 0x164ae(%rip), %rax     # 0x1afe0
movq (%rax), %rdi
leaq 0xd0(%rsp), %rdx
leaq 0xfddf(%rip), %rsi      # 0x14923
movb $0x0, %al
callq 0x2240
xorl %edi, %edi
callq 0x21d0
jmp 0x4b54
movl $0x0, 0xcc(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0xcc(%rsp), %rsi
callq 0x2760
movq %rax, 0xc0(%rsp)
movq 0x1645d(%rip), %rax     # 0x1afe0
movq (%rax), %rdi
movl 0xcc(%rsp), %edx
leaq 0xfda3(%rip), %rsi      # 0x14937
movb $0x0, %al
callq 0x2240
movl 0xfdae(%rip), %eax      # 0x1494f
movl %eax, 0xba(%rsp)
movw 0xfda4(%rip), %ax       # 0x14953
movw %ax, 0xbe(%rsp)
movl $0x1, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
cmpl 0xcc(%rsp), %eax
jg 0x4e00
movl $0x0, 0xb0(%rsp)
movl $0x0, 0xac(%rsp)
movl $0xffffffff, 0xa8(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0xa4(%rsp)
cmpl $0x4, 0xa4(%rsp)
jge 0x4d20
movq 0xc0(%rsp), %rax
movslq 0xa4(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0xb4(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
addl 0xb0(%rsp), %eax
movl %eax, 0xb0(%rsp)
movq 0x8c0(%rsp), %rax
movq 0x4b8(%rsp), %rcx
movslq 0xb4(%rsp), %rdx
movsbq (%rcx,%rdx), %rcx
movl (%rax,%rcx,4), %eax
cmpl 0xa4(%rsp), %eax
setne %al
andb $0x1, %al
movb %al, 0xa3(%rsp)
testb $0x1, 0xa3(%rsp)
je 0x4d08
movq 0xc0(%rsp), %rax
movslq 0xa4(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0xb4(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
cmpl 0x8e8(%rsp), %eax
jle 0x4d08
movl 0xac(%rsp), %eax
movq 0xc0(%rsp), %rcx
movslq 0xa4(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq 0xb4(%rsp), %rdx
movzwl (%rcx,%rdx,2), %ecx
cmpl %ecx, %eax
jge 0x4d08
movq 0xc0(%rsp), %rax
movslq 0xa4(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0xb4(%rsp), %rcx
movzwl (%rax,%rcx,2), %eax
movl %eax, 0xac(%rsp)
movl 0xa4(%rsp), %eax
movl %eax, 0xa8(%rsp)
jmp 0x4d0a
movl 0xa4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa4(%rsp)
jmp 0x4c02
movl 0xb0(%rsp), %eax
cmpl 0x8ec(%rsp), %eax
jge 0x4d35
jmp 0x4dea
cvtsi2sdl 0xac(%rsp), %xmm0
cvtsi2sdl 0xb0(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x98(%rsp)
movsd 0x98(%rsp), %xmm1
movsd 0x8e0(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x4d6e
jmp 0x4dea
movq 0x8b8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x8d0(%rsp), %rdi
movslq 0x8b4(%rsp), %rsi
callq 0x4f70
movq 0x20(%rsp), %rdi
movq (%rax), %rdx
movl 0xb4(%rsp), %ecx
movq 0x4b8(%rsp), %rax
movslq 0xb4(%rsp), %rsi
movsbl (%rax,%rsi), %r8d
movslq 0xa8(%rsp), %rax
movsbl 0xba(%rsp,%rax), %r9d
movl 0xac(%rsp), %r10d
movl 0xb0(%rsp), %eax
leaq 0xfb7a(%rip), %rsi      # 0x14955
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x2240
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x4bc2
movq 0xc0(%rsp), %rdi
callq 0x4110
movq 0x4b8(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x4e2a
movq 0x18(%rsp), %rdi
callq 0x2200
jmp 0x4e2c
movl 0x8b4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8b4(%rsp)
jmp 0x499a
movq 0x8b8(%rsp), %rdi
callq 0x2170
jmp 0x4e51
jmp 0x4e53
movl 0x1954(%rsp), %eax
addq $0x1958, %rsp           # imm = 0x1958
retq
nopw %cs:(%rax,%rax)
nopl (%rax)