// File: /workspace/github_c_makefile_star2_O2/nh13[P]ksw/src/parasail/src/nw_trace_scan.c
// Function: parasail_nw_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;

    /* 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 */
    s1Len = matrix->type == PARASAIL_MATRIX_TYPE_SQUARE ? _s1Len : matrix->length;

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

    /* set known flags */
    result->flag |= PARASAIL_FLAG_NW | 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;
    HT = (int8_t* const restrict)result->trace->trace_table;
    Ex = parasail_memalign_int(16, s1Len);

    /* validate heap variables */
    if (!s2) return NULL;
    if (!HB) return NULL;
    if (!E) return NULL;
    if (!HtB) return NULL;
    if (!HT) 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] = -open - i*gap;
    }

    /* 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 */
        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);
        }
        Ht[-1] = -open -j*gap;
        /* 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;
                }
            }
        }
        H[-1] = -open - j*gap;
    }

    result->score = H[s1Len-1];
    result->end_query = s1Len-1;
    result->end_ref = s2Len-1;

    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 $0x58, %rsp
movl %r8d, 0xc(%rsp)
testq %rdx, %rdx
je 0x24e986
movl %ecx, %ebx
testl %ecx, %ecx
jle 0x24e9aa
cmpl $0x0, 0xc(%rsp)
js 0x24e9ce
movl %r9d, %ebp
testl %r9d, %r9d
js 0x24e9f2
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0x24ea13
cmpl $0x0, 0x30(%rax)
je 0x24e5b2
movl 0x34(%rax), %r14d
jmp 0x24e5c6
testq %rdi, %rdi
je 0x24ea34
movl %esi, %r14d
testl %esi, %esi
jle 0x24ea55
movq %rdi, 0x50(%rsp)
movq %rdx, 0x40(%rsp)
pushq $0x10
popq %rdx
pushq $0x1
popq %rcx
movl %r14d, %edi
movl %ebx, %esi
callq 0x1abb59
testq %rax, %rax
je 0x24ea7b
orl $0x1480201, 0xc(%rax)   # imm = 0x1480201
movl %ebx, 0x34(%rsp)
movl %ebx, %ebx
pushq $0x10
popq %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, 0x48(%rsp)
callq 0x1ab76d
movq %rax, 0x20(%rsp)
leal 0x1(%r14), %eax
movslq %eax, %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x1ab76d
movq %rax, %r12
movq %r14, 0x28(%rsp)
movslq %r14d, %r15
pushq $0x10
popq %rdi
movq %r15, %rsi
callq 0x1ab76d
movq %rax, %r14
pushq $0x10
popq %rdi
movq %r13, %rsi
callq 0x1ab76d
movq %rax, %r13
movq 0x48(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
pushq $0x10
popq %rdi
movq %r15, 0x38(%rsp)
movq %r15, %rsi
callq 0x1ab76d
movq %rax, %r15
movq 0x20(%rsp), %xmm0
movq %r12, %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq %r14, %xmm1
movq %r13, %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 %r8d, %r8d
testl %eax, %eax
jne 0x24ea7e
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x24ea7e
testq %r15, %r15
je 0x24ea7e
movq 0x90(%rsp), %r11
cmpl $0x0, 0x30(%r11)
je 0x24e924
movq $0x0, 0x18(%rsp)
movq 0x40(%rsp), %rdi
movq 0x10(%r11), %rax
xorl %ecx, %ecx
movq 0x20(%rsp), %rsi
cmpq %rcx, %rbx
je 0x24e709
movzbl (%rdi,%rcx), %edx
movl (%rax,%rdx,4), %edx
movl %edx, (%rsi,%rcx,4)
incq %rcx
jmp 0x24e6f5
andl $0x0, (%r12)
andl $0x0, (%r13)
xorl %ecx, %ecx
movq 0x28(%rsp), %rdx
testl %edx, %edx
movl $0x0, %eax
cmovgl %edx, %eax
movl 0xc(%rsp), %edx
negl %edx
cmpq %rcx, %rax
je 0x24e73b
movl %edx, 0x4(%r12,%rcx,4)
incq %rcx
subl %ebp, %edx
jmp 0x24e72a
xorl %ecx, %ecx
movq 0x10(%rsp), %rdx
cmpq %rcx, %rax
je 0x24e754
movl $0xc0000000, (%r14,%rcx,4) # imm = 0xC0000000
incq %rcx
jmp 0x24e742
xorl %ecx, %ecx
cmpq %rbx, %rcx
je 0x24e8bb
movq %rdx, 0x10(%rsp)
xorl %esi, %esi
cmpq %rsi, %rax
je 0x24e79d
movl 0x4(%r12,%rsi,4), %edi
subl 0xc(%rsp), %edi
movl (%r14,%rsi,4), %r8d
subl %ebp, %r8d
cmpl %edi, %r8d
cmovlel %edi, %r8d
movl %r8d, (%r14,%rsi,4)
setge %dil
shlb $0x3, %dil
addb $0x8, %dil
movb %dil, (%rdx)
incq %rsi
addq %rbx, %rdx
jmp 0x24e766
xorl %edx, %edx
cmpq %rdx, %rax
je 0x24e7fb
cmpl $0x0, 0x30(%r11)
movl 0x18(%r11), %esi
je 0x24e7b4
imull %edx, %esi
jmp 0x24e7bd
movq 0x18(%rsp), %rdi
imull (%rdi,%rdx,4), %esi
movq 0x8(%r11), %rdi
movq 0x20(%rsp), %r8
movslq (%r8,%rcx,4), %r8
movslq %esi, %rsi
addq %r8, %rsi
movl (%r12,%rdx,4), %r8d
addl (%rdi,%rsi,4), %r8d
movl (%r14,%rdx,4), %esi
cmpl %esi, %r8d
cmovgl %r8d, %esi
movl %esi, 0x4(%r13,%rdx,4)
xorl %esi, %esi
cmpl %r8d, (%r14,%rdx,4)
setg %sil
movl %esi, (%r15,%rdx,4)
incq %rdx
jmp 0x24e79f
movl %ecx, %edx
imull %ebp, %edx
addl 0xc(%rsp), %edx
negl %edx
movl %edx, (%r13)
movl $0xc0000000, %r8d       # imm = 0xC0000000
movq 0x10(%rsp), %rsi
xorl %edi, %edi
cmpq %rdi, %rax
je 0x24e8a7
movl %r8d, %r10d
movl (%r13,%rdi,4), %r8d
subl %ebp, %r10d
cmpl %r10d, %r8d
cmovlel %r10d, %r8d
movl %r8d, %r9d
subl 0xc(%rsp), %r9d
cmpl %r10d, (%r12,%rdi,4)
setle %r10b
shlb $0x5, %r10b
addb $0x20, %r10b
orb %r10b, (%rsi)
movl 0x4(%r13,%rdi,4), %r10d
cmpl %r9d, %r10d
jle 0x24e874
movl %r10d, 0x4(%r12,%rdi,4)
xorl %r9d, %r9d
cmpl $0x0, (%r15,%rdi,4)
sete %r9b
leal (%r9,%r9,2), %r9d
incl %r9d
orb %r9b, (%rsi)
jmp 0x24e89c
movl %r9d, 0x4(%r12,%rdi,4)
cmpl %r9d, 0x4(%r13,%rdi,4)
jne 0x24e890
cmpl $0x0, (%r15,%rdi,4)
movb (%rsi), %r9b
je 0x24e895
orb $0x2, %r9b
jmp 0x24e899
orb $0x2, (%rsi)
jmp 0x24e89c
orb $0x4, %r9b
movb %r9b, (%rsi)
incq %rdi
addq %rbx, %rsi
jmp 0x24e817
movl %edx, (%r12)
incq %rcx
movq 0x10(%rsp), %rdx
incq %rdx
jmp 0x24e756
movq 0x28(%rsp), %rcx
decl %ecx
movq 0x38(%rsp), %rax
movl (%r12,%rax,4), %eax
movq 0x48(%rsp), %rbp
movl %eax, (%rbp)
movl %ecx, 0x4(%rbp)
movl 0x34(%rsp), %eax
decl %eax
movl %eax, 0x8(%rbp)
movq %r15, %rdi
movq %r11, %rbx
callq 0x1ab763
movq %r13, %rdi
callq 0x1ab763
movq %r14, %rdi
callq 0x1ab763
movq %r12, %rdi
callq 0x1ab763
movq 0x20(%rsp), %rdi
callq 0x1ab763
cmpl $0x0, 0x30(%rbx)
jne 0x24e91c
movq 0x18(%rsp), %rdi
callq 0x1ab763
movq %rbp, %r8
jmp 0x24ea7e
pushq $0x10
popq %rdi
movq 0x38(%rsp), %rsi
callq 0x1ab76d
xorl %r8d, %r8d
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x24ea7e
movq 0x28(%rsp), %rcx
testl %ecx, %ecx
movl $0x0, %eax
cmovgl %ecx, %eax
movq 0x90(%rsp), %r11
movq 0x40(%rsp), %rdi
movq 0x50(%rsp), %rsi
cmpq %r8, %rax
je 0x24e6ea
movq 0x10(%r11), %rcx
movzbl (%rsi,%r8), %edx
movl (%rcx,%rdx,4), %ecx
movq 0x18(%rsp), %rdx
movl %ecx, (%rdx,%r8,4)
incq %r8
jmp 0x24e963
movq 0x4ec64b(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x378654(%rip), %rsi    # 0x5c6feb
leaq 0x34767d(%rip), %rdx    # 0x59601b
leaq 0x378d58(%rip), %rcx    # 0x5c76fd
jmp 0x24ea74
movq 0x4ec627(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x378d46(%rip), %rsi    # 0x5c7701
leaq 0x347659(%rip), %rdx    # 0x59601b
leaq 0x378d4c(%rip), %rcx    # 0x5c7715
jmp 0x24ea74
movq 0x4ec603(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x378d3c(%rip), %rsi    # 0x5c771b
leaq 0x347635(%rip), %rdx    # 0x59601b
leaq 0x378d43(%rip), %rcx    # 0x5c7730
jmp 0x24ea74
movq 0x4ec5df(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x378d18(%rip), %rsi    # 0x5c771b
leaq 0x347611(%rip), %rdx    # 0x59601b
leaq 0x378d24(%rip), %rcx    # 0x5c7735
jmp 0x24ea74
movq 0x4ec5be(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x3785c7(%rip), %rsi    # 0x5c6feb
leaq 0x3475f0(%rip), %rdx    # 0x59601b
leaq 0x378f10(%rip), %rcx    # 0x5c7942
jmp 0x24ea74
movq 0x4ec59d(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x3785a6(%rip), %rsi    # 0x5c6feb
leaq 0x3475cf(%rip), %rdx    # 0x59601b
leaq 0x378ce6(%rip), %rcx    # 0x5c7739
jmp 0x24ea74
movq 0x4ec57c(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x378c9b(%rip), %rsi    # 0x5c7701
leaq 0x3475ae(%rip), %rdx    # 0x59601b
leaq 0x378cc9(%rip), %rcx    # 0x5c773d
xorl %eax, %eax
callq 0x19e180
xorl %r8d, %r8d
movq %r8, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq