// File: /workspace/github_c_makefile_star2_O0/sc932[P]ALE/src/ALElike.c
// Function: initRefNumForRealign
void initRefNumForRealign(assemblyT *theAssembly, int matchScore, int mismatchPenalty, int gapOpenPenalty, int gapExtendPenalty, int minSoftClip) {
	int i,j;

	if (realignParameters == NULL) {
		realignParameters = (realign_parameters_t*) malloc(sizeof(realign_parameters_t));
		if(realignParameters == NULL) {
			fprintf(stderr, "Could not allocate memory for mismatch realignment structure");
			abort();
		}
		realignParameters->scoringMatrix = NULL;
	}
	realignParameters->matchScore = matchScore;
	realignParameters->mismatchPenalty = mismatchPenalty;
	realignParameters->gapOpenPenalty = gapOpenPenalty;
	realignParameters->gapExtendPenalty = gapExtendPenalty;
	realignParameters->minSoftClip = minSoftClip;

	// Then build the match/mismatch matrix
	realignParameters->scoringMatrix = (int8_t*) realloc(realignParameters->scoringMatrix, NUM_NT_CHARACTERS * NUM_NT_CHARACTERS * sizeof(int8_t));
	if (realignParameters->scoringMatrix == NULL) {
		fprintf(stderr, "Could not allocate memory for mismatch realignment matrix");
		abort();
	}
	for(i = 0; i < NUM_NT_CHARACTERS; i++) {
		for(j = 0; j < NUM_NT_CHARACTERS; j++) {
			char ref = baseOrder[i], query = baseOrder[j];
			realignParameters->scoringMatrix[i*NUM_NT_CHARACTERS+j] = isAmbiguousMatch(ref, query)|isAmbiguousMatch(query,ref) ? realignParameters->matchScore : -realignParameters->mismatchPenalty;
		}
	}
	// set special case of N,N to 0 score
	realignParameters->scoringMatrix[ (NUM_NT_CHARACTERS-1) * NUM_NT_CHARACTERS + (NUM_NT_CHARACTERS-1) ] = 0;

	// Then prep the reference as a number string
	for(i = 0; i < theAssembly->numContigs; i++) {
		contig_t *contig = theAssembly->contigs[i];
		if (contig->seqNum != NULL)
			continue;
		contig->seqNum = (int8_t*) realloc(contig->seqNum, sizeof(*contig->seqNum) * contig->seqLen);
		if (contig->seqNum == NULL) {
			fprintf(stderr, "Could not allocate memory for realignment: %ld bytes\n", sizeof(*contig->seqNum) * contig->seqLen);
			abort();
		}
		for(j = 0; j < contig->seqLen; j++) {
			contig->seqNum[j] = seqNumTransformTable[ contig->seq[j] ];
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
cmpq $0x0, 0x2e6c3(%rip)     # 0x3a138
jne 0xbabd
movl $0x10, %edi
callq 0x3420
movq %rax, 0x2e6b0(%rip)     # 0x3a138
cmpq $0x0, 0x2e6a8(%rip)     # 0x3a138
jne 0xbaaf
movq 0x2d55f(%rip), %rax     # 0x38ff8
movq (%rax), %rdi
leaq 0x2572f(%rip), %rsi     # 0x311d2
movb $0x0, %al
callq 0x3350
callq 0x3080
movq 0x2e682(%rip), %rax     # 0x3a138
movq $0x0, (%rax)
movl -0xc(%rbp), %eax
movb %al, %cl
movq 0x2e66f(%rip), %rax     # 0x3a138
movb %cl, 0x8(%rax)
movl -0x10(%rbp), %eax
movb %al, %cl
movq 0x2e660(%rip), %rax     # 0x3a138
movb %cl, 0x9(%rax)
movl -0x14(%rbp), %eax
movb %al, %cl
movq 0x2e651(%rip), %rax     # 0x3a138
movb %cl, 0xa(%rax)
movl -0x18(%rbp), %eax
movb %al, %cl
movq 0x2e642(%rip), %rax     # 0x3a138
movb %cl, 0xb(%rax)
movl -0x1c(%rbp), %eax
movb %al, %cl
movq 0x2e633(%rip), %rax     # 0x3a138
movb %cl, 0xc(%rax)
movq 0x2e629(%rip), %rax     # 0x3a138
movq (%rax), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x3470
movq %rax, %rcx
movq 0x2e612(%rip), %rax     # 0x3a138
movq %rcx, (%rax)
movq 0x2e608(%rip), %rax     # 0x3a138
cmpq $0x0, (%rax)
jne 0xbb53
movq 0x2d4bb(%rip), %rax     # 0x38ff8
movq (%rax), %rdi
leaq 0x256c8(%rip), %rsi     # 0x3120f
movb $0x0, %al
callq 0x3350
callq 0x3080
movl $0x0, -0x20(%rbp)
cmpl $0x10, -0x20(%rbp)
jge 0xbc22
movl $0x0, -0x24(%rbp)
cmpl $0x10, -0x24(%rbp)
jge 0xbc12
movslq -0x20(%rbp), %rcx
leaq 0x201a0(%rip), %rax     # 0x2bd20
movb (%rax,%rcx), %al
movb %al, -0x25(%rbp)
movslq -0x24(%rbp), %rcx
leaq 0x2018f(%rip), %rax     # 0x2bd20
movb (%rax,%rcx), %al
movb %al, -0x26(%rbp)
movb -0x25(%rbp), %al
movsbl %al, %edi
movsbl -0x26(%rbp), %esi
callq 0x4c20
movl %eax, -0x34(%rbp)
movb -0x26(%rbp), %al
movsbl %al, %edi
movsbl -0x25(%rbp), %esi
callq 0x4c20
movl %eax, %ecx
movl -0x34(%rbp), %eax
orl %ecx, %eax
cmpl $0x0, %eax
je 0xbbd4
movq 0x2e56d(%rip), %rax     # 0x3a138
movsbl 0x8(%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0xbbe6
movq 0x2e55d(%rip), %rax     # 0x3a138
movsbl 0x9(%rax), %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movb %al, %dl
movq 0x2e546(%rip), %rax     # 0x3a138
movq (%rax), %rax
movl -0x20(%rbp), %ecx
shll $0x4, %ecx
addl -0x24(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xbb6b
jmp 0xbc14
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xbb5a
movq 0x2e50f(%rip), %rax     # 0x3a138
movq (%rax), %rax
movb $0x0, 0xff(%rax)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xbd20
movq -0x8(%rbp), %rax
movq 0xa0(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0xbc70
jmp 0xbd12
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rax
movslq 0x8(%rax), %rsi
shlq $0x0, %rsi
callq 0x3470
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xbcc8
movq 0x2d352(%rip), %rax     # 0x38ff8
movq (%rax), %rdi
movq -0x30(%rbp), %rax
movslq 0x8(%rax), %rdx
shlq $0x0, %rdx
leaq 0x2558d(%rip), %rsi     # 0x31249
movb $0x0, %al
callq 0x3350
callq 0x3080
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xbd10
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movsbq (%rax,%rcx), %rcx
leaq 0x2003d(%rip), %rax     # 0x2bd30
movb (%rax,%rcx), %dl
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x24(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xbccf
jmp 0xbd12
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xbc3a
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)