// File: /workspace/github_c_makefile_star2_O2/sc932[P]ALE/src/ssw.c
// Function: mark_mismatch
int32_t mark_mismatch (int32_t ref_begin1,
					   int32_t read_begin1,
					   int32_t read_end1,
					   const int8_t* ref,
					   const int8_t* read,
					   int32_t readLen,
					   uint32_t** cigar,
					   int32_t* cigarLen) {

	int32_t mismatch_length = 0, p = 0, i, length, j, s = *cigarLen + 2;
	uint32_t *new_cigar = (uint32_t*)malloc(s*sizeof(uint32_t)), length_m = 0,  length_x = 0;
	char op;

	ref += ref_begin1;
	read += read_begin1;
	if (read_begin1 > 0) new_cigar[p ++] = to_cigar_int(read_begin1, 'S');
	for (i = 0; i < (*cigarLen); ++i) {
		op = cigar_int_to_op((*cigar)[i]);
		length = cigar_int_to_len((*cigar)[i]);
		if (op == 'M') {
			for (j = 0; j < length; ++j) {
				if (*ref != *read) {
					++ mismatch_length;
					// the previous is match; however the current one is mismatche
					new_cigar = store_previous_m (2, &length_m, &length_x, &p, &s, new_cigar);			
					++ length_x;
				} else {
					// the previous is mismatch; however the current one is matche
					new_cigar = store_previous_m (1, &length_m, &length_x, &p, &s, new_cigar);			
					++ length_m;
				}
				++ ref;
				++ read;
			}
		}else if (op == 'I') {
			read += length;
			mismatch_length += length;
			new_cigar = store_previous_m (0, &length_m, &length_x, &p, &s, new_cigar);			
			new_cigar = add_cigar (new_cigar, &p, &s, length, 'I'); 
		}else if (op == 'D') {
			ref += length;
			mismatch_length += length;
			new_cigar = store_previous_m (0, &length_m, &length_x, &p, &s, new_cigar);			
			new_cigar = add_cigar (new_cigar, &p, &s, length, 'D'); 
		}
	}
	new_cigar = store_previous_m (0, &length_m, &length_x, &p, &s, new_cigar);
	
	length = readLen - read_end1 - 1;
	if (length > 0) new_cigar = add_cigar(new_cigar, &p, &s, length, 'S');
	
	(*cigarLen) = p;	
	free(*cigar);
	(*cigar) = new_cigar;
	return mismatch_length;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, 0x10(%rsp)
movq %r8, %r15
movq %rcx, %r14
movl %edx, 0x14(%rsp)
movl %esi, %ebx
movl %edi, %ebp
movq 0x68(%rsp), %rax
andl $0x0, 0x4(%rsp)
movslq (%rax), %r13
leaq 0x2(%r13), %rax
movl %eax, (%rsp)
leaq 0x8(,%r13,4), %rdi
callq 0x3420
andl $0x0, 0xc(%rsp)
andl $0x0, 0x8(%rsp)
movslq %ebp, %rdx
movslq %ebx, %rcx
testl %ecx, %ecx
jle 0xc6ea
shll $0x4, %ebx
orl $0x4, %ebx
movl $0x1, 0x4(%rsp)
movl %ebx, (%rax)
addq %rdx, %r14
addq %rcx, %r15
xorl %ebp, %ebp
xorl %r12d, %r12d
movslq %r13d, %rcx
cmpq %rcx, %rbp
jge 0xc849
movq 0x60(%rsp), %rcx
movq (%rcx), %rcx
movl (%rcx,%rbp,4), %r13d
movl %r13d, %ecx
andl $0xf, %ecx
cmpl $0x9, %ecx
jb 0xc7a4
movl %r13d, %ebx
shrl $0x4, %ebx
movq %rbp, 0x20(%rsp)
shrl $0x4, %r13d
leaq (%r15,%r13), %rcx
movq %rcx, 0x18(%rsp)
movl %ebx, %ebx
xorl %ebp, %ebp
cmpl %ebp, %ebx
je 0xc792
movb (%r14,%rbp), %cl
cmpb (%r15,%rbp), %cl
jne 0xc769
pushq $0x1
popq %rdi
leaq 0xc(%rsp), %rsi
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movq %rsp, %r8
movq %rax, %r9
callq 0xc60a
incl 0xc(%rsp)
jmp 0xc78d
incl %r12d
pushq $0x2
popq %rdi
leaq 0xc(%rsp), %rsi
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movq %rsp, %r8
movq %rax, %r9
callq 0xc60a
incl 0x8(%rsp)
incq %rbp
jmp 0xc738
addq %r13, %r14
movq 0x18(%rsp), %r15
movq 0x20(%rsp), %rbp
jmp 0xc839
leaq 0x13e11(%rip), %rdx     # 0x205bc
movzbl (%rcx,%rdx), %ecx
movl %r13d, %ebx
shrl $0x4, %ebx
cmpl $0x44, %ecx
je 0xc7fe
cmpl $0x49, %ecx
je 0xc7ca
cmpl $0x4d, %ecx
je 0xc722
jmp 0xc839
addq %rbx, %r15
addl %ebx, %r12d
xorl %edi, %edi
leaq 0xc(%rsp), %rsi
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %r13
movq %r13, %rcx
movq %rsp, %r8
movq %rax, %r9
callq 0xc60a
movq %rax, %rdi
movq %r13, %rsi
movq %rsp, %rdx
movl %ebx, %ecx
pushq $0x49
jmp 0xc832
movl %ebx, %ecx
addq %rcx, %r14
addl %ebx, %r12d
xorl %edi, %edi
leaq 0xc(%rsp), %rsi
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %r13
movq %r13, %rcx
movq %rsp, %r8
movq %rax, %r9
callq 0xc60a
movq %rax, %rdi
movq %r13, %rsi
movq %rsp, %rdx
movl %ebx, %ecx
pushq $0x44
popq %r8
callq 0xc593
incq %rbp
movq 0x68(%rsp), %rcx
movl (%rcx), %r13d
jmp 0xc6f5
leaq 0xc(%rsp), %rsi
leaq 0x8(%rsp), %rdx
leaq 0x4(%rsp), %rcx
movq %rsp, %r8
xorl %edi, %edi
movq %rax, %r9
callq 0xc60a
movq %rax, %rbx
movl 0x14(%rsp), %ecx
notl %ecx
addl 0x10(%rsp), %ecx
testl %ecx, %ecx
jle 0xc88d
leaq 0x4(%rsp), %rsi
movq %rsp, %rdx
pushq $0x53
popq %r8
movq %rbx, %rdi
callq 0xc593
movq %rax, %rbx
movl 0x4(%rsp), %eax
movq 0x68(%rsp), %rcx
movl %eax, (%rcx)
movq 0x60(%rsp), %r14
movq (%r14), %rdi
callq 0x3070
movq %rbx, (%r14)
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop