// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movl %r9d, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq 0x18(%rbp), %rax
movl (%rax), %eax
addl $0x2, %eax
movl %eax, -0x3c(%rbp)
movslq -0x3c(%rbp), %rdi
shlq $0x2, %rdi
callq 0x3420
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x4(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0x8(%rbp), %ecx
movq -0x20(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
cmpl $0x0, -0x8(%rbp)
jle 0x1443a
movl -0x8(%rbp), %edi
movl $0x53, %esi
callq 0x142a0
movl %eax, %edx
movq -0x48(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq 0x18(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x14610
movq 0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x14690
movb %al, -0x51(%rbp)
movq 0x10(%rbp), %rax
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x146d0
movl %eax, -0x34(%rbp)
movsbl -0x51(%rbp), %eax
cmpl $0x4d, %eax
jne 0x1453a
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x14535
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
movq -0x20(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
je 0x144e4
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x48(%rbp), %r9
movl $0x2, %edi
leaq -0x4c(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
leaq -0x3c(%rbp), %r8
callq 0x142d0
movq %rax, -0x48(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x1450f
movq -0x48(%rbp), %r9
movl $0x1, %edi
leaq -0x4c(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
leaq -0x3c(%rbp), %r8
callq 0x142d0
movq %rax, -0x48(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x14490
jmp 0x14600
movsbl -0x51(%rbp), %eax
cmpl $0x49, %eax
jne 0x1459c
movl -0x34(%rbp), %ecx
movq -0x20(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movl -0x34(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x48(%rbp), %r9
xorl %edi, %edi
leaq -0x4c(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
leaq -0x3c(%rbp), %r8
callq 0x142d0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movl -0x34(%rbp), %ecx
leaq -0x2c(%rbp), %rsi
leaq -0x3c(%rbp), %rdx
movl $0x49, %r8d
callq 0x141b0
movq %rax, -0x48(%rbp)
jmp 0x145fe
movsbl -0x51(%rbp), %eax
cmpl $0x44, %eax
jne 0x145fc
movl -0x34(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0x34(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x48(%rbp), %r9
xorl %edi, %edi
leaq -0x4c(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
leaq -0x3c(%rbp), %r8
callq 0x142d0
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movl -0x34(%rbp), %ecx
leaq -0x2c(%rbp), %rsi
leaq -0x3c(%rbp), %rdx
movl $0x44, %r8d
callq 0x141b0
movq %rax, -0x48(%rbp)
jmp 0x145fe
jmp 0x14600
jmp 0x14602
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x14441
movq -0x48(%rbp), %r9
xorl %edi, %edi
leaq -0x4c(%rbp), %rsi
leaq -0x50(%rbp), %rdx
leaq -0x2c(%rbp), %rcx
leaq -0x3c(%rbp), %r8
callq 0x142d0
movq %rax, -0x48(%rbp)
movl -0x24(%rbp), %eax
subl -0xc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0x1465f
movq -0x48(%rbp), %rdi
movl -0x34(%rbp), %ecx
leaq -0x2c(%rbp), %rsi
leaq -0x3c(%rbp), %rdx
movl $0x53, %r8d
callq 0x141b0
movq %rax, -0x48(%rbp)
movl -0x2c(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movq 0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x3050
movq -0x48(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movl -0x28(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)