// File: chhylp123[P]hifiasm/./Levenshtein_distance.h
// Function: cigar_check(char*, char*, bit_extz_t*)
inline uint32_t cigar_check(char *pstr, char *tstr, bit_extz_t *ez)
{
	int32_t pi = ez->ps, ti = ez->ts, err = 0; uint32_t ci = 0, cl, k; uint16_t c;
	while (ci < ez->cigar.n) {
		ci = pop_trace(&(ez->cigar), ci, &c, &cl);
		// fprintf(stderr, "# %u = %u\n", c, cl); 
		if(c == 0) {
			for (k=0;(k<cl)&&(pstr[pi]==tstr[ti]);k++,pi++,ti++);
			if(k!=cl) {
				fprintf(stderr, "ERROR-d-0, pi::%d, ti::%d\n", pi, ti); 
				return 0;
			}
		} else {
			err += cl;
			if(c == 1) {
				for (k=0;(k<cl)&&(pstr[pi]!=tstr[ti]);k++,pi++,ti++);
				if(k!=cl) {
					fprintf(stderr, "ERROR-d-1, pi::%d, ti::%d\n", pi, ti);  
					return 0;
				}
			} else if(c == 2) {///more p
				pi+=cl;
			} else if(c == 3) {
				ti+=cl;
			}
		}
	}
	if(err != ez->err) {
		fprintf(stderr, "ERROR-err\n"); 
		return 0;
	}
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpq 0xa8(%rcx), %rax
jae 0xc102c
movq -0x20(%rbp), %rdi
addq $0xa8, %rdi
movl -0x30(%rbp), %esi
leaq -0x3a(%rbp), %rdx
leaq -0x34(%rbp), %rcx
callq 0xa1ee0
movl %eax, -0x30(%rbp)
movzwl -0x3a(%rbp), %eax
cmpl $0x0, %eax
jne 0xc0f58
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %ecx
xorl %eax, %eax
cmpl -0x34(%rbp), %ecx
movb %al, -0x3b(%rbp)
jae 0xc0ef9
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x3b(%rbp)
movb -0x3b(%rbp), %al
testb $0x1, %al
jne 0xc0f02
jmp 0xc0f21
jmp 0xc0f04
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xc0ecc
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0xc0f53
movq 0x3030b0(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
leaq 0x2c5815(%rip), %rsi    # 0x386755
movb $0x0, %al
callq 0x22a0
movl $0x0, -0x4(%rbp)
jmp 0xc1060
jmp 0xc1027
movl -0x34(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movzwl -0x3a(%rbp), %eax
cmpl $0x1, %eax
jne 0xc0ffb
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %ecx
xorl %eax, %eax
cmpl -0x34(%rbp), %ecx
movb %al, -0x3c(%rbp)
jae 0xc0fa2
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
setne %al
movb %al, -0x3c(%rbp)
movb -0x3c(%rbp), %al
testb $0x1, %al
jne 0xc0fab
jmp 0xc0fca
jmp 0xc0fad
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xc0f75
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0xc0ff9
movq 0x303007(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movl -0x24(%rbp), %edx
movl -0x28(%rbp), %ecx
leaq 0x2c5787(%rip), %rsi    # 0x386770
movb $0x0, %al
callq 0x22a0
movl $0x0, -0x4(%rbp)
jmp 0xc1060
jmp 0xc1025
movzwl -0x3a(%rbp), %eax
cmpl $0x2, %eax
jne 0xc100f
movl -0x34(%rbp), %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0xc1023
movzwl -0x3a(%rbp), %eax
cmpl $0x3, %eax
jne 0xc1021
movl -0x34(%rbp), %eax
addl -0x28(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0xc1023
jmp 0xc1025
jmp 0xc1027
jmp 0xc0e86
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
je 0xc1059
movq 0x302fa1(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x2c5742(%rip), %rsi    # 0x38678b
movb $0x0, %al
callq 0x22a0
movl $0x0, -0x4(%rbp)
jmp 0xc1060
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)