// File: /workspace/github_c_makefile_star2_O2/nh13[P]ksw/src/parasail/src/nw_banded.c
// Function: parasail_nw_banded
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 int k,
        const parasail_matrix_t *matrix)
{
    /* declare local variables */
    parasail_result_t *result = NULL;
    int * restrict s1 = NULL;
    int * restrict s2 = NULL;
    int * HB = NULL;
    int * H = NULL;
    int * EB = NULL;
    int * E = NULL;
    int i = 0;
    int j = 0;
    int low = 0;
    int colLen = 0;
    int colOff = 0;

    /* validate inputs */
    PARASAIL_CHECK_NULL(_s1);
    PARASAIL_CHECK_GT0(s1Len);
    PARASAIL_CHECK_NULL(_s2);
    PARASAIL_CHECK_GT0(s2Len);
    PARASAIL_CHECK_GE0(open);
    PARASAIL_CHECK_GE0(gap);
    PARASAIL_CHECK_GT0(k);
    PARASAIL_CHECK_NULL(matrix);

    /* initialize stack variables */

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

    /* initalize heap variables */
    s1 = parasail_memalign_int(16, s1Len);
    s2 = parasail_memalign_int(16, s2Len);

    /* validate heap variables */
    if (!s1) return NULL;
    if (!s2) return NULL;

    low = s1Len - s2Len - k;
    if (s1Len > s2Len) {
        low = s2Len - s1Len - k;
    }
    colLen = k-low+1;
    colOff = s1Len > s2Len ? -k : low;

    HB = parasail_memalign_int(16, colLen+2);
    if (!HB) return NULL;
    H = HB+1;
    EB = parasail_memalign_int(16, colLen+2);
    if (!EB) return NULL;
    E = EB+1;
    parasail_memset_int(HB, 0, colLen+2);
    parasail_memset_int(EB, 0, colLen+2);

    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]];
    }

#ifdef PARASAIL_TABLE
    /* fill the table with zeros */
    {
        int limit = s1Len*s2Len;
        for (i=0; i<limit; ++i) {
            result->tables->score_table[i] = 0;
        }
    }
#endif

    /* initialize H */
    /* initialize E */
    for (i=-colOff+1,j=0; i<colLen; ++i, ++j) {
        H[i] = -open - j*gap;
        E[i] = NEG_INF_32;
    }
    H[-colOff-1] = -open;
    E[-colOff-1] = NEG_INF_32;
    H[-colOff] = 0;
    E[-colOff] = NEG_INF_32;
    H[-1] = NEG_INF_32;
    E[-1] = NEG_INF_32;
    H[colLen] = NEG_INF_32;
    E[colLen] = NEG_INF_32;

    /* iter over db */
    for (j=0; j<s2Len; ++j) {
        /* substitution matrix row (really we wanted a column) */
        int F = NEG_INF_32;
        if (colOff < 0) {
            H[-colOff-1] = -open - j*gap;
        }
        /* iter over query */
        for (i=0; i<colLen; ++i) {
            int pos = 0;
            int H_dag = 0;
            int E_opn = 0;
            int E_ext = 0;
            int F_opn = 0;
            int F_ext = 0;
            int matval = 0;
            pos = colOff+i;
            if (pos < 0 || pos >= s1Len) {
                continue;
            }
            matval = matrix->type == PARASAIL_MATRIX_TYPE_SQUARE ?
                     matrix->matrix[matrix->size*s1[pos]+s2[j]] :
                     matrix->matrix[matrix->size*pos+s2[j]];
            H_dag = H[i] + matval;
            E_opn = H[i+1] - open;
            E_ext = E[i+1] - gap;
            F_opn = H[i-1] - open;
            F_ext = F - gap;
            E[i] = MAX(E_opn, E_ext);
            F = MAX(F_opn, F_ext);
            H[i] = MAX(E[i], F);
            H[i] = MAX(H[i], H_dag);
#ifdef PARASAIL_TABLE
            result->tables->score_table[pos*s2Len + j] = H[i];
#endif
        }
        colOff += 1;
    }

    result->score = s1Len > s2Len ? H[-low] : H[k];
    result->end_query = s1Len-1;
    result->end_ref = s2Len-1;

    parasail_free(EB);
    parasail_free(HB);
    parasail_free(s2);
    parasail_free(s1);

    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r8d, 0x4(%rsp)
testq %rdi, %rdi
je 0x28767d
movl %esi, %r15d
testl %esi, %esi
jle 0x2876a1
movq %rdx, %r14
testq %rdx, %rdx
je 0x2876c5
movl %ecx, %r13d
testl %ecx, %ecx
jle 0x2876e9
cmpl $0x0, 0x4(%rsp)
js 0x28770d
movl %r9d, %ebp
testl %r9d, %r9d
js 0x28772e
movl 0xa0(%rsp), %eax
testl %eax, %eax
jle 0x28774f
cmpq $0x0, 0xa8(%rsp)
je 0x287770
movq %rdi, 0x18(%rsp)
xorl %eax, %eax
callq 0x1f47e9
testq %rax, %rax
je 0x287452
movq %rax, %rbx
movq %r14, 0x10(%rsp)
orl $0x1400181, 0xc(%rax)   # imm = 0x1400181
movl %r15d, %r12d
pushq $0x10
popq %rdi
movq %r12, %rsi
callq 0x1f4769
movq %rax, %r14
movl %r13d, %esi
pushq $0x10
popq %rdi
movq %rsi, 0x48(%rsp)
callq 0x1f4769
testq %r14, %r14
sete %dl
testq %rax, %rax
sete %cl
orb %dl, %cl
jne 0x287452
movq %rax, 0x28(%rsp)
movq %r14, 0x40(%rsp)
movq %rbx, 0x60(%rsp)
movl 0xa0(%rsp), %eax
movq %rax, %rdx
negl %eax
movl %r15d, %esi
subl %r13d, %esi
subl %edx, %esi
movl %r13d, %ebx
subl %r15d, %ebx
subl %edx, %ebx
movq %r13, 0x58(%rsp)
cmpl %r13d, %r15d
cmovbel %esi, %ebx
cmoval %eax, %esi
movl %esi, 0x3c(%rsp)
movl %edx, %r14d
subl %ebx, %r14d
leal 0x3(%r14), %eax
movslq %eax, %r13
pushq $0x10
popq %rdi
movq %r13, %rsi
callq 0x1f4769
testq %rax, %rax
je 0x287452
movq %rax, 0x8(%rsp)
pushq $0x10
popq %rdi
movq %r13, %rsi
callq 0x1f4769
testq %rax, %rax
je 0x287452
movl %ebx, 0x38(%rsp)
movq %r14, 0x50(%rsp)
leal 0x1(%r14), %ecx
movl %ecx, 0x34(%rsp)
xorl %ebx, %ebx
movq %rax, %r14
movq 0x8(%rsp), %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x1f4796
movq %r14, 0x20(%rsp)
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x1f4796
movq 0xa8(%rsp), %r14
movq 0x10(%r14), %rax
movq 0x40(%rsp), %r8
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
cmpq %rbx, %r12
je 0x287459
movzbl (%rdx,%rbx), %ecx
movl (%rax,%rcx,4), %ecx
movl %ecx, (%r8,%rbx,4)
incq %rbx
jmp 0x28743d
xorl %ebx, %ebx
jmp 0x287798
movq 0x10(%r14), %rax
xorl %ecx, %ecx
movq 0x48(%rsp), %rbx
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %r9
cmpq %rcx, %rbx
je 0x287483
movzbl (%r9,%rcx), %edx
movl (%rax,%rdx,4), %edx
movl %edx, (%rsi,%rcx,4)
incq %rcx
jmp 0x28746e
pushq $0x1
popq %rax
movl 0x3c(%rsp), %r9d
subl %r9d, %eax
movslq %eax, %rcx
movslq 0x50(%rsp), %rax
movl 0x4(%rsp), %edx
negl %edx
movq 0x8(%rsp), %rsi
cmpq %rax, %rcx
jg 0x2874b9
movl %edx, 0x4(%rsi,%rcx,4)
movl $0xc0000000, 0x4(%rdi,%rcx,4) # imm = 0xC0000000
incq %rcx
subl %ebp, %edx
jmp 0x2874a1
movl %r9d, %edx
negl %edx
movl 0x4(%rsp), %ecx
negl %ecx
movl %r9d, %esi
notl %esi
movslq %esi, %rsi
movl %ecx, 0x10(%rsp)
movq 0x8(%rsp), %r10
movl %ecx, 0x4(%r10,%rsi,4)
movq %rdi, %rcx
movl $0xc0000000, %edi       # imm = 0xC0000000
movl %edi, 0x4(%rcx,%rsi,4)
movq 0x8(%rsp), %rsi
movslq %edx, %rdx
andl $0x0, 0x4(%rsi,%rdx,4)
movl %edi, 0x4(%rcx,%rdx,4)
movl %edi, (%rsi)
movl %edi, (%rcx)
movslq 0x34(%rsp), %rdx
movl %edi, 0x4(%rsi,%rdx,4)
movl %edi, 0x4(%rcx,%rdx,4)
movslq %r9d, %rdx
leaq (%r8,%rdx,4), %rcx
movl %r9d, %edi
xorl %r8d, %r8d
movl %ebp, 0x18(%rsp)
cmpq %rbx, %r8
je 0x28761b
testq %rdx, %rdx
jns 0x287541
movl %r8d, %r9d
imull %ebp, %r9d
movl 0x10(%rsp), %r10d
subl %r9d, %r10d
movl %edx, %r9d
notl %r9d
movl %r10d, 0x4(%rsi,%r9,4)
movl $0xc0000000, %r9d       # imm = 0xC0000000
xorl %r10d, %r10d
incq %r10
leaq -0x1(%r10), %r11
cmpq %rax, %r11
jg 0x287609
leal (%rdi,%r10), %r11d
decl %r11d
cmpl %r15d, %r11d
jae 0x28754a
cmpl $0x0, 0x30(%r14)
movl 0x18(%r14), %r11d
je 0x287581
movq %rcx, %r13
leaq (%rdi,%r10), %rbx
decq %rbx
imull %ebx, %r11d
jmp 0x28758a
movq %rcx, %r13
imull -0x4(%rcx,%r10,4), %r11d
movq 0x8(%r14), %rbx
movq 0x28(%rsp), %rcx
movslq (%rcx,%r8,4), %r12
movslq %r11d, %r11
addq %r12, %r11
movl -0x4(%rsi,%r10,4), %r12d
movl (%rsi,%r10,4), %ecx
addl (%rbx,%r11,4), %ecx
movl 0x4(%rsi,%r10,4), %r11d
movl 0x4(%rsp), %r14d
subl %r14d, %r11d
movq 0x20(%rsp), %rsi
movl 0x4(%rsi,%r10,4), %ebx
movl 0x18(%rsp), %ebp
subl %ebp, %ebx
subl %r14d, %r12d
movq 0xa8(%rsp), %r14
subl %ebp, %r9d
cmpl %ebx, %r11d
cmovgl %r11d, %ebx
cmpl %r9d, %r12d
cmovgl %r12d, %r9d
movl %ebx, (%rsi,%r10,4)
movq 0x8(%rsp), %rsi
cmpl %r9d, %ebx
cmovlel %r9d, %ebx
cmpl %ecx, %ebx
cmovlel %ecx, %ebx
movl %ebx, (%rsi,%r10,4)
movq 0x48(%rsp), %rbx
movq %r13, %rcx
jmp 0x28754a
incq %rdx
incq %r8
addq $0x4, %rcx
incq %rdi
jmp 0x287519
movl 0x38(%rsp), %eax
negl %eax
movq 0x58(%rsp), %rdx
cmpl %edx, %r15d
cltq
movl 0xa0(%rsp), %ecx
movl %ecx, %ecx
cmovaq %rax, %rcx
movl 0x4(%rsi,%rcx,4), %eax
movq 0x60(%rsp), %rbx
movl %eax, (%rbx)
decl %r15d
movl %r15d, 0x4(%rbx)
decl %edx
movl %edx, 0x8(%rbx)
movq 0x20(%rsp), %rdi
movq %rsi, %r14
callq 0x1f475f
movq %r14, %rdi
callq 0x1f475f
movq 0x28(%rsp), %rdi
callq 0x1f475f
movq 0x40(%rsp), %rdi
callq 0x1f475f
jmp 0x287798
movq 0x4bc954(%rip), %rax    # 0x743fd8
movq (%rax), %rdi
leaq 0x38ae1d(%rip), %rsi    # 0x6124ab
leaq 0x38b6b3(%rip), %rdx    # 0x612d48
leaq 0x38b68f(%rip), %rcx    # 0x612d2b
jmp 0x28778f
movq 0x4bc930(%rip), %rax    # 0x743fd8
movq (%rax), %rdi
leaq 0x38b646(%rip), %rsi    # 0x612cf8
leaq 0x38b68f(%rip), %rdx    # 0x612d48
leaq 0x38b8bf(%rip), %rcx    # 0x612f7f
jmp 0x28778f
movq 0x4bc90c(%rip), %rax    # 0x743fd8
movq (%rax), %rdi
leaq 0x38add5(%rip), %rsi    # 0x6124ab
leaq 0x38b66b(%rip), %rdx    # 0x612d48
leaq 0x38b610(%rip), %rcx    # 0x612cf4
jmp 0x28778f
movq 0x4bc8e8(%rip), %rax    # 0x743fd8
movq (%rax), %rdi
leaq 0x38b5fe(%rip), %rsi    # 0x612cf8
leaq 0x38b647(%rip), %rdx    # 0x612d48
leaq 0x38b604(%rip), %rcx    # 0x612d0c
jmp 0x28778f
movq 0x4bc8c4(%rip), %rax    # 0x743fd8
movq (%rax), %rdi
leaq 0x38b5f4(%rip), %rsi    # 0x612d12
leaq 0x38b623(%rip), %rdx    # 0x612d48
leaq 0x32ea2b(%rip), %rcx    # 0x5b6157
jmp 0x28778f
movq 0x4bc8a3(%rip), %rax    # 0x743fd8
movq (%rax), %rdi
leaq 0x38b5d3(%rip), %rsi    # 0x612d12
leaq 0x38b602(%rip), %rdx    # 0x612d48
leaq 0x38b5da(%rip), %rcx    # 0x612d27
jmp 0x28778f
movq 0x4bc882(%rip), %rax    # 0x743fd8
movq (%rax), %rdi
leaq 0x38b598(%rip), %rsi    # 0x612cf8
leaq 0x38b5e1(%rip), %rdx    # 0x612d48
leaq 0x38b5ed(%rip), %rcx    # 0x612d5b
jmp 0x28778f
movq 0x4bc861(%rip), %rax    # 0x743fd8
movq (%rax), %rdi
leaq 0x38ad2a(%rip), %rsi    # 0x6124ab
leaq 0x38b5c0(%rip), %rdx    # 0x612d48
leaq 0x38b7e0(%rip), %rcx    # 0x612f6f
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1f0220
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop