// File: /workspace/github_c_makefile_star2_O0/dapogon[P]cellcoal/src/signatures.c
// Function: PrepareGeneticSignatures
void PrepareGeneticSignatures (void)
	{
	int 	i, j, k, l;
	char	*header, *token;

	/*  alloc memory */
	header = (char*) calloc (MAX_LINE, sizeof(char));
	if (!header)
		{
		fprintf (stderr, "Could not allocate the header string\n");
		exit (-1);
		}

	token = (char*) calloc (MAX_NAME, sizeof(char));
	if (!token)
		{
		fprintf (stderr, "Could not allocate the token string\n");
		exit (-1);
		}

	/* allocate memory for signatures */
	geneticSignature = (double****) calloc (NUM_SIGNATURES, sizeof(double***));
	if (!geneticSignature)
		{
		fprintf (stderr, "Could not allocate the geneticSignature array\n");
		exit (-1);
		}
	for (l=0; l<NUM_SIGNATURES; l++)
		{
		geneticSignature[l] = (double***) calloc (4, sizeof(double**));
		if (!geneticSignature[l])
			{
			fprintf (stderr, "Could not allocate the geneticSignature[%d] array\n", l);
			exit (-1);
			}
		for (i=0; i<4; i++)
			{
			geneticSignature[l][i] = (double**) calloc (6, sizeof(double*));
			if (!geneticSignature[l][i])
				{
				fprintf (stderr, "Could not allocate the geneticSignature[%d][%d] array\n", l, i);
				exit (-1);
				}
			for (j=0; j<6; j++)
				{
				geneticSignature[l][i][j] = (double*) calloc (4, sizeof(double));
				if (!geneticSignature[l][i][j])
					{
					fprintf (stderr, "Could not allocate the geneticSignature[%d][%d][%d] array\n", l, i, j);
					exit (-1);
					}
				}
			}
		}

	/* allocate matrix to store the signatures in 2D */
	signatureProbs = (double**) calloc (NUM_SIGNATURES, sizeof(double));
	if (!signatureProbs)
		{
		fprintf (stderr, "Could not allocate the signatureProbs array\n");
		exit (-1);
		}
	for (i=0; i<NUM_SIGNATURES; i++)
		{
		signatureProbs[i] = (double*) calloc (96, sizeof(double));
		if (!signatureProbs[i])
			{
			fprintf (stderr, "Could not allocate the signatureProbs[%d] array\n", i);
			exit (-1);
			}
		}
	
	
	/*
	selectedSignature = (double***) calloc (4, sizeof(double**));
	if (!selectedSignature)
		{
		fprintf (stderr, "Could not allocate the selectedSignature array\n");
		exit (-1);
		}
	for (i=0; i<4; i++)
		{
		selectedSignature[i] = (double**) calloc (6, sizeof(double*));
		if (!selectedSignature[i])
			{
			fprintf (stderr, "Could not allocate the selectedSignature[%d] array\n", i);
			exit (-1);
			}
		for (j=0; j<6; j++)
			{
			selectedSignature[i][j] = (double*) calloc (4, sizeof(double));
			if (!selectedSignature[i][j])
				{
				fprintf (stderr, "Could not allocate the selectedSignature[%d][%d] array\n", i, j);
				exit (-1);
				}
			}
		}
	 */

	#ifdef LOAD_INTERNAL_SIGNATURES
	/* load internal signatures */
	LoadSignatures();
	#else
	/* open signatures file */
	FILE 	*fpSign;
	if ((fpSign = fopen("stuff/signatures/signatures_probabilities.txt", "r")) == NULL)
		{
		fprintf (stderr, "\nERROR: Can't open file \"%s\"\n", "signatures_probabilities.txt");
		PrintUsage();
		}

	/* read the header string */
	fgets (header, MAX_LINE, fpSign);

	/* read in the probabilities */
	for (i=0; i<4; i++)
		for (j=0; j<6; j++)
			for (k=0; k<4; k++)
			 	{
			 	fscanf (fpSign, "%s %s %s", token, token, token);
				for (l=0; l<NUM_SIGNATURES; l++)
					fscanf (fpSign, "%lf", &geneticSignature[l][i][j][k]);
				}
	/* close signatures file */
	fclose(fpSign);
	#endif
		
	#undef PRINT_SIGNATURES
	#ifdef PRINT_SIGNATURES
	/* print all the signatures */
	fprintf (stderr, "\nSubstitution Type\tTrinucleotide\tSomatic Mutation Type");
	for (l=1; l<NUM_SIGNATURES; l++)
		fprintf (stderr, "\tSignature %d",l);
	for (i=0; i<4; i++)
		for (j=0; j<6; j++)
			{
			if (j == 0) strcpy(token,"C>A");
			else if (j == 1) strcpy(token,"C>G");
			else if (j == 2) strcpy(token,"C>T");
			else if (j == 3) strcpy(token,"T>A");
			else if (j == 4) strcpy(token,"T>C");
			else if (j == 5) strcpy(token,"T>G");
			for (k=0; k<4; k++)
				{
				fprintf (stderr, "\n%s %c%c%c %c[%s]%c",  token, WhichNuc(i), token[0], WhichNuc(k), WhichNuc(i), token, WhichNuc(k));
				for (l=0; l<NUM_SIGNATURES; l++)
					fprintf (stderr, "\t%14.12lf", geneticSignature[l][i][j][k]);
				}
			}
	fprintf (stderr, "\n\n");

	/* print the selected genetic signature */
	/*
	fprintf (stderr, "\nSelected signature %d", userSignature);
	for (i=0; i<4; i++)
		for (j=0; j<6; j++)
			{
			if (j == 0) strcpy(token,"C>A");
			else if (j == 1) strcpy(token,"C>G");
			else if (j == 2) strcpy(token,"C>T");
			else if (j == 3) strcpy(token,"T>A");
			else if (j == 4) strcpy(token,"T>C");
			else if (j == 5) strcpy(token,"T>G");
			for (k=0; k<4; k++)
				fprintf (stderr, "\n%c[%s]%c\t%14.12lf", WhichNuc(i), token, WhichNuc(k),  selectedSignature[i][j][k]);
			}
	fprintf (stderr, "\n\n");
	*/
	exit(-1);
	#endif

	/* print for hard coding */
	#undef PRINT_CODE
	#ifdef PRINT_CODE
	for (l=0; l<NUM_SIGNATURES; l++)
		{
		fprintf (stderr, "\n\n/* Signature %02d */", l+1);
		for (i=0; i<4; i++)
			for (j=0; j<6; j++)
				{
				if (j == 0) strcpy(token,"CG_AT");
				else if (j == 1) strcpy(token,"CG_GC");
				else if (j == 2) strcpy(token,"CG_TA");
				else if (j == 3) strcpy(token,"TA_AT");
				else if (j == 4) strcpy(token,"TA_CG");
				else if (j == 5) strcpy(token,"TA_GC");
				for (k=0; k<4; k++)
					fprintf (stderr, "\ngeneticSignature[%d][%c][%s][%c] = %14.12lf;", l, WhichNuc(i), token, WhichNuc(k), geneticSignature[l][i][j][k]);
				}
		}
	exit(-1);
	#endif
	
	/* copy in the selected genetic signature  */
	for (l=0; l<NUM_SIGNATURES; l++)
		for (i=0; i<4; i++)
			for (j=0; j<6; j++)
				for (k=0; k<4; k++)
					signatureProbs[l][trimut(i,j,k)] = geneticSignature[l][i][j][k];

	#undef PRINT_SIGNATURES2
	#ifdef PRINT_SIGNATURES2
	/* print in the selected genetic signature  */
	for (i=0; i<96; i++)
		{
		fprintf (stderr, "\n");
		for (l=0; l<NUM_SIGNATURES; l++)
			fprintf(stderr, "%14.12lf ", signatureProbs[l][i]);
		}
	exit(-1);
	#endif

	
	/* load the trinucleotide frequencies from the human genome */
	LoadTrinucleotideFrequencies();
	
	/*
	for (i=0; i<4; i++)
		for (j=0; j<4; j++)
			for (k=0; k<4; k++)
				fprintf (stderr, "\ntrinucfreq [%c][%c][%c] = %10.8lf;",  WhichNuc(i), WhichNuc(j), WhichNuc(k), triNucFreq[trinuc(i,j,k)]);
	 */


	/* free memopry */
	free(header);
	free(token);
	free(geneticSignature);
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl $0x7a120, %edi          # imm = 0x7A120
movl $0x1, %esi
callq 0x2190
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x270f4
movq 0x26f1f(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
leaq 0x19ad4(%rip), %rsi     # 0x40bb7
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
movl $0x78, %edi
movl $0x1, %esi
callq 0x2190
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x27130
movq 0x26ee3(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
leaq 0x23be9(%rip), %rsi     # 0x4ad08
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
movl $0x1e, %edi
movl $0x8, %esi
callq 0x2190
movq %rax, 0x2926a(%rip)     # 0x503b0
cmpq $0x0, 0x29262(%rip)     # 0x503b0
jne 0x27172
movq 0x26ea1(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
leaq 0x23bcc(%rip), %rsi     # 0x4ad2d
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
movl $0x0, -0x10(%rbp)
cmpl $0x1e, -0x10(%rbp)
jge 0x27317
movl $0x4, %edi
movl $0x8, %esi
callq 0x2190
movq %rax, %rdx
movq 0x29214(%rip), %rax     # 0x503b0
movslq -0x10(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x29205(%rip), %rax     # 0x503b0
movslq -0x10(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x271db
movq 0x26e3b(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
movl -0x10(%rbp), %edx
leaq 0x23b92(%rip), %rsi     # 0x4ad5c
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
movl $0x0, -0x4(%rbp)
cmpl $0x4, -0x4(%rbp)
jge 0x27307
movl $0x6, %edi
movl $0x8, %esi
callq 0x2190
movq %rax, %rdx
movq 0x291ab(%rip), %rax     # 0x503b0
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x29194(%rip), %rax     # 0x503b0
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x27257
movq 0x26dc2(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
movl -0x10(%rbp), %edx
movl -0x4(%rbp), %ecx
leaq 0x23b49(%rip), %rsi     # 0x4ad8f
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
movl $0x0, -0x8(%rbp)
cmpl $0x6, -0x8(%rbp)
jge 0x272f7
movl $0x4, %edi
movl $0x8, %esi
callq 0x2190
movq %rax, %rdx
movq 0x2912f(%rip), %rax     # 0x503b0
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x29110(%rip), %rax     # 0x503b0
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x8(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x272e7
movq 0x26d36(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
movl -0x10(%rbp), %edx
movl -0x4(%rbp), %ecx
movl -0x8(%rbp), %r8d
leaq 0x23af0(%rip), %rsi     # 0x4adc6
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
jmp 0x272e9
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x2725e
jmp 0x272f9
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x271e2
jmp 0x27309
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x27179
movl $0x1e, %edi
movl $0x8, %esi
callq 0x2190
movq %rax, 0x2908b(%rip)     # 0x503b8
cmpq $0x0, 0x29083(%rip)     # 0x503b8
jne 0x27359
movq 0x26cba(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
leaq 0x23ab9(%rip), %rsi     # 0x4ae01
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
movl $0x0, -0x4(%rbp)
cmpl $0x1e, -0x4(%rbp)
jge 0x273cb
movl $0x60, %edi
movl $0x8, %esi
callq 0x2190
movq %rax, %rdx
movq 0x29039(%rip), %rax     # 0x503b8
movslq -0x4(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x2902a(%rip), %rax     # 0x503b8
movslq -0x4(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x273be
movq 0x26c58(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
movl -0x4(%rbp), %edx
leaq 0x23a81(%rip), %rsi     # 0x4ae2e
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
jmp 0x273c0
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x27360
callq 0x274c0
movl $0x0, -0x10(%rbp)
cmpl $0x1e, -0x10(%rbp)
jge 0x27492
movl $0x0, -0x4(%rbp)
cmpl $0x4, -0x4(%rbp)
jge 0x27482
movl $0x0, -0x8(%rbp)
cmpl $0x6, -0x8(%rbp)
jge 0x27472
movl $0x0, -0xc(%rbp)
cmpl $0x4, -0xc(%rbp)
jge 0x27465
movq 0x28f9d(%rip), %rax     # 0x503b0
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xc(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x28f7d(%rip), %rax     # 0x503b8
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
imull $0x18, -0x4(%rbp), %ecx
movl -0x8(%rbp), %edx
shll $0x2, %edx
addl %edx, %ecx
addl -0xc(%rbp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x27406
jmp 0x27467
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0x273f9
jmp 0x27474
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x273e8
jmp 0x27484
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x273d7
callq 0x3df20
movq -0x18(%rbp), %rdi
callq 0x2030
movq -0x20(%rbp), %rdi
callq 0x2030
movq 0x28f00(%rip), %rdi     # 0x503b0
callq 0x2030
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)