// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
testq %rdx, %rdx
je 0x2a387c
movl %ecx, %r14d
testl %ecx, %ecx
jle 0x2a3883
movl %r8d, %r12d
testl %r8d, %r8d
js 0x2a388a
movl %r9d, %ebp
testl %r9d, %r9d
js 0x2a3891
movq 0x70(%rsp), %rcx
testq %rcx, %rcx
je 0x2a3898
movq %rdx, %rbx
movl 0x30(%rcx), %eax
testl %eax, %eax
jne 0x2a35c2
testq %rdi, %rdi
je 0x2a389f
movl %esi, %r15d
testl %esi, %esi
jle 0x2a38a6
testl %eax, %eax
je 0x2a35c6
movl 0x34(%rcx), %r15d
movq %rdi, 0x28(%rsp)
movl %r15d, %edi
movl %r14d, %esi
callq 0x209630
testq %rax, %rax
je 0x2a38ab
movq %r15, 0x8(%rsp)
movq %rax, 0x10(%rsp)
orl $0x1440101, 0xc(%rax)   # imm = 0x1440101
movl %r14d, %esi
movl $0x10, %edi
movq %rsi, 0x30(%rsp)
callq 0x2094bf
movq %rax, %r13
movq %r14, 0x20(%rsp)
incl %r14d
movl $0x10, %edi
movq %r14, %rsi
callq 0x2094bf
movq %rax, %r15
movl $0x10, %edi
movq %r14, %rsi
callq 0x2094bf
movq %rax, %r14
testq %r13, %r13
sete %al
testq %r15, %r15
sete %cl
orb %al, %cl
testq %r14, %r14
sete %al
orb %cl, %al
jne 0x2a38ab
movq 0x70(%rsp), %r8
cmpl $0x0, 0x30(%r8)
je 0x2a3821
movq $0x0, 0x18(%rsp)
movq 0x10(%rsp), %rdi
movq 0x10(%r8), %rcx
movq 0x20(%rsp), %rdx
cmpl $0x2, %edx
movl $0x1, %eax
cmovgel %edx, %eax
xorl %edx, %edx
movzbl (%rbx,%rdx), %esi
movl (%rcx,%rsi,4), %esi
movl %esi, (%r13,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0x2a367d
movl $0x0, (%r15)
movl $0xc0000000, (%r14)     # imm = 0xC0000000
movl %r12d, %ecx
negl %ecx
xorl %edx, %edx
movl %ecx, 0x4(%r15,%rdx,4)
movl $0xc0000000, 0x4(%r14,%rdx,4) # imm = 0xC0000000
subl %ebp, %ecx
incq %rdx
cmpq %rdx, %rax
jne 0x2a36a6
cmpl $0x0, 0x8(%rsp)
jle 0x2a37a2
movq 0x8(%rsp), %rcx
incl %ecx
movq %rcx, 0x28(%rsp)
movl $0x1, %edx
cmpl $0x0, 0x30(%r8)
je 0x2a36eb
leaq -0x1(%rdx), %rcx
movslq 0x18(%r8), %rsi
jmp 0x2a36f9
movslq 0x18(%r8), %rcx
movq 0x18(%rsp), %rsi
movslq -0x4(%rsi,%rdx,4), %rsi
imulq %rcx, %rsi
shlq $0x2, %rsi
addq 0x8(%r8), %rsi
movl (%r15), %r8d
leal -0x1(%rdx), %r9d
imull %ebp, %r9d
addl %r12d, %r9d
negl %r9d
movl %r9d, (%r15)
movl $0xc0000000, %ecx       # imm = 0xC0000000
xorl %edi, %edi
movl 0x4(%r15,%rdi,4), %r11d
movl %r11d, %r10d
subl %r12d, %r10d
movl 0x4(%r14,%rdi,4), %ebx
subl %ebp, %ebx
cmpl %ebx, %r10d
cmovgl %r10d, %ebx
movl %ebx, 0x4(%r14,%rdi,4)
subl %r12d, %r9d
movl %ecx, %r10d
subl %ebp, %r10d
movl %r9d, %ecx
cmpl %r10d, %r9d
jg 0x2a3752
movl %r10d, %ecx
movslq (%r13,%rdi,4), %r9
addl (%rsi,%r9,4), %r8d
cmpl %ecx, %r8d
cmovlel %ecx, %r8d
movl %r8d, %r9d
cmpl %ebx, %r8d
jg 0x2a376d
movl %ebx, %r9d
movl %r9d, 0x4(%r15,%rdi,4)
incq %rdi
movl %r11d, %r8d
cmpq %rdi, %rax
jne 0x2a3720
movq 0x10(%rsp), %rdi
movq 0x10(%rdi), %rcx
movq 0x8(%rcx), %rcx
movl %r9d, -0x4(%rcx,%rdx,4)
incq %rdx
cmpq 0x28(%rsp), %rdx
movq 0x70(%rsp), %r8
jne 0x2a36da
movq 0x20(%rsp), %rcx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
xorl %ecx, %ecx
movl 0x4(%r15,%rcx,4), %edx
movq 0x10(%rdi), %rsi
movq (%rsi), %rsi
movl %edx, (%rsi,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x2a37b4
movq 0x30(%rsp), %rax
movl (%r15,%rax,4), %eax
movl %eax, (%rdi)
movq 0x8(%rsp), %rax
decl %eax
movl %eax, 0x4(%rdi)
movq 0x20(%rsp), %rax
decl %eax
movl %eax, 0x8(%rdi)
movq %r14, %rdi
callq 0x2094b5
movq %r15, %rdi
callq 0x2094b5
movq %r13, %rdi
callq 0x2094b5
movq 0x70(%rsp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x2a3817
movq 0x18(%rsp), %rdi
callq 0x2094b5
movq 0x10(%rsp), %rax
jmp 0x2a38ad
movslq 0x8(%rsp), %rsi
movl $0x10, %edi
callq 0x2094bf
testq %rax, %rax
je 0x2a38ab
movq %rax, 0x18(%rsp)
movq 0x8(%rsp), %rcx
testl %ecx, %ecx
movq 0x10(%rsp), %rdi
movq 0x70(%rsp), %r8
jle 0x2a3667
movq 0x10(%r8), %rax
movl %ecx, %ecx
xorl %edx, %edx
movq 0x18(%rsp), %r9
movq 0x28(%rsp), %r10
movzbl (%r10,%rdx), %esi
movl (%rax,%rsi,4), %esi
movl %esi, (%r9,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x2a3863
jmp 0x2a3667
callq 0x1a11eb
jmp 0x2a38ab
callq 0x1a11c5
jmp 0x2a38ab
callq 0x1a119f
jmp 0x2a38ab
callq 0x1a1179
jmp 0x2a38ab
callq 0x1a1153
jmp 0x2a38ab
callq 0x1a112d
jmp 0x2a38ab
callq 0x1a1107
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq