// File: /workspace/github_c_makefile_star2_O3/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
testq %rdi, %rdi
je 0x2e59d7
testl %esi, %esi
jle 0x2e59de
testq %rdx, %rdx
je 0x2e59e5
movl %ecx, %r15d
testl %ecx, %ecx
jle 0x2e59ec
movl %r8d, %r12d
testl %r8d, %r8d
js 0x2e59f3
movl %r9d, %ebp
testl %r9d, %r9d
js 0x2e59fa
movl 0xa0(%rsp), %eax
testl %eax, %eax
jle 0x2e5a01
cmpq $0x0, 0xa8(%rsp)
je 0x2e5a08
movq %rdi, 0x58(%rsp)
movq %rdx, 0x60(%rsp)
movq %rsi, 0x28(%rsp)
xorl %eax, %eax
callq 0x253001
testq %rax, %rax
je 0x2e5a0d
movq %rax, %r14
orl $0x1400181, 0xc(%rax)   # imm = 0x1400181
movq 0x28(%rsp), %rbx
movl %ebx, %esi
movl $0x10, %edi
movq %rsi, 0x50(%rsp)
callq 0x252aa7
movq %rax, %r13
movl %r15d, %esi
movl $0x10, %edi
movq %rsi, 0x30(%rsp)
callq 0x252aa7
testq %r13, %r13
sete %dl
testq %rax, %rax
sete %cl
orb %dl, %cl
jne 0x2e5a0d
movq %rax, 0x20(%rsp)
movq %r13, 0x18(%rsp)
movl 0xa0(%rsp), %esi
movl %esi, %eax
negl %eax
movl %ebx, %edx
subl %r15d, %edx
subl %esi, %edx
movl %r15d, %r13d
subl %ebx, %r13d
subl %esi, %r13d
cmpl %r15d, %ebx
cmovbel %edx, %r13d
cmoval %eax, %edx
movq %rdx, 0x48(%rsp)
movl %esi, %eax
subl %r13d, %eax
movq %rax, 0x10(%rsp)
addl $0x3, %eax
movslq %eax, %rsi
movl $0x10, %edi
movq %rsi, 0x8(%rsp)
callq 0x252aa7
testq %rax, %rax
je 0x2e5a0d
movq %rax, %rbx
movl %r13d, 0x4(%rsp)
movl $0x10, %edi
movq 0x8(%rsp), %rsi
callq 0x252aa7
testq %rax, %rax
je 0x2e5a0d
movq %rax, %r13
movq %r15, 0x38(%rsp)
movq %r14, 0x40(%rsp)
movq 0x10(%rsp), %rax
leal 0x1(%rax), %r14d
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
callq 0x252ad4
movq %r13, %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
callq 0x252ad4
movq 0xa8(%rsp), %r11
movq 0x10(%r11), %rax
movq 0x18(%rsp), %rdx
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdi
movzbl (%rsi,%r15), %ecx
movl (%rax,%rcx,4), %ecx
movl %ecx, (%rdx,%r15,4)
incq %r15
cmpq %r15, %rdi
jne 0x2e57c7
movq 0x10(%r11), %rax
xorl %ecx, %ecx
movq 0x20(%rsp), %rsi
movq 0x30(%rsp), %rdi
movq 0x60(%rsp), %r8
movq 0x48(%rsp), %r9
movzbl (%r8,%rcx), %edx
movl (%rax,%rdx,4), %edx
movl %edx, (%rsi,%rcx,4)
incq %rcx
cmpq %rcx, %rdi
jne 0x2e57f5
movl %r9d, %ecx
negl %ecx
movl $0x1, %eax
subl %r9d, %eax
cmpl 0x10(%rsp), %eax
movq 0x38(%rsp), %r15
jg 0x2e5862
movslq %eax, %rsi
movl 0xa0(%rsp), %eax
addl %r9d, %eax
subl 0x4(%rsp), %eax
leaq (%rbx,%rsi,4), %rdx
addq $0x4, %rdx
leaq 0x4(,%rsi,4), %rsi
addq %r13, %rsi
movl %r12d, %edi
negl %edi
xorl %r8d, %r8d
movl %edi, (%rdx,%r8,4)
movl $0xc0000000, (%rsi,%r8,4) # imm = 0xC0000000
incq %r8
subl %ebp, %edi
cmpl %r8d, %eax
jne 0x2e584c
movl %r12d, %eax
negl %eax
movl %r9d, %edx
notl %edx
movslq %edx, %rdx
movl %eax, 0x4(%rbx,%rdx,4)
movl $0xc0000000, %esi       # imm = 0xC0000000
movl %esi, 0x4(%r13,%rdx,4)
movslq %ecx, %rcx
movl $0x0, 0x4(%rbx,%rcx,4)
movl %esi, 0x4(%r13,%rcx,4)
movl %esi, (%rbx)
movl %esi, (%r13)
movslq %r14d, %rcx
movl %esi, 0x4(%rbx,%rcx,4)
movl %esi, 0x4(%r13,%rcx,4)
movslq %r9d, %rcx
xorl %edx, %edx
movq 0x28(%rsp), %r8
testq %rcx, %rcx
jns 0x2e58bf
movl %edx, %esi
imull %ebp, %esi
movl %eax, %edi
subl %esi, %edi
movl %ecx, %esi
notl %esi
movl %edi, 0x4(%rbx,%rsi,4)
cmpl $0x0, 0x10(%rsp)
js 0x2e596e
movl $0xc0000000, %esi       # imm = 0xC0000000
xorl %edi, %edi
leaq (%rdi,%rcx), %r9
cmpl %r8d, %r9d
jae 0x2e58eb
cmpl $0x0, 0x30(%r11)
movl 0x18(%r11), %r8d
je 0x2e58f0
imull %r9d, %r8d
jmp 0x2e58fa
incq %rdi
jmp 0x2e5965
movq 0x18(%rsp), %r10
imull (%r10,%r9,4), %r8d
movq 0x8(%r11), %r9
movq 0x20(%rsp), %r10
movslq (%r10,%rdx,4), %r10
movslq %r8d, %r8
addq %r10, %r8
movl (%rbx,%rdi,4), %r10d
movl 0x4(%rbx,%rdi,4), %r11d
addl (%r9,%r8,4), %r11d
movl 0x8(%rbx,%rdi,4), %r8d
subl %r12d, %r8d
movl 0x8(%r13,%rdi,4), %r9d
subl %ebp, %r9d
subl %r12d, %r10d
subl %ebp, %esi
cmpl %r9d, %r8d
cmovgl %r8d, %r9d
cmpl %esi, %r10d
cmovgl %r10d, %esi
movl %r9d, 0x4(%r13,%rdi,4)
cmpl %esi, %r9d
cmovlel %esi, %r9d
cmpl %r11d, %r9d
cmovlel %r11d, %r9d
movq 0xa8(%rsp), %r11
movl %r9d, 0x4(%rbx,%rdi,4)
incq %rdi
movq 0x28(%rsp), %r8
cmpq %r14, %rdi
jne 0x2e58d1
incq %rcx
incq %rdx
cmpq 0x30(%rsp), %rdx
jne 0x2e58a9
movl 0x4(%rsp), %eax
negl %eax
cmpl %r15d, %r8d
cltq
movl 0xa0(%rsp), %ecx
movl %ecx, %ecx
cmovaq %rax, %rcx
movl 0x4(%rbx,%rcx,4), %eax
movq 0x40(%rsp), %r14
movl %eax, (%r14)
decl %r8d
movl %r8d, 0x4(%r14)
decl %r15d
movl %r15d, 0x8(%r14)
movq %r13, %rdi
callq 0x252a9d
movq %rbx, %rdi
callq 0x252a9d
movq 0x20(%rsp), %rdi
callq 0x252a9d
movq 0x18(%rsp), %rdi
callq 0x252a9d
jmp 0x2e5a10
callq 0x1f2386
jmp 0x2e5a0d
callq 0x1f2360
jmp 0x2e5a0d
callq 0x1f233a
jmp 0x2e5a0d
callq 0x1f2314
jmp 0x2e5a0d
callq 0x1f22ee
jmp 0x2e5a0d
callq 0x1f22c8
jmp 0x2e5a0d
callq 0x1f22a2
jmp 0x2e5a0d
callq 0x1f227c
xorl %r14d, %r14d
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop