// File: /workspace/github_c_makefile_star2_O1/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, 0xc(%rsp)
testq %rdi, %rdi
je 0x2e5576
movl %esi, %r15d
testl %esi, %esi
jle 0x2e557d
testq %rdx, %rdx
je 0x2e5584
movl %ecx, %r12d
testl %ecx, %ecx
jle 0x2e558b
cmpl $0x0, 0xc(%rsp)
js 0x2e5592
movl %r9d, %ebp
testl %r9d, %r9d
js 0x2e5599
movl 0xa0(%rsp), %ebx
testl %ebx, %ebx
jle 0x2e55a0
cmpq $0x0, 0xa8(%rsp)
je 0x2e55a7
movq %rdi, 0x18(%rsp)
movq %rdx, 0x38(%rsp)
xorl %eax, %eax
callq 0x252a89
testq %rax, %rax
je 0x2e55ac
movq %rax, %r14
orl $0x1400181, 0xc(%rax)   # imm = 0x1400181
movl %r15d, %esi
movl $0x10, %edi
movq %rsi, 0x60(%rsp)
callq 0x2529ff
movq %rax, %r13
movl %r12d, %esi
movl $0x10, %edi
callq 0x2529ff
testq %r13, %r13
sete %dl
testq %rax, %rax
sete %cl
orb %dl, %cl
jne 0x2e55ac
movq %rax, 0x40(%rsp)
movq %r13, 0x48(%rsp)
movl %ebx, %eax
negl %eax
movl %r15d, %edx
subl %r12d, %edx
subl %ebx, %edx
movl %r12d, %r13d
subl %r15d, %r13d
subl %ebx, %r13d
cmpl %r12d, %r15d
cmovlel %edx, %r13d
cmovgl %eax, %edx
movq %rdx, 0x58(%rsp)
subl %r13d, %ebx
movq %rbx, 0x30(%rsp)
leal 0x3(%rbx), %eax
movslq %eax, %rsi
movl $0x10, %edi
movq %rsi, 0x10(%rsp)
callq 0x2529ff
testq %rax, %rax
je 0x2e55ac
movq %rax, %rbx
movl %r13d, 0x24(%rsp)
movq %r12, 0x28(%rsp)
movl $0x10, %edi
movq 0x10(%rsp), %rsi
callq 0x2529ff
testq %rax, %rax
je 0x2e55ac
movq %rax, %r13
movq %r14, 0x50(%rsp)
movq 0x30(%rsp), %rax
leal 0x1(%rax), %r14d
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %esi, %esi
movq 0x10(%rsp), %rdx
callq 0x252a2c
movq %r13, %rdi
xorl %esi, %esi
movq 0x10(%rsp), %rdx
callq 0x252a2c
movq 0xa8(%rsp), %rdx
movq 0x10(%rdx), %rax
movq 0x48(%rsp), %r10
movq 0x18(%rsp), %rsi
movq 0x60(%rsp), %rdi
movzbl (%rsi,%r12), %ecx
movl (%rax,%rcx,4), %ecx
movl %ecx, (%r10,%r12,4)
incq %r12
cmpq %r12, %rdi
jne 0x2e5318
movq 0x10(%rdx), %rax
movq 0x28(%rsp), %rdx
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
xorl %edx, %edx
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %r8
movq 0x58(%rsp), %r11
movzbl (%r8,%rdx), %esi
movl (%rax,%rsi,4), %esi
movl %esi, (%rdi,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x2e5351
movl %r11d, %edx
negl %edx
movl $0x1, %eax
movq %rax, 0x18(%rsp)
movl $0x1, %ecx
subl %r11d, %ecx
cmpl 0x30(%rsp), %ecx
jg 0x2e53c8
movslq %ecx, %rdi
movl 0xa0(%rsp), %eax
leal (%r11,%rax), %ecx
subl 0x24(%rsp), %ecx
leaq (%rbx,%rdi,4), %rsi
addq $0x4, %rsi
leaq 0x4(,%rdi,4), %rdi
addq %r13, %rdi
movl 0xc(%rsp), %r8d
negl %r8d
xorl %r9d, %r9d
movl %r8d, (%rsi,%r9,4)
movl $0xc0000000, (%rdi,%r9,4) # imm = 0xC0000000
incq %r9
subl %ebp, %r8d
cmpl %r9d, %ecx
jne 0x2e53b1
movl 0xc(%rsp), %eax
negl %eax
movl %r11d, %esi
notl %esi
movslq %esi, %rsi
movl %eax, 0x10(%rsp)
movl %eax, 0x4(%rbx,%rsi,4)
movl $0xc0000000, %edi       # imm = 0xC0000000
movl %edi, 0x4(%r13,%rsi,4)
movslq %edx, %rdx
movl $0x0, 0x4(%rbx,%rdx,4)
movl %edi, 0x4(%r13,%rdx,4)
movl %edi, (%rbx)
movl %edi, (%r13)
movslq %r14d, %rdx
movl %edi, 0x4(%rbx,%rdx,4)
movl %edi, 0x4(%r13,%rdx,4)
movq 0x28(%rsp), %rax
cmpl $0x2, %eax
movq 0x18(%rsp), %rcx
cmovgel %eax, %ecx
movq %rcx, 0x18(%rsp)
movslq %r11d, %rax
movl %r11d, %esi
leaq (%r10,%rax,4), %rdi
xorl %r8d, %r8d
movq 0xa8(%rsp), %rdx
testq %rax, %rax
jns 0x2e5453
movl %r8d, %r9d
imull %ebp, %r9d
movl 0x10(%rsp), %r10d
subl %r9d, %r10d
movl %eax, %r9d
notl %r9d
movl %r10d, 0x4(%rbx,%r9,4)
movq %rax, 0x38(%rsp)
cmpl $0x0, 0x30(%rsp)
js 0x2e54fd
movl $0xc0000000, %r9d       # imm = 0xC0000000
xorl %r10d, %r10d
leal (%rsi,%r10), %r11d
cmpl %r15d, %r11d
jae 0x2e54f1
cmpl $0x0, 0x30(%rdx)
je 0x2e5481
leal (%rsi,%r10), %r11d
jmp 0x2e5485
movl (%rdi,%r10,4), %r11d
imull 0x18(%rdx), %r11d
movq 0x8(%rdx), %r12
movq 0x40(%rsp), %rax
movslq (%rax,%r8,4), %rcx
movslq %r11d, %r11
addq %rcx, %r11
movl (%rbx,%r10,4), %ecx
movl 0x4(%rbx,%r10,4), %eax
addl (%r12,%r11,4), %eax
movl 0x8(%rbx,%r10,4), %r11d
movl 0xc(%rsp), %edx
subl %edx, %r11d
movl 0x8(%r13,%r10,4), %r12d
subl %ebp, %r12d
subl %edx, %ecx
movq 0xa8(%rsp), %rdx
subl %ebp, %r9d
cmpl %r12d, %r11d
cmovgl %r11d, %r12d
cmpl %r9d, %ecx
cmovgl %ecx, %r9d
movl %r12d, 0x4(%r13,%r10,4)
cmpl %r9d, %r12d
cmovlel %r9d, %r12d
cmpl %eax, %r12d
cmovlel %eax, %r12d
movl %r12d, 0x4(%rbx,%r10,4)
incq %r10
cmpq %r10, %r14
jne 0x2e546c
movq 0x38(%rsp), %rax
incq %rax
incq %r8
incq %rsi
addq $0x4, %rdi
cmpq 0x18(%rsp), %r8
jne 0x2e5434
movl 0x24(%rsp), %eax
negl %eax
movq 0x28(%rsp), %rdx
cmpl %edx, %r15d
cltq
movl 0xa0(%rsp), %ecx
movl %ecx, %ecx
cmovgq %rax, %rcx
movl 0x4(%rbx,%rcx,4), %eax
movq 0x50(%rsp), %r14
movl %eax, (%r14)
decl %r15d
movl %r15d, 0x4(%r14)
decl %edx
movl %edx, 0x8(%r14)
movq %r13, %rdi
callq 0x2529f5
movq %rbx, %rdi
callq 0x2529f5
movq 0x40(%rsp), %rdi
callq 0x2529f5
movq 0x48(%rsp), %rdi
callq 0x2529f5
jmp 0x2e55af
callq 0x1f232b
jmp 0x2e55ac
callq 0x1f2305
jmp 0x2e55ac
callq 0x1f22df
jmp 0x2e55ac
callq 0x1f22b9
jmp 0x2e55ac
callq 0x1f2293
jmp 0x2e55ac
callq 0x1f226d
jmp 0x2e55ac
callq 0x1f2247
jmp 0x2e55ac
callq 0x1f2221
xorl %r14d, %r14d
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)