// File: /workspace/github_c_makefile_star2_O2/nh13[P]ksw/src/parasail/src/sw_trace_scan.c
// Function: parasail_sw_trace_scan
parasail_result_t* ENAME(
        const char * const restrict _s1, const int _s1Len,
        const char * const restrict _s2, const int s2Len,
        const int open, const int gap, const parasail_matrix_t *matrix)
{
    /* declare local variables */
    parasail_result_t *result = NULL;
    int * restrict s1 = NULL;
    int * restrict s2 = NULL;
    int * restrict HB = NULL;
    int * restrict H  = NULL;
    int * restrict E  = NULL;
    int * restrict HtB= NULL;
    int * restrict Ht = NULL;
    int8_t * restrict HT = NULL;
    int * restrict Ex = NULL;
    int i = 0;
    int j = 0;
    int s1Len = 0;
    int score = 0;
    int end_query = 0;
    int end_ref = 0;

    /* validate inputs */
    PARASAIL_CHECK_NULL(_s2);
    PARASAIL_CHECK_GT0(s2Len);
    PARASAIL_CHECK_GE0(open);
    PARASAIL_CHECK_GE0(gap);
    PARASAIL_CHECK_NULL(matrix);
    if (matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) {
        PARASAIL_CHECK_NULL(_s1);
        PARASAIL_CHECK_GT0(_s1Len);
    }

    /* initialize stack variables */
    i = 0;
    j = 0;
    s1Len = matrix->type == PARASAIL_MATRIX_TYPE_SQUARE ? _s1Len : matrix->length;
    score = NEG_INF_32;
    end_query = s1Len;
    end_ref = s2Len;

    /* initialize result */
    result = parasail_result_new_trace(s1Len, s2Len, 16, sizeof(int8_t));
    if (!result) return NULL;

    /* set known flags */
    result->flag |= PARASAIL_FLAG_SW | PARASAIL_FLAG_NOVEC_SCAN
        | PARASAIL_FLAG_TRACE
        | PARASAIL_FLAG_BITS_INT | PARASAIL_FLAG_LANES_1;

    /* initialize heap variables */
    s2 = parasail_memalign_int(16, s2Len);
    HB = parasail_memalign_int(16, s1Len+1);
    H  = HB+1;
    E  = parasail_memalign_int(16, s1Len);
    HtB= parasail_memalign_int(16, s1Len+1);
    Ht = HtB+1;
    Ex = parasail_memalign_int(16, s1Len);
    HT = (int8_t* restrict)result->trace->trace_table;

    /* validate heap variables */
    if (!s2) return NULL;
    if (!HB) return NULL;
    if (!E) return NULL;
    if (!HtB) return NULL;
    if (!Ex) return NULL;

    if (matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) {
        s1 = parasail_memalign_int(16, s1Len);
        if (!s1) return NULL;
        for (i=0; i<s1Len; ++i) {
            s1[i] = matrix->mapper[(unsigned char)_s1[i]];
        }
    }
    for (j=0; j<s2Len; ++j) {
        s2[j] = matrix->mapper[(unsigned char)_s2[j]];
    }

    /* initialize H */
    H[-1] = 0;
    Ht[-1] = 0;
    for (i=0; i<s1Len; ++i) {
        H[i] = 0;
    }

    /* initialize E */
    for (i=0; i<s1Len; ++i) {
        E[i] = NEG_INF_32;
    }

    /* iterate over database */
    for (j=0; j<s2Len; ++j) {
        int Ft = NEG_INF_32;
        /* calculate E */
        for (i=0; i<s1Len; ++i) {
            int E_opn = H[i]-open;
            int E_ext = E[i]-gap;
            E[i] = MAX(E_ext, E_opn);
            HT[1LL*i*s2Len + j] = (E_opn > E_ext) ? PARASAIL_DIAG_E
                                                  : PARASAIL_INS_E;
        }
        /* calculate Ht */
        Ht[-1] = 0;
        for (i=0; i<s1Len; ++i) {
            int matval = matrix->type == PARASAIL_MATRIX_TYPE_SQUARE ?
                         matrix->matrix[matrix->size*s1[i]+s2[j]] :
                         matrix->matrix[matrix->size*i+s2[j]];
            int H_dag = H[i-1]+matval;
            Ht[i] = MAX(H_dag, E[i]);
            Ex[i] = (E[i] > H_dag);
        }
        /* calculate H */
        for (i=0; i<s1Len; ++i) {
            int Ft_opn;
            int Ht_pre = Ht[i-1];
            int Ft_ext = Ft-gap;
            if (Ht_pre >= Ft_ext) {
                Ft = Ht_pre;
            }
            else {
                Ft = Ft_ext;
            }
            Ft_opn = Ft-open;
            if (H[i-1] > Ft_ext) {
                HT[1LL*i*s2Len + j] |= PARASAIL_DIAG_F;
            }
            else {
                HT[1LL*i*s2Len + j] |= PARASAIL_DEL_F;
            }
            if (Ht[i] > Ft_opn) {
                H[i] = Ht[i];
                HT[1LL*i*s2Len + j] |= Ex[i] ? PARASAIL_INS : PARASAIL_DIAG;
            }
            else {
                H[i] = Ft_opn;
                if (Ht[i] == Ft_opn) {
                    if (Ex[i]) {
                        HT[1LL*i*s2Len + j] |= PARASAIL_DEL;
                    }
                    else {
                        HT[1LL*i*s2Len + j] |= PARASAIL_DIAG;
                    }
                }
                else {
                    HT[1LL*i*s2Len + j] |= PARASAIL_DEL;
                }
            }
            if (0 >= H[i]) {
                H[i] = 0;
                HT[1LL*i*s2Len + j] &= PARASAIL_ZERO_MASK;
            }
            if (H[i] > score) {
                score = H[i];
                end_query = i;
                end_ref = j;
            }
        }
    }

    result->score = score;
    result->end_query = end_query;
    result->end_ref = end_ref;

    parasail_free(Ex);
    parasail_free(HtB);
    parasail_free(E);
    parasail_free(HB);
    parasail_free(s2);
    if (matrix->type == PARASAIL_MATRIX_TYPE_SQUARE) {
        parasail_free(s1);
    }

    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, 0x10(%rsp)
movl %r8d, 0x14(%rsp)
testq %rdx, %rdx
je 0x24f7da
movl %ecx, %ebx
testl %ecx, %ecx
jle 0x24f7fe
cmpl $0x0, 0x14(%rsp)
js 0x24f822
cmpl $0x0, 0x10(%rsp)
js 0x24f846
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0x24f867
cmpl $0x0, 0x30(%rax)
je 0x24f3f9
movl 0x34(%rax), %ebp
jmp 0x24f40c
testq %rdi, %rdi
je 0x24f888
movl %esi, %ebp
testl %esi, %esi
jle 0x24f8a9
movq %rdi, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
pushq $0x10
popq %rdx
pushq $0x1
popq %rcx
movl %ebp, %edi
movl %ebx, %esi
callq 0x1abb59
testq %rax, %rax
je 0x24f8cf
movq %rax, 0x30(%rsp)
orl $0x1480204, 0xc(%rax)   # imm = 0x1480204
movl %ebx, %r15d
movl %ebx, %r13d
pushq $0x10
popq %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x1ab76d
movq %rax, 0x28(%rsp)
leal 0x1(%rbp), %eax
movslq %eax, %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1ab76d
movq %rax, %r12
movq %rbp, %r14
movslq %ebp, %rsi
movq %rsi, 0x8(%rsp)
pushq $0x10
popq %rdi
callq 0x1ab76d
movq %rax, %rbp
pushq $0x10
popq %rdi
movq %rbx, %rsi
callq 0x1ab76d
movq %rax, %rbx
pushq $0x10
popq %rdi
movq 0x8(%rsp), %rsi
callq 0x1ab76d
movq %rax, %r10
movq 0x28(%rsp), %xmm0
movq %r12, %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq %rbp, %xmm1
movq %rbx, %xmm2
punpcklqdq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0]
pxor %xmm2, %xmm2
pcmpeqd %xmm2, %xmm0
pcmpeqd %xmm2, %xmm1
movdqa %xmm0, %xmm2
shufps $0xdd, %xmm1, %xmm2     # xmm2 = xmm2[1,3],xmm1[1,3]
shufps $0x88, %xmm1, %xmm0     # xmm0 = xmm0[0,2],xmm1[0,2]
andps %xmm2, %xmm0
movmskps %xmm0, %eax
xorl %r9d, %r9d
testl %eax, %eax
jne 0x24f8d2
testq %r10, %r10
je 0x24f8d2
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rdi
movq 0x80(%rsp), %r11
cmpl $0x0, 0x30(%r11)
movq %r10, 0x20(%rsp)
je 0x24f76b
movq $0x0, 0x8(%rsp)
movq 0x38(%rsp), %r8
movq 0x10(%r11), %rax
xorl %ecx, %ecx
movq 0x28(%rsp), %rsi
cmpq %rcx, %r13
je 0x24f53d
movzbl (%r8,%rcx), %edx
movl (%rax,%rdx,4), %edx
movl %edx, (%rsi,%rcx,4)
incq %rcx
jmp 0x24f528
andl $0x0, (%r12)
andl $0x0, (%rbx)
xorl %ecx, %ecx
movq %r14, %rdx
testl %edx, %edx
movl $0x0, %eax
cmovgl %edx, %eax
cmpq %rcx, %rax
je 0x24f564
andl $0x0, 0x4(%r12,%rcx,4)
incq %rcx
jmp 0x24f554
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x24f578
movl $0xc0000000, (%rbp,%rcx,4) # imm = 0xC0000000
incq %rcx
jmp 0x24f566
movl $0xc0000000, %ecx       # imm = 0xC0000000
xorl %edx, %edx
cmpq %r13, %rdx
je 0x24f714
movq %rdi, 0x18(%rsp)
movq %rdi, %rsi
xorl %edi, %edi
cmpq %rdi, %rax
je 0x24f5ce
movl 0x4(%r12,%rdi,4), %r8d
subl 0x14(%rsp), %r8d
movl (%rbp,%rdi,4), %r9d
subl 0x10(%rsp), %r9d
cmpl %r8d, %r9d
cmovlel %r8d, %r9d
movl %r9d, (%rbp,%rdi,4)
setge %r8b
shlb $0x3, %r8b
addb $0x8, %r8b
movb %r8b, (%rsi)
incq %rdi
addq %r13, %rsi
jmp 0x24f592
andl $0x0, (%rbx)
xorl %esi, %esi
cmpq %rsi, %rax
je 0x24f630
cmpl $0x0, 0x30(%r11)
movl 0x18(%r11), %edi
je 0x24f5e8
imull %esi, %edi
jmp 0x24f5f2
movq 0x8(%rsp), %r8
imull (%r8,%rsi,4), %edi
movq 0x8(%r11), %r8
movq 0x28(%rsp), %r9
movslq (%r9,%rdx,4), %r9
movslq %edi, %rdi
addq %r9, %rdi
movl (%r12,%rsi,4), %r9d
addl (%r8,%rdi,4), %r9d
movl (%rbp,%rsi,4), %edi
cmpl %edi, %r9d
cmovgl %r9d, %edi
movl %edi, 0x4(%rbx,%rsi,4)
xorl %edi, %edi
cmpl %r9d, (%rbp,%rsi,4)
setg %dil
movl %edi, (%r10,%rsi,4)
incq %rsi
jmp 0x24f5d3
movl $0xc0000000, %r8d       # imm = 0xC0000000
movq 0x18(%rsp), %rsi
xorl %edi, %edi
cmpq %rdi, %rax
je 0x24f704
movl %r8d, %r10d
movl (%rbx,%rdi,4), %r8d
subl 0x10(%rsp), %r10d
cmpl %r10d, %r8d
cmovlel %r10d, %r8d
movl %r8d, %r9d
subl 0x14(%rsp), %r9d
cmpl %r10d, (%r12,%rdi,4)
setle %r10b
shlb $0x5, %r10b
addb $0x20, %r10b
orb %r10b, (%rsi)
movl 0x4(%rbx,%rdi,4), %r10d
cmpl %r9d, %r10d
jle 0x24f6a0
movl %r10d, 0x4(%r12,%rdi,4)
xorl %r9d, %r9d
movq 0x20(%rsp), %r10
cmpl $0x0, (%r10,%rdi,4)
sete %r9b
leal (%r9,%r9,2), %r9d
incl %r9d
orb %r9b, (%rsi)
jmp 0x24f6d2
movl %r9d, 0x4(%r12,%rdi,4)
cmpl %r9d, 0x4(%rbx,%rdi,4)
jne 0x24f6c1
movq 0x20(%rsp), %r10
cmpl $0x0, (%r10,%rdi,4)
movb (%rsi), %r9b
je 0x24f6cb
orb $0x2, %r9b
jmp 0x24f6cf
orb $0x2, (%rsi)
movq 0x20(%rsp), %r10
jmp 0x24f6d2
orb $0x4, %r9b
movb %r9b, (%rsi)
movl 0x4(%r12,%rdi,4), %r9d
testl %r9d, %r9d
jg 0x24f6ea
andl $0x0, 0x4(%r12,%rdi,4)
andb $0x78, (%rsi)
movl 0x4(%r12,%rdi,4), %r9d
cmpl %ecx, %r9d
cmovgl %r9d, %ecx
cmovgl %edi, %r14d
cmovgl %edx, %r15d
incq %rdi
addq %r13, %rsi
jmp 0x24f63d
incq %rdx
movq 0x18(%rsp), %rdi
incq %rdi
jmp 0x24f57f
movq 0x30(%rsp), %r13
movl %ecx, (%r13)
movl %r14d, 0x4(%r13)
movl %r15d, 0x8(%r13)
movq %r10, %rdi
movq %r11, %r14
callq 0x1ab763
movq %rbx, %rdi
callq 0x1ab763
movq %rbp, %rdi
callq 0x1ab763
movq %r12, %rdi
callq 0x1ab763
movq 0x28(%rsp), %rdi
callq 0x1ab763
cmpl $0x0, 0x30(%r14)
jne 0x24f763
movq 0x8(%rsp), %rdi
callq 0x1ab763
movq %r13, %r9
jmp 0x24f8d2
movq %rdi, 0x18(%rsp)
pushq $0x10
popq %rdi
movq 0x8(%rsp), %rsi
callq 0x1ab76d
xorl %r9d, %r9d
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x24f8d2
movq %r14, %rcx
testl %ecx, %ecx
movl $0x0, %eax
cmovgl %ecx, %eax
movq 0x80(%rsp), %r11
movq 0x20(%rsp), %r10
movq 0x18(%rsp), %rdi
movq 0x38(%rsp), %r8
movq 0x40(%rsp), %rsi
cmpq %r9, %rax
je 0x24f51d
movq 0x10(%r11), %rcx
movzbl (%rsi,%r9), %edx
movl (%rcx,%rdx,4), %ecx
movq 0x8(%rsp), %rdx
movl %ecx, (%rdx,%r9,4)
incq %r9
jmp 0x24f7b7
movq 0x4eb7f7(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x377800(%rip), %rsi    # 0x5c6feb
leaq 0x34786b(%rip), %rdx    # 0x59705d
leaq 0x377f04(%rip), %rcx    # 0x5c76fd
jmp 0x24f8c8
movq 0x4eb7d3(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x377ef2(%rip), %rsi    # 0x5c7701
leaq 0x347847(%rip), %rdx    # 0x59705d
leaq 0x377ef8(%rip), %rcx    # 0x5c7715
jmp 0x24f8c8
movq 0x4eb7af(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x377ee8(%rip), %rsi    # 0x5c771b
leaq 0x347823(%rip), %rdx    # 0x59705d
leaq 0x377eef(%rip), %rcx    # 0x5c7730
jmp 0x24f8c8
movq 0x4eb78b(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x377ec4(%rip), %rsi    # 0x5c771b
leaq 0x3477ff(%rip), %rdx    # 0x59705d
leaq 0x377ed0(%rip), %rcx    # 0x5c7735
jmp 0x24f8c8
movq 0x4eb76a(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x377773(%rip), %rsi    # 0x5c6feb
leaq 0x3477de(%rip), %rdx    # 0x59705d
leaq 0x3780bc(%rip), %rcx    # 0x5c7942
jmp 0x24f8c8
movq 0x4eb749(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x377752(%rip), %rsi    # 0x5c6feb
leaq 0x3477bd(%rip), %rdx    # 0x59705d
leaq 0x377e92(%rip), %rcx    # 0x5c7739
jmp 0x24f8c8
movq 0x4eb728(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x377e47(%rip), %rsi    # 0x5c7701
leaq 0x34779c(%rip), %rdx    # 0x59705d
leaq 0x377e75(%rip), %rcx    # 0x5c773d
xorl %eax, %eax
callq 0x19e180
xorl %r9d, %r9d
movq %r9, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq