// File: /workspace/github_c_makefile_star2_O3/nh13[P]ksw/src/parasail/src/nw.c
// Function: parasail_nw_rowcol
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 H = NULL;
    int * restrict F = 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
        | 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);
    H = parasail_memalign_int(16, s2Len+1);
    F = parasail_memalign_int(16, s2Len+1);

    /* validate heap variables */
    if (!s2) return NULL;
    if (!H) return NULL;
    if (!F) 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]];
    }

    /* upper left corner */
    H[0] = 0;
    F[0] = NEG_INF_32;
    
    /* first row */
    for (j=1; j<=s2Len; ++j) {
        H[j] = -open -(j-1)*gap;
        F[j] = NEG_INF_32;
    }

    /* iter over first sequence */
    for (i=1; i<=s1Len; ++i) {
        const int * const restrict matrow =
            matrix->type == PARASAIL_MATRIX_TYPE_SQUARE ?
            &matrix->matrix[matrix->size*s1[i-1]] :
            &matrix->matrix[matrix->size*(i-1)];
        /* init first column */
        int NH = H[0];
        int WH = -open - (i-1)*gap;
        int E = NEG_INF_32;
        H[0] = WH;
        for (j=1; j<=s2Len; ++j) {
            int H_dag;
            int E_opn;
            int E_ext;
            int F_opn;
            int F_ext;
            int NWH = NH;
            NH = H[j];
            F_opn = NH - open;
            F_ext = F[j] - gap;
            F[j] = MAX(F_opn, F_ext);
            E_opn = WH - open;
            E_ext = E    - gap;
            E    = MAX(E_opn, E_ext);
            H_dag = NWH + matrow[s2[j-1]];
            WH = MAX(H_dag, E);
            WH = MAX(WH, F[j]);
            H[j] = WH;
#ifdef PARASAIL_TABLE
            result->tables->score_table[1LL*(i-1)*s2Len + (j-1)] = WH;
#endif
        }
#ifdef PARASAIL_ROWCOL
        result->rowcols->score_col[i-1] = WH;
#endif
    }
#ifdef PARASAIL_ROWCOL
    for (j=1; j<=s2Len; ++j) {
        result->rowcols->score_row[j-1] = H[j];
    }
#endif

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

    parasail_free(F);
    parasail_free(H);
    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 0x2a5e43
movl %ecx, %ebx
testl %ecx, %ecx
jle 0x2a5e4a
movl %r8d, %r12d
testl %r8d, %r8d
js 0x2a5e51
movl %r9d, %ebp
testl %r9d, %r9d
js 0x2a5e58
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0x2a5e5f
cmpl $0x0, 0x30(%rax)
je 0x2a5b5a
movl 0x34(%rax), %r14d
jmp 0x2a5b6e
testq %rdi, %rdi
je 0x2a5e66
movl %esi, %r14d
testl %esi, %esi
jle 0x2a5e6d
movq %rdi, 0x30(%rsp)
movq %rdx, 0x18(%rsp)
movl %r14d, %edi
movl %ebx, %esi
callq 0x20ac53
testq %rax, %rax
je 0x2a5e72
movq %rax, %r15
movq %r14, 0x8(%rsp)
orl $0x1440101, 0xc(%rax)   # imm = 0x1440101
movl %ebx, %esi
movl $0x10, %edi
movq %rsi, 0x20(%rsp)
callq 0x20a617
movq %rax, %r13
movq %rbx, 0x38(%rsp)
incl %ebx
movl $0x10, %edi
movq %rbx, %rsi
callq 0x20a617
movq %rax, %r14
movl $0x10, %edi
movq %rbx, 0x28(%rsp)
movq %rbx, %rsi
callq 0x20a617
movq %rax, %rbx
testq %r13, %r13
sete %al
testq %r14, %r14
sete %cl
orb %al, %cl
testq %rbx, %rbx
sete %al
orb %cl, %al
jne 0x2a5e72
movq 0x80(%rsp), %r8
cmpl $0x0, 0x30(%r8)
je 0x2a5de0
movq $0x0, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %r10
movq 0x10(%r8), %rax
xorl %ecx, %ecx
movq 0x28(%rsp), %rsi
movzbl (%r10,%rcx), %edx
movl (%rax,%rdx,4), %edx
movl %edx, (%r13,%rcx,4)
incq %rcx
cmpq %rcx, %rdi
jne 0x2a5c27
movl $0x0, (%r14)
movl $0xc0000000, (%rbx)     # imm = 0xC0000000
movl %r12d, %eax
negl %eax
movl $0x1, %ecx
movl %eax, (%r14,%rcx,4)
movl $0xc0000000, (%rbx,%rcx,4) # imm = 0xC0000000
incq %rcx
subl %ebp, %eax
cmpq %rcx, %rsi
jne 0x2a5c53
cmpl $0x0, 0x8(%rsp)
jle 0x2a5d64
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x30(%rsp)
movq 0x8(%r8), %rax
movq %rax, 0x40(%rsp)
movq 0x28(%rsp), %rax
leaq -0x1(%rax), %rdx
movl $0x1, %esi
movq %r15, 0x18(%rsp)
leaq -0x1(%rsi), %rdi
cmpl $0x0, 0x30(%r8)
movslq 0x18(%r8), %rax
je 0x2a5cb3
imulq %rdi, %rax
movq %rax, %rcx
jmp 0x2a5cc1
movq 0x10(%rsp), %rcx
movslq -0x4(%rcx,%rsi,4), %rcx
imulq %rax, %rcx
movq 0x40(%rsp), %rax
leaq (%rax,%rcx,4), %r8
movl (%r14), %r10d
imull %ebp, %edi
addl %r12d, %edi
negl %edi
movl %edi, (%r14)
movl $0xc0000000, %r15d      # imm = 0xC0000000
xorl %r9d, %r9d
movl 0x4(%r14,%r9,4), %eax
movl %eax, %r11d
subl %r12d, %r11d
movl 0x4(%rbx,%r9,4), %ecx
subl %ebp, %ecx
cmpl %ecx, %r11d
cmovgl %r11d, %ecx
movl %ecx, 0x4(%rbx,%r9,4)
subl %r12d, %edi
movl %r15d, %r11d
subl %ebp, %r11d
movl %edi, %r15d
cmpl %r11d, %edi
jg 0x2a5d13
movl %r11d, %r15d
movslq (%r13,%r9,4), %rdi
addl (%r8,%rdi,4), %r10d
cmpl %r15d, %r10d
cmovlel %r15d, %r10d
movl %r10d, %edi
cmpl %ecx, %r10d
jg 0x2a5d2d
movl %ecx, %edi
movl %edi, 0x4(%r14,%r9,4)
incq %r9
movl %eax, %r10d
cmpq %r9, %rdx
jne 0x2a5ce1
movq 0x18(%rsp), %r15
movq 0x10(%r15), %rax
movq 0x8(%rax), %rax
movl %edi, -0x4(%rax,%rsi,4)
incq %rsi
cmpq 0x30(%rsp), %rsi
movq 0x80(%rsp), %r8
jne 0x2a5c9b
movl $0x1, %eax
movq 0x28(%rsp), %rsi
movl (%r14,%rax,4), %ecx
movq 0x10(%r15), %rdx
movq (%rdx), %rdx
movl %ecx, -0x4(%rdx,%rax,4)
incq %rax
cmpq %rax, %rsi
jne 0x2a5d6e
movq 0x20(%rsp), %rax
movl (%r14,%rax,4), %eax
movl %eax, (%r15)
movq 0x8(%rsp), %rax
decl %eax
movl %eax, 0x4(%r15)
movq 0x38(%rsp), %rax
decl %eax
movl %eax, 0x8(%r15)
movq %rbx, %rdi
callq 0x20a60d
movq %r14, %rdi
callq 0x20a60d
movq %r13, %rdi
callq 0x20a60d
movq 0x80(%rsp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x2a5e75
movq 0x10(%rsp), %rdi
callq 0x20a60d
jmp 0x2a5e75
movslq 0x8(%rsp), %rsi
movl $0x10, %edi
callq 0x20a617
testq %rax, %rax
je 0x2a5e72
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rcx
testl %ecx, %ecx
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %r10
movq 0x80(%rsp), %r8
jle 0x2a5c1c
movq 0x10(%r8), %rax
movl %ecx, %ecx
xorl %edx, %edx
movq 0x10(%rsp), %r9
movq 0x30(%rsp), %r11
movzbl (%r11,%rdx), %esi
movl (%rax,%rsi,4), %esi
movl %esi, (%r9,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x2a5e2a
jmp 0x2a5c1c
callq 0x1a11df
jmp 0x2a5e72
callq 0x1a11b9
jmp 0x2a5e72
callq 0x1a1193
jmp 0x2a5e72
callq 0x1a116d
jmp 0x2a5e72
callq 0x1a1147
jmp 0x2a5e72
callq 0x1a1121
jmp 0x2a5e72
callq 0x1a10fb
xorl %r15d, %r15d
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop