// File: /workspace/github_c_makefile_star2_O2/nh13[P]ksw/src/parasail/src/nw_scan.c
// Function: parasail_nw_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;
    int s1Len = 0;
    int i = 0;
    int j = 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 */
#ifdef PARASAIL_TABLE
    result = parasail_result_new_table1(s1Len, s2Len);
#else
#ifdef PARASAIL_ROWCOL
    result = parasail_result_new_rowcol1(s1Len, s2Len);
#else
    result = parasail_result_new();
#endif
#endif
    if (!result) return NULL;

    /* set known flags */
    result->flag |= PARASAIL_FLAG_NW | PARASAIL_FLAG_NOVEC_SCAN
        | PARASAIL_FLAG_BITS_INT | PARASAIL_FLAG_LANES_1;
#ifdef PARASAIL_TABLE
    result->flag |= PARASAIL_FLAG_TABLE;
#endif
#ifdef PARASAIL_ROWCOL
    result->flag |= PARASAIL_FLAG_ROWCOL;
#endif

    /* 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;

    /* validate heap variables */
    if (!s2) return NULL;
    if (!HB) return NULL;
    if (!E) return NULL;
    if (!HtB) 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) {
            E[i] = MAX(E[i]-gap, H[i]-open);
        }
        /* 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]];
            Ht[i] = MAX(H[i-1]+matval, E[i]);
        }
        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;
            H[i] = MAX(Ht[i], Ft_opn);
#ifdef PARASAIL_TABLE
            result->tables->score_table[i*s2Len + j] = H[i];
#endif
        }
        H[-1] = -open - j*gap;
#ifdef PARASAIL_ROWCOL
        if (j == s2Len-1) {
            for (i=0; i<s1Len; ++i) {
                result->rowcols->score_col[i] = H[i];
            }
        }
        result->rowcols->score_row[j] = H[s1Len-1];
#endif
    }

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

    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
testq %rdx, %rdx
je 0x23cf98
movl %ecx, %ebp
testl %ecx, %ecx
jle 0x23cfbc
movl %r8d, %r12d
testl %r8d, %r8d
js 0x23cfe0
movl %r9d, %r14d
testl %r9d, %r9d
js 0x23d004
movq 0x80(%rsp), %r13
testq %r13, %r13
je 0x23d028
cmpl $0x0, 0x30(%r13)
je 0x23ce53
movl 0x34(%r13), %r15d
jmp 0x23ce67
testq %rdi, %rdi
je 0x23d1db
movl %esi, %r15d
testl %esi, %esi
jle 0x23d1fc
movq %rdi, 0x38(%rsp)
movq %rdx, 0x28(%rsp)
xorl %eax, %eax
callq 0x1ab7ed
testq %rax, %rax
je 0x23cf2b
movq %rax, %rbx
orl $0x1400201, 0xc(%rax)   # imm = 0x1400201
movl %ebp, %esi
pushq $0x10
popq %rdi
movq %rsi, 0x30(%rsp)
callq 0x1ab76d
movq %rax, (%rsp)
leal 0x1(%r15), %eax
movslq %eax, %rsi
movq %rsi, 0x40(%rsp)
pushq $0x10
popq %rdi
callq 0x1ab76d
movl %ebp, 0x24(%rsp)
movq %rax, %rbp
movq %r15, 0x18(%rsp)
movslq %r15d, %rsi
pushq $0x10
popq %rdi
movq %rdi, %r15
movq %rsi, 0x8(%rsp)
callq 0x1ab76d
movq %rbx, 0x10(%rsp)
movq %rax, %rbx
movq %r15, %rdi
movq 0x40(%rsp), %rsi
callq 0x1ab76d
movq (%rsp), %r10
movq %rax, %r15
movq %r10, %xmm0
movq %rbp, %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq %rbx, %xmm1
movq %rax, %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
testl %eax, %eax
je 0x23cf32
xorl %ebx, %ebx
jmp 0x23d224
cmpl $0x0, 0x30(%r13)
je 0x23cf4a
xorl %eax, %eax
movq 0x8(%rsp), %rsi
movq 0x28(%rsp), %r8
jmp 0x23d051
pushq $0x10
popq %rdi
movq 0x8(%rsp), %rsi
callq 0x1ab76d
xorl %edi, %edi
testq %rax, %rax
je 0x23cf2b
movq 0x18(%rsp), %rdx
testl %edx, %edx
movl $0x0, %ecx
cmovgl %edx, %ecx
movq (%rsp), %r10
movq 0x28(%rsp), %r8
movq 0x38(%rsp), %r9
cmpq %rdi, %rcx
je 0x23d04c
movq 0x10(%r13), %rdx
movzbl (%r9,%rdi), %esi
movl (%rdx,%rsi,4), %edx
movl %edx, (%rax,%rdi,4)
incq %rdi
jmp 0x23cf7b
movq 0x4fe039(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x38a042(%rip), %rsi    # 0x5c6feb
leaq 0x32bf26(%rip), %rdx    # 0x568ed6
leaq 0x38a746(%rip), %rcx    # 0x5c76fd
jmp 0x23d21b
movq 0x4fe015(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x38a734(%rip), %rsi    # 0x5c7701
leaq 0x32bf02(%rip), %rdx    # 0x568ed6
leaq 0x38a73a(%rip), %rcx    # 0x5c7715
jmp 0x23d21b
movq 0x4fdff1(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x38a72a(%rip), %rsi    # 0x5c771b
leaq 0x32bede(%rip), %rdx    # 0x568ed6
leaq 0x38a731(%rip), %rcx    # 0x5c7730
jmp 0x23d21b
movq 0x4fdfcd(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x38a706(%rip), %rsi    # 0x5c771b
leaq 0x32beba(%rip), %rdx    # 0x568ed6
leaq 0x38a712(%rip), %rcx    # 0x5c7735
jmp 0x23d21b
movq 0x4fdfa9(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x389fb2(%rip), %rsi    # 0x5c6feb
leaq 0x32be96(%rip), %rdx    # 0x568ed6
leaq 0x38a8fb(%rip), %rcx    # 0x5c7942
jmp 0x23d21b
movq 0x8(%rsp), %rsi
movq 0x10(%r13), %rdi
xorl %ecx, %ecx
cmpq %rcx, 0x30(%rsp)
je 0x23d06f
movzbl (%r8,%rcx), %edx
movl (%rdi,%rdx,4), %edx
movl %edx, (%r10,%rcx,4)
incq %rcx
jmp 0x23d057
andl $0x0, (%rbp)
andl $0x0, (%r15)
xorl %ecx, %ecx
movq 0x18(%rsp), %rdx
testl %edx, %edx
movl $0x0, %r11d
cmovgl %edx, %r11d
movl %r12d, %edx
negl %edx
cmpq %rcx, %r11
je 0x23d0a0
movl %edx, 0x4(%rbp,%rcx,4)
incq %rcx
subl %r14d, %edx
jmp 0x23d08f
xorl %ecx, %ecx
cmpq %rcx, %r11
je 0x23d0b3
movl $0xc0000000, (%rbx,%rcx,4) # imm = 0xC0000000
incq %rcx
jmp 0x23d0a2
xorl %ecx, %ecx
movq %rax, (%rsp)
cmpq 0x30(%rsp), %rcx
je 0x23d183
xorl %edx, %edx
cmpq %rdx, %r11
je 0x23d0e5
movl (%rbx,%rdx,4), %esi
subl %r14d, %esi
movl 0x4(%rbp,%rdx,4), %edi
subl %r12d, %edi
cmpl %edi, %esi
cmovgl %esi, %edi
movl %edi, (%rbx,%rdx,4)
incq %rdx
jmp 0x23d0c6
xorl %edx, %edx
cmpq %rdx, %r11
je 0x23d12b
cmpl $0x0, 0x30(%r13)
movl 0x18(%r13), %esi
je 0x23d0fc
imull %edx, %esi
jmp 0x23d100
imull (%rax,%rdx,4), %esi
movq 0x8(%r13), %rdi
movslq (%r10,%rcx,4), %r8
movslq %esi, %rsi
addq %r8, %rsi
movl (%rbp,%rdx,4), %r8d
addl (%rdi,%rsi,4), %r8d
movl (%rbx,%rdx,4), %esi
cmpl %esi, %r8d
cmovlel %esi, %r8d
movl %r8d, 0x4(%r15,%rdx,4)
incq %rdx
jmp 0x23d0e7
movl %ecx, %edx
imull %r14d, %edx
addl %r12d, %edx
negl %edx
movl %edx, (%r15)
movl $0xc0000000, %esi       # imm = 0xC0000000
xorl %edi, %edi
cmpq %rdi, %r11
je 0x23d16f
subl %r14d, %esi
movl (%r15,%rdi,4), %r8d
cmpl %esi, %r8d
cmovgl %r8d, %esi
movl 0x4(%r15,%rdi,4), %r8d
movl %esi, %r9d
subl %r12d, %r9d
cmpl %r9d, %r8d
cmovgl %r8d, %r9d
movl %r9d, 0x4(%rbp,%rdi,4)
incq %rdi
jmp 0x23d140
movl %edx, (%rbp)
incq %rcx
movq 0x8(%rsp), %rsi
movq (%rsp), %rax
jmp 0x23d0b9
movq 0x18(%rsp), %rdx
decl %edx
movl (%rbp,%rsi,4), %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
movl %edx, 0x4(%rcx)
movl 0x24(%rsp), %eax
decl %eax
movl %eax, 0x8(%rcx)
movq %r15, %rdi
movq %r10, %r14
callq 0x1ab763
movq %rbx, %rdi
callq 0x1ab763
movq %rbp, %rdi
callq 0x1ab763
movq %r14, %rdi
callq 0x1ab763
cmpl $0x0, 0x30(%r13)
jne 0x23d1d4
movq (%rsp), %rdi
callq 0x1ab763
movq 0x10(%rsp), %rbx
jmp 0x23d224
movq 0x4fddf6(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x389dff(%rip), %rsi    # 0x5c6feb
leaq 0x32bce3(%rip), %rdx    # 0x568ed6
leaq 0x38a53f(%rip), %rcx    # 0x5c7739
jmp 0x23d21b
movq 0x4fddd5(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x38a4f4(%rip), %rsi    # 0x5c7701
leaq 0x32bcc2(%rip), %rdx    # 0x568ed6
leaq 0x38a522(%rip), %rcx    # 0x5c773d
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x19e180
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop