// File: WeiqiangZhou[P]BIRD/source/predict_function.cpp
// Function: WriteWIG(double**, char**, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, char*, int, int, int, int, double, int)
int WriteWIG(double **data_out, char **select_idx, std::vector<std::string> outname, char *outfile, int bin_size, int loci_length, int sample_size, int flag, double up_bound, int flag_log)
{
	char *part;
	char temp_name[255];
	char chrname[10];
	int startsite, count;
	double value;
	FILE * pFile;

	//standard output
	if (flag != 1)
	{
		pFile = fopen(outfile, "w");
		if (pFile != NULL)
		{
			fprintf(pFile, "Chromosome\tStart\tEnd\t");
			for (int i = 0; i < sample_size-1; i++)
			{
				fprintf(pFile, "%s\t", outname[i].c_str());
			}
			fprintf(pFile, "%s\n", outname[sample_size-1].c_str());
			for (int i = 0; i < loci_length; i++)
			{
				fprintf(pFile, "%s\t", select_idx[i]);
				for (int j = 0; j < sample_size-1; j++)
				{
					value = data_out[j][i];
					if (value < 0)
					{
						value = 0;
					}
					else if (value > up_bound)
					{
						value = up_bound;
					}
					fprintf(pFile, "%lf\t", value);   //report original output value, log2(x+1) transformed.
				}

				value = data_out[sample_size-1][i];
				if (value < 0)
				{
					value = 0;
				}
				else if (value > up_bound)
				{
					value = up_bound;
				}
				fprintf(pFile, "%lf\n", value);

			}
			fclose(pFile);
		}
		else
		{
			std::cout << "Error! Cannot write file " << outfile << std::endl;
			return 1;
		}


	}
	else    //WIG output
	{
		std::vector<std::vector<int> > location;
		std::vector<int>::iterator it;
		for (int i = 0; i < 23; i++)
		{
			location.push_back(std::vector<int>());
		}

		for (int i = 0; i < loci_length; i++)
		{
			part = strtok(select_idx[i], "\t\0");
			if (strcmp(part, "chrX") == 0)
			{
				part = strtok(NULL, "\t\0");
				startsite = atoi(part);
				location[22].push_back(startsite);
			}
			else
			{
				for (int j = 0; j < 22; j++)
				{
					sprintf(chrname, "chr%d", j + 1);
					if (strcmp(part, chrname) == 0)
					{
						part = strtok(NULL, "\t\0");
						startsite = atoi(part);
						location[j].push_back(startsite);
						break;
					}
				}
			}
		}
        
        if (flag_log != 1)
        {
            for (int i = 0; i < sample_size; i++)
            {
                count = 0;
                strcpy(temp_name, outfile);
                strcat(temp_name, ".");
                strcat(temp_name, outname[i].c_str());
                strcat(temp_name, ".wig");
                std::cout << "Writing file " << temp_name << std::endl;
                pFile = fopen(temp_name, "w");
                if (pFile != NULL)
                {
                    fprintf(pFile, "track\ttype=wiggle_0\tname=%s\tvisibility=full\tautoScale=off\tmaxHeightPixels=100:50:10\tviewLimits=0.0:100.0\tyLineOnOff=off\n", outname[i].c_str());
                    //print chr1-chr22
                    for (int j = 0; j < 22; j++)
                    {
                        fprintf(pFile, "variableStep\tchrom=chr%d\tspan=%d\n", j + 1, bin_size);
                        for (it = location[j].begin(); it != location[j].end(); it++)
                        {
                            value = pow(2, data_out[i][count]) - 1;
                            if (value < 0)
                            {
                                value = 0;
                            }
                            else if (value > pow(2,up_bound))
                            {
                                value = pow(2,up_bound);
                            }
                            count++;
                            fprintf(pFile, "%d\t%lf\n", (*it), value);        //report value is limited from 0 to 10000.
                        }
                    }
                    //print chrX
                    fprintf(pFile, "variableStep\tchrom=chrX\tspan=%d\n", bin_size);
                    for (it = location[22].begin(); it != location[22].end(); it++)
                    {
                        value = pow(2, data_out[i][count]) - 1;
                        if (value < 0)
                        {
                            value = 0;
                        }
                        else if (value > pow(2,up_bound))
                        {
                            value = pow(2,up_bound);
                        }
                        count++;
                        fprintf(pFile, "%d\t%lf\n", (*it), value);
                    }

                    fclose(pFile);
                }
                else
                {
                    std::cout << "Error! Cannot write file " << temp_name << std::endl;
                    return 1;
                }

            }
        }
        else
        {
            for (int i = 0; i < sample_size; i++)
            {
                count = 0;
                strcpy(temp_name, outfile);
                strcat(temp_name, ".");
                strcat(temp_name, outname[i].c_str());
                strcat(temp_name, ".wig");
                std::cout << "Writing file " << temp_name << std::endl;
                pFile = fopen(temp_name, "w");
                if (pFile != NULL)
                {
                    fprintf(pFile, "track\ttype=wiggle_0\tname=%s\tvisibility=full\tautoScale=off\tmaxHeightPixels=100:50:10\tviewLimits=0.0:100.0\tyLineOnOff=off\n", outname[i].c_str());
                    //print chr1-chr22
                    for (int j = 0; j < 22; j++)
                    {
                        fprintf(pFile, "variableStep\tchrom=chr%d\tspan=%d\n", j + 1, bin_size);
                        for (it = location[j].begin(); it != location[j].end(); it++)
                        {
                            value = data_out[i][count];
                            if (value < 0)
                            {
                                value = 0;
                            }
                            else if (value > up_bound)
                            {
                                value = up_bound;
                            }
                            count++;
                            fprintf(pFile, "%d\t%lf\n", (*it), value);        //report value is limited from 0 to 10000.
                        }
                    }
                    //print chrX
                    fprintf(pFile, "variableStep\tchrom=chrX\tspan=%d\n", bin_size);
                    for (it = location[22].begin(); it != location[22].end(); it++)
                    {
                        value = data_out[i][count];
                        if (value < 0)
                        {
                            value = 0;
                        }
                        else if (value > up_bound)
                        {
                            value = up_bound;
                        }
                        count++;
                        fprintf(pFile, "%d\t%lf\n", (*it), value);
                    }

                    fclose(pFile);
                }
                else
                {
                    std::cout << "Error! Cannot write file " << temp_name << std::endl;
                    return 1;
                }

            }
        }
        
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movq %rdx, -0x258(%rbp)
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
cmpl $0x1, 0x18(%rbp)
je 0x8a1d
movq -0x28(%rbp), %rdi
leaq 0x6b57(%rip), %rsi      # 0xf2d4
callq 0x2220
movq %rax, -0x168(%rbp)
cmpq $0x0, -0x168(%rbp)
je 0x89de
movq -0x168(%rbp), %rdi
leaq 0x6dc7(%rip), %rsi      # 0xf56c
movb $0x0, %al
callq 0x22d0
movl $0x0, -0x16c(%rbp)
movl -0x16c(%rbp), %eax
movl 0x10(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x8818
movq -0x258(%rbp), %rdi
movq -0x168(%rbp), %rax
movq %rax, -0x260(%rbp)
movslq -0x16c(%rbp), %rsi
callq 0x9950
movq %rax, %rdi
callq 0x20d0
movq -0x260(%rbp), %rdi
movq %rax, %rdx
leaq 0x6cdc(%rip), %rsi      # 0xf4dc
movb $0x0, %al
callq 0x22d0
movl -0x16c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x16c(%rbp)
jmp 0x87b6
movq -0x258(%rbp), %rdi
movq -0x168(%rbp), %rax
movq %rax, -0x268(%rbp)
movl 0x10(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x9950
movq %rax, %rdi
callq 0x20d0
movq -0x268(%rbp), %rdi
movq %rax, %rdx
leaq 0x6c94(%rip), %rsi      # 0xf4e8
movb $0x0, %al
callq 0x22d0
movl $0x0, -0x170(%rbp)
movl -0x170(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x89d0
movq -0x168(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x170(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
leaq 0x6c4b(%rip), %rsi      # 0xf4dc
movb $0x0, %al
callq 0x22d0
movl $0x0, -0x174(%rbp)
movl -0x174(%rbp), %eax
movl 0x10(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x8942
movq -0x10(%rbp), %rax
movslq -0x174(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x170(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x160(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x160(%rbp), %xmm0
jbe 0x88f3
xorps %xmm0, %xmm0
movsd %xmm0, -0x160(%rbp)
jmp 0x8911
movsd -0x160(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x890f
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x160(%rbp)
jmp 0x8911
movq -0x168(%rbp), %rdi
movsd -0x160(%rbp), %xmm0
leaq 0x6bc5(%rip), %rsi      # 0xf4ec
movb $0x1, %al
callq 0x22d0
movl -0x174(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x174(%rbp)
jmp 0x88a2
movq -0x10(%rbp), %rax
movl 0x10(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x170(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x160(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x160(%rbp), %xmm0
jbe 0x8981
xorps %xmm0, %xmm0
movsd %xmm0, -0x160(%rbp)
jmp 0x899f
movsd -0x160(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x899d
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x160(%rbp)
jmp 0x899f
movq -0x168(%rbp), %rdi
movsd -0x160(%rbp), %xmm0
leaq 0x6c89(%rip), %rsi      # 0xf63e
movb $0x1, %al
callq 0x22d0
movl -0x170(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x170(%rbp)
jmp 0x8865
movq -0x168(%rbp), %rdi
callq 0x21d0
jmp 0x8a18
movq 0xd5f3(%rip), %rdi      # 0x15fd8
leaq 0x6b05(%rip), %rsi      # 0xf4f1
callq 0x21c0
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x21c0
movq %rax, %rdi
movq 0xd5b9(%rip), %rsi      # 0x15fc0
callq 0x2200
movl $0x1, -0x4(%rbp)
jmp 0x9687
jmp 0x9680
leaq -0x190(%rbp), %rdi
callq 0x9b90
leaq -0x198(%rbp), %rdi
callq 0x9bb0
movl $0x0, -0x19c(%rbp)
cmpl $0x17, -0x19c(%rbp)
jge 0x8ac5
xorps %xmm0, %xmm0
movaps %xmm0, -0x1c0(%rbp)
movq $0x0, -0x1b0(%rbp)
leaq -0x1c0(%rbp), %rdi
movq %rdi, -0x270(%rbp)
callq 0x9c00
movq -0x270(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0x9bd0
jmp 0x8a85
leaq -0x1c0(%rbp), %rdi
callq 0x9c20
movl -0x19c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x19c(%rbp)
jmp 0x8a3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c8(%rbp)
movl %eax, -0x1cc(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x9c20
jmp 0x9672
movl $0x0, -0x1d0(%rbp)
movl -0x1d0(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x8c34
movq -0x18(%rbp), %rax
movslq -0x1d0(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x6df7(%rip), %rsi      # 0xf8eb
callq 0x2330
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
leaq 0x6a7a(%rip), %rsi      # 0xf582
callq 0x22c0
cmpl $0x0, %eax
jne 0x8b73
leaq 0x6dd2(%rip), %rsi      # 0xf8eb
xorl %eax, %eax
movl %eax, %edi
callq 0x2330
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x2320
movl %eax, -0x150(%rbp)
leaq -0x190(%rbp), %rdi
movl $0x16, %esi
callq 0x9c80
movq %rax, %rdi
leaq -0x150(%rbp), %rsi
callq 0x9ca0
jmp 0x8b57
jmp 0x8c1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1c8(%rbp)
movl %eax, -0x1cc(%rbp)
jmp 0x9672
movl $0x0, -0x1d4(%rbp)
cmpl $0x16, -0x1d4(%rbp)
jge 0x8c1c
leaq -0x14a(%rbp), %rdi
movl -0x1d4(%rbp), %edx
addl $0x1, %edx
leaq 0x69e6(%rip), %rsi      # 0xf587
movb $0x0, %al
callq 0x2040
movq -0x40(%rbp), %rdi
leaq -0x14a(%rbp), %rsi
callq 0x22c0
cmpl $0x0, %eax
jne 0x8c06
leaq 0x6d27(%rip), %rsi      # 0xf8eb
xorl %eax, %eax
movl %eax, %edi
callq 0x2330
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x2320
movl %eax, -0x150(%rbp)
movslq -0x1d4(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0x9c80
movq %rax, %rdi
leaq -0x150(%rbp), %rsi
callq 0x9ca0
jmp 0x8c04
jmp 0x8c1c
jmp 0x8c08
movl -0x1d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1d4(%rbp)
jmp 0x8b7d
jmp 0x8c1e
jmp 0x8c20
movl -0x1d0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1d0(%rbp)
jmp 0x8acf
cmpl $0x1, 0x20(%rbp)
je 0x91bc
movl $0x0, -0x1d8(%rbp)
movl -0x1d8(%rbp), %eax
cmpl 0x10(%rbp), %eax
jge 0x91b7
movl $0x0, -0x154(%rbp)
movq -0x28(%rbp), %rsi
leaq -0x140(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x21a0
movq -0x280(%rbp), %rdi
leaq 0x6b78(%rip), %rsi      # 0xf7fe
callq 0x23d0
movq -0x258(%rbp), %rdi
movslq -0x1d8(%rbp), %rsi
callq 0x9950
movq %rax, %rdi
callq 0x20d0
movq -0x280(%rbp), %rdi
movq %rax, %rsi
callq 0x23d0
movq -0x280(%rbp), %rdi
leaq 0x68ca(%rip), %rsi      # 0xf58d
callq 0x23d0
movq 0xd309(%rip), %rdi      # 0x15fd8
leaq 0x68bc(%rip), %rsi      # 0xf592
callq 0x21c0
movq %rax, -0x278(%rbp)
jmp 0x8ce4
movq -0x278(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x21c0
movq %rax, -0x288(%rbp)
jmp 0x8d00
movq -0x288(%rbp), %rdi
movq 0xd2b2(%rip), %rsi      # 0x15fc0
callq 0x2200
jmp 0x8d15
leaq 0x65b8(%rip), %rsi      # 0xf2d4
leaq -0x140(%rbp), %rdi
callq 0x2220
movq %rax, -0x290(%rbp)
jmp 0x8d31
movq -0x290(%rbp), %rax
movq %rax, -0x168(%rbp)
cmpq $0x0, -0x168(%rbp)
je 0x913e
movq -0x258(%rbp), %rdi
movq -0x168(%rbp), %rax
movq %rax, -0x298(%rbp)
movslq -0x1d8(%rbp), %rsi
callq 0x9950
movq %rax, %rdi
callq 0x20d0
movq -0x298(%rbp), %rdi
movq %rax, %rdx
leaq 0x6819(%rip), %rsi      # 0xf5a0
movb $0x0, %al
callq 0x22d0
movl $0x0, -0x1dc(%rbp)
cmpl $0x16, -0x1dc(%rbp)
jge 0x8f7b
movq -0x168(%rbp), %rdi
movl -0x1dc(%rbp), %edx
addl $0x1, %edx
movl -0x2c(%rbp), %ecx
leaq 0x685a(%rip), %rsi      # 0xf619
movb $0x0, %al
callq 0x22d0
movslq -0x1dc(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0x9c80
movq %rax, %rdi
callq 0x9d10
movq %rax, -0x1e8(%rbp)
movq -0x1e8(%rbp), %rax
movq %rax, -0x198(%rbp)
movslq -0x1dc(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0x9c80
movq %rax, %rdi
callq 0x9d80
movq %rax, -0x1f0(%rbp)
leaq -0x198(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0x9d40
testb $0x1, %al
jne 0x8e34
jmp 0x8f65
movq -0x10(%rbp), %rax
movslq -0x1d8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x154(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movl $0x2, %edi
callq 0x9a10
movsd %xmm0, -0x2a0(%rbp)
jmp 0x8e63
movsd -0x2a0(%rbp), %xmm0
movsd 0x6195(%rip), %xmm1     # 0xf008
subsd %xmm1, %xmm0
movsd %xmm0, -0x160(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x160(%rbp), %xmm0
jbe 0x8e99
xorps %xmm0, %xmm0
movsd %xmm0, -0x160(%rbp)
jmp 0x8f03
movsd -0x160(%rbp), %xmm0
movsd %xmm0, -0x2b0(%rbp)
movsd -0x38(%rbp), %xmm0
movl $0x2, %edi
callq 0x9a10
movsd %xmm0, -0x2a8(%rbp)
jmp 0x8ec2
movsd -0x2b0(%rbp), %xmm0
movsd -0x2a8(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x8f01
movsd -0x38(%rbp), %xmm0
movl $0x2, %edi
callq 0x9a10
movsd %xmm0, -0x2b8(%rbp)
jmp 0x8ef1
movsd -0x2b8(%rbp), %xmm0
movsd %xmm0, -0x160(%rbp)
jmp 0x8f03
movl -0x154(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x154(%rbp)
movq -0x168(%rbp), %rax
movq %rax, -0x2c0(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x9db0
movq -0x2c0(%rbp), %rdi
movl (%rax), %edx
movsd -0x160(%rbp), %xmm0
leaq 0x66f7(%rip), %rsi      # 0xf63b
movb $0x1, %al
callq 0x22d0
leaq -0x198(%rbp), %rdi
xorl %esi, %esi
callq 0x9dd0
movq %rax, -0x1f8(%rbp)
jmp 0x8df6
jmp 0x8f67
movl -0x1dc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1dc(%rbp)
jmp 0x8d98
movq -0x168(%rbp), %rdi
movl -0x2c(%rbp), %edx
leaq 0x66b7(%rip), %rsi      # 0xf643
movb $0x0, %al
callq 0x22d0
leaq -0x190(%rbp), %rdi
movl $0x16, %esi
callq 0x9c80
movq %rax, %rdi
callq 0x9d10
movq %rax, -0x200(%rbp)
movq -0x200(%rbp), %rax
movq %rax, -0x198(%rbp)
leaq -0x190(%rbp), %rdi
movl $0x16, %esi
callq 0x9c80
movq %rax, %rdi
callq 0x9d80
movq %rax, -0x208(%rbp)
leaq -0x198(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x9d40
testb $0x1, %al
jne 0x8ffd
jmp 0x912e
movq -0x10(%rbp), %rax
movslq -0x1d8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x154(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movl $0x2, %edi
callq 0x9a10
movsd %xmm0, -0x2c8(%rbp)
jmp 0x902c
movsd -0x2c8(%rbp), %xmm0
movsd 0x5fcc(%rip), %xmm1     # 0xf008
subsd %xmm1, %xmm0
movsd %xmm0, -0x160(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x160(%rbp), %xmm0
jbe 0x9062
xorps %xmm0, %xmm0
movsd %xmm0, -0x160(%rbp)
jmp 0x90cc
movsd -0x160(%rbp), %xmm0
movsd %xmm0, -0x2d8(%rbp)
movsd -0x38(%rbp), %xmm0
movl $0x2, %edi
callq 0x9a10
movsd %xmm0, -0x2d0(%rbp)
jmp 0x908b
movsd -0x2d8(%rbp), %xmm0
movsd -0x2d0(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x90ca
movsd -0x38(%rbp), %xmm0
movl $0x2, %edi
callq 0x9a10
movsd %xmm0, -0x2e0(%rbp)
jmp 0x90ba
movsd -0x2e0(%rbp), %xmm0
movsd %xmm0, -0x160(%rbp)
jmp 0x90cc
movl -0x154(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x154(%rbp)
movq -0x168(%rbp), %rax
movq %rax, -0x2e8(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x9db0
movq -0x2e8(%rbp), %rdi
movl (%rax), %edx
movsd -0x160(%rbp), %xmm0
leaq 0x652e(%rip), %rsi      # 0xf63b
movb $0x1, %al
callq 0x22d0
leaq -0x198(%rbp), %rdi
xorl %esi, %esi
callq 0x9dd0
movq %rax, -0x210(%rbp)
jmp 0x8fc1
movq -0x168(%rbp), %rdi
callq 0x21d0
jmp 0x913c
jmp 0x91a1
movq 0xce93(%rip), %rdi      # 0x15fd8
leaq 0x63a5(%rip), %rsi      # 0xf4f1
callq 0x21c0
movq %rax, -0x2f0(%rbp)
jmp 0x915a
movq -0x2f0(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x21c0
movq %rax, -0x2f8(%rbp)
jmp 0x9176
movq -0x2f8(%rbp), %rdi
movq 0xce3c(%rip), %rsi      # 0x15fc0
callq 0x2200
jmp 0x918b
movl $0x1, -0x4(%rbp)
movl $0x1, -0x214(%rbp)
jmp 0x9656
jmp 0x91a3
movl -0x1d8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1d8(%rbp)
jmp 0x8c48
jmp 0x964c
movl $0x0, -0x218(%rbp)
movl -0x218(%rbp), %eax
cmpl 0x10(%rbp), %eax
jge 0x964a
movl $0x0, -0x154(%rbp)
movq -0x28(%rbp), %rsi
leaq -0x140(%rbp), %rdi
movq %rdi, -0x308(%rbp)
callq 0x21a0
movq -0x308(%rbp), %rdi
leaq 0x65fa(%rip), %rsi      # 0xf7fe
callq 0x23d0
movq -0x258(%rbp), %rdi
movslq -0x218(%rbp), %rsi
callq 0x9950
movq %rax, %rdi
callq 0x20d0
movq -0x308(%rbp), %rdi
movq %rax, %rsi
callq 0x23d0
movq -0x308(%rbp), %rdi
leaq 0x634c(%rip), %rsi      # 0xf58d
callq 0x23d0
movq 0xcd8b(%rip), %rdi      # 0x15fd8
leaq 0x633e(%rip), %rsi      # 0xf592
callq 0x21c0
movq %rax, -0x300(%rbp)
jmp 0x9262
movq -0x300(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x21c0
movq %rax, -0x310(%rbp)
jmp 0x927e
movq -0x310(%rbp), %rdi
movq 0xcd34(%rip), %rsi      # 0x15fc0
callq 0x2200
jmp 0x9293
leaq 0x603a(%rip), %rsi      # 0xf2d4
leaq -0x140(%rbp), %rdi
callq 0x2220
movq %rax, -0x318(%rbp)
jmp 0x92af
movq -0x318(%rbp), %rax
movq %rax, -0x168(%rbp)
cmpq $0x0, -0x168(%rbp)
je 0x95d4
movq -0x258(%rbp), %rdi
movq -0x168(%rbp), %rax
movq %rax, -0x320(%rbp)
movslq -0x218(%rbp), %rsi
callq 0x9950
movq %rax, %rdi
callq 0x20d0
movq -0x320(%rbp), %rdi
movq %rax, %rdx
leaq 0x629b(%rip), %rsi      # 0xf5a0
movb $0x0, %al
callq 0x22d0
movl $0x0, -0x21c(%rbp)
cmpl $0x16, -0x21c(%rbp)
jge 0x9485
movq -0x168(%rbp), %rdi
movl -0x21c(%rbp), %edx
addl $0x1, %edx
movl -0x2c(%rbp), %ecx
leaq 0x62dc(%rip), %rsi      # 0xf619
movb $0x0, %al
callq 0x22d0
movslq -0x21c(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0x9c80
movq %rax, %rdi
callq 0x9d10
movq %rax, -0x228(%rbp)
movq -0x228(%rbp), %rax
movq %rax, -0x198(%rbp)
movslq -0x21c(%rbp), %rsi
leaq -0x190(%rbp), %rdi
callq 0x9c80
movq %rax, %rdi
callq 0x9d80
movq %rax, -0x230(%rbp)
leaq -0x198(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x9d40
testb $0x1, %al
jne 0x93b2
jmp 0x946f
movq -0x10(%rbp), %rax
movslq -0x218(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x154(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x160(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x160(%rbp), %xmm0
jbe 0x93ef
xorps %xmm0, %xmm0
movsd %xmm0, -0x160(%rbp)
jmp 0x940d
movsd -0x160(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x940b
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x160(%rbp)
jmp 0x940d
movl -0x154(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x154(%rbp)
movq -0x168(%rbp), %rax
movq %rax, -0x328(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x9db0
movq -0x328(%rbp), %rdi
movl (%rax), %edx
movsd -0x160(%rbp), %xmm0
leaq 0x61ed(%rip), %rsi      # 0xf63b
movb $0x1, %al
callq 0x22d0
leaq -0x198(%rbp), %rdi
xorl %esi, %esi
callq 0x9dd0
movq %rax, -0x238(%rbp)
jmp 0x9374
jmp 0x9471
movl -0x21c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x21c(%rbp)
jmp 0x9316
movq -0x168(%rbp), %rdi
movl -0x2c(%rbp), %edx
leaq 0x61ad(%rip), %rsi      # 0xf643
movb $0x0, %al
callq 0x22d0
leaq -0x190(%rbp), %rdi
movl $0x16, %esi
callq 0x9c80
movq %rax, %rdi
callq 0x9d10
movq %rax, -0x240(%rbp)
movq -0x240(%rbp), %rax
movq %rax, -0x198(%rbp)
leaq -0x190(%rbp), %rdi
movl $0x16, %esi
callq 0x9c80
movq %rax, %rdi
callq 0x9d80
movq %rax, -0x248(%rbp)
leaq -0x198(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x9d40
testb $0x1, %al
jne 0x9507
jmp 0x95c4
movq -0x10(%rbp), %rax
movslq -0x218(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x154(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x160(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x160(%rbp), %xmm0
jbe 0x9544
xorps %xmm0, %xmm0
movsd %xmm0, -0x160(%rbp)
jmp 0x9562
movsd -0x160(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x9560
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x160(%rbp)
jmp 0x9562
movl -0x154(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x154(%rbp)
movq -0x168(%rbp), %rax
movq %rax, -0x330(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x9db0
movq -0x330(%rbp), %rdi
movl (%rax), %edx
movsd -0x160(%rbp), %xmm0
leaq 0x6098(%rip), %rsi      # 0xf63b
movb $0x1, %al
callq 0x22d0
leaq -0x198(%rbp), %rdi
xorl %esi, %esi
callq 0x9dd0
movq %rax, -0x250(%rbp)
jmp 0x94cb
movq -0x168(%rbp), %rdi
callq 0x21d0
jmp 0x95d2
jmp 0x9634
movq 0xc9fd(%rip), %rdi      # 0x15fd8
leaq 0x5f0f(%rip), %rsi      # 0xf4f1
callq 0x21c0
movq %rax, -0x338(%rbp)
jmp 0x95f0
movq -0x338(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x21c0
movq %rax, -0x340(%rbp)
jmp 0x960c
movq -0x340(%rbp), %rdi
movq 0xc9a6(%rip), %rsi      # 0x15fc0
callq 0x2200
jmp 0x9621
movl $0x1, -0x4(%rbp)
movl $0x1, -0x214(%rbp)
jmp 0x9656
jmp 0x9636
movl -0x218(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x218(%rbp)
jmp 0x91c6
jmp 0x964c
movl $0x0, -0x214(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x9e10
movl -0x214(%rbp), %eax
testl %eax, %eax
je 0x9670
jmp 0x966e
jmp 0x9687
jmp 0x9680
leaq -0x190(%rbp), %rdi
callq 0x9e10
jmp 0x9693
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
movq -0x1c8(%rbp), %rdi
callq 0x23b0
nop