// File: /workspace/github_c_makefile_star2_O1/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
movq %rdx, 0x40(%rsp)
testq %rdx, %rdx
je 0x2a9fd2
movl %ecx, %ebp
testl %ecx, %ecx
jle 0x2a9fd9
testl %r8d, %r8d
js 0x2a9fe0
testl %r9d, %r9d
js 0x2a9fe7
movq 0x90(%rsp), %rcx
testq %rcx, %rcx
je 0x2a9fee
movq %rdi, %rbx
movl 0x30(%rcx), %eax
testl %eax, %eax
jne 0x2a9be7
testq %rbx, %rbx
je 0x2a9fff
movl %esi, %r14d
testl %esi, %esi
jle 0x2aa006
testl %eax, %eax
je 0x2a9beb
movl 0x34(%rcx), %r14d
movl %r8d, 0x4(%rsp)
movl %r9d, (%rsp)
movl $0x10, %edx
movl $0x1, %ecx
movl %r14d, %edi
movl %ebp, %esi
callq 0x2097d1
testq %rax, %rax
je 0x2aa00b
movq %rbx, 0x50(%rsp)
orl $0x1480201, 0xc(%rax)   # imm = 0x1480201
movl %ebp, 0x14(%rsp)
movl %ebp, %ebx
movl $0x10, %edi
movq %rbx, %rsi
movq %rax, 0x38(%rsp)
callq 0x2094bf
movq %rax, 0x18(%rsp)
leal 0x1(%r14), %eax
movslq %eax, %r15
movl $0x10, %edi
movq %r15, %rsi
callq 0x2094bf
movq %rax, %r12
movq %r14, 0x8(%rsp)
movslq %r14d, %rbp
movl $0x10, %edi
movq %rbp, %rsi
callq 0x2094bf
movq %rax, %r14
movl $0x10, %edi
movq %r15, %rsi
callq 0x2094bf
movq %rax, %r13
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movl $0x10, %edi
movq %rbp, 0x30(%rsp)
movq %rbp, %rsi
callq 0x2094bf
movq 0x18(%rsp), %rdi
movq %rax, %r15
xorl %eax, %eax
testq %rdi, %rdi
je 0x2aa00d
testq %r12, %r12
je 0x2aa00d
testq %r14, %r14
je 0x2aa00d
testq %r13, %r13
je 0x2aa00d
cmpq $0x0, 0x20(%rsp)
je 0x2aa00d
testq %r15, %r15
je 0x2aa00d
movq 0x90(%rsp), %r11
cmpl $0x0, 0x30(%r11)
movl 0x8(%rsp), %ebp
je 0x2a9f67
movq $0x0, 0x28(%rsp)
movl (%rsp), %r9d
movl 0x4(%rsp), %r10d
movq 0x40(%rsp), %r8
movq 0x10(%r11), %rax
movl 0x14(%rsp), %edx
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
xorl %edx, %edx
movzbl (%r8,%rdx), %esi
movl (%rax,%rsi,4), %esi
movl %esi, (%rdi,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x2a9d22
xorl %eax, %eax
movl %eax, (%r12)
movl %eax, (%r13)
cmpl $0x0, 0x8(%rsp)
jle 0x2a9d5d
movl %r10d, %eax
negl %eax
xorl %ecx, %ecx
movl %eax, 0x4(%r12,%rcx,4)
incq %rcx
subl %r9d, %eax
cmpq %rcx, %rbp
jne 0x2a9d4d
cmpl $0x0, 0x8(%rsp)
jle 0x2a9d76
xorl %eax, %eax
movl $0xc0000000, (%r14,%rax,4) # imm = 0xC0000000
incq %rax
cmpq %rax, %rbp
jne 0x2a9d66
movl 0x14(%rsp), %ecx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
xorl %ecx, %ecx
cmpl $0x0, 0x8(%rsp)
jle 0x2a9dc9
movq 0x20(%rsp), %rdx
xorl %esi, %esi
movl 0x4(%r12,%rsi,4), %edi
subl %r10d, %edi
movl (%r14,%rsi,4), %r8d
subl %r9d, %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
cmpq %rsi, %rbp
jne 0x2a9d95
cmpl $0x0, 0x8(%rsp)
jle 0x2a9e30
movq 0x8(%r11), %rdx
xorl %esi, %esi
cmpl $0x0, 0x30(%r11)
je 0x2a9de6
movl 0x18(%r11), %edi
imull %esi, %edi
jmp 0x2a9df3
movq 0x28(%rsp), %rdi
movl (%rdi,%rsi,4), %edi
imull 0x18(%r11), %edi
movq 0x18(%rsp), %r8
movslq (%r8,%rcx,4), %r8
movslq %edi, %rdi
addq %r8, %rdi
movl (%r12,%rsi,4), %r8d
addl (%rdx,%rdi,4), %r8d
movl (%r14,%rsi,4), %edi
cmpl %edi, %r8d
cmovgl %r8d, %edi
movl %edi, 0x4(%r13,%rsi,4)
xorl %edi, %edi
cmpl %r8d, (%r14,%rsi,4)
setg %dil
movl %edi, (%r15,%rsi,4)
incq %rsi
cmpq %rsi, %rbp
jne 0x2a9dd6
movl %ecx, %edx
imull %r9d, %edx
addl %r10d, %edx
negl %edx
movl %edx, (%r13)
cmpl $0x0, 0x8(%rsp)
jle 0x2a9ee4
movl $0xc0000000, %r8d       # imm = 0xC0000000
movq 0x20(%rsp), %rsi
xorl %edi, %edi
movl %r8d, %r10d
movl (%r13,%rdi,4), %r8d
subl %r9d, %r10d
cmpl %r10d, %r8d
cmovlel %r10d, %r8d
movl %r8d, %r9d
subl 0x4(%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 0x2a9eab
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 0x2a9eca
movl %r9d, 0x4(%r12,%rdi,4)
cmpl %r9d, 0x4(%r13,%rdi,4)
jne 0x2a9ec7
cmpl $0x0, (%r15,%rdi,4)
movl (%rsp), %r9d
je 0x2a9edf
orb $0x2, (%rsi)
jmp 0x2a9ece
orb $0x2, (%rsi)
movl (%rsp), %r9d
incq %rdi
addq %rbx, %rsi
cmpq %rdi, %rbp
jne 0x2a9e57
jmp 0x2a9ee4
orb $0x4, (%rsi)
jmp 0x2a9ece
movl %edx, (%r12)
incq %rcx
incq 0x20(%rsp)
cmpq %rax, %rcx
movl 0x4(%rsp), %r10d
jne 0x2a9d87
movq 0x8(%rsp), %rcx
decl %ecx
movq 0x30(%rsp), %rax
movl (%r12,%rax,4), %eax
movq 0x38(%rsp), %rbp
movl %eax, (%rbp)
movl %ecx, 0x4(%rbp)
movl 0x14(%rsp), %eax
decl %eax
movl %eax, 0x8(%rbp)
movq %r15, %rdi
movq %r11, %rbx
callq 0x2094b5
movq %r13, %rdi
callq 0x2094b5
movq %r14, %rdi
callq 0x2094b5
movq %r12, %rdi
callq 0x2094b5
movq 0x18(%rsp), %rdi
callq 0x2094b5
cmpl $0x0, 0x30(%rbx)
jne 0x2a9f5f
movq 0x28(%rsp), %rdi
callq 0x2094b5
movq %rbp, %rax
jmp 0x2aa00d
movl $0x10, %edi
movq 0x30(%rsp), %rsi
callq 0x2094bf
testq %rax, %rax
je 0x2aa00b
cmpl $0x0, 0x8(%rsp)
movl (%rsp), %r9d
movl 0x4(%rsp), %r10d
movq 0x40(%rsp), %r8
movq %rax, 0x28(%rsp)
movq 0x90(%rsp), %r11
jle 0x2a9ff5
movq 0x10(%r11), %rcx
movq %rcx, 0x48(%rsp)
xorl %ecx, %ecx
movq 0x18(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movzbl (%rdx,%rcx), %edx
movl (%rsi,%rdx,4), %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
cmpq %rcx, %rbp
jne 0x2a9fb6
jmp 0x2a9d0d
callq 0x1a223b
jmp 0x2aa00b
callq 0x1a2215
jmp 0x2aa00b
callq 0x1a21ef
jmp 0x2aa00b
callq 0x1a21c9
jmp 0x2aa00b
callq 0x1a21a3
jmp 0x2aa00b
movq 0x18(%rsp), %rdi
jmp 0x2a9d0d
callq 0x1a217d
jmp 0x2aa00b
callq 0x1a2157
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq