// File: /workspace/github_c_makefile_star2_O3/nh13[P]ksw/src/parasail/src/sw.c
// Function: parasail_sw_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;
    int score = 0;
    int end_query = 0;
    int end_ref = 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;
    i = 0;
    j = 0;
    score = NEG_INF_32;
    end_query = s1Len;
    end_ref = s2Len;

    /* 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_SW | 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] = 0;
        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 = 0;
        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, 0);
            WH = MAX(WH, E);
            WH = MAX(WH, F[j]);
            H[j] = WH;
            if (WH > score) {
                end_query = i-1;
                end_ref = j-1;
            }
            else if (score == WH && j-1 < end_ref) {
                end_query = i-1;
                end_ref = j-1;
            }
            score = MAX(score,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 = score;
    result->end_query = end_query;
    result->end_ref = end_ref;

    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 $0x58, %rsp
movl %r9d, (%rsp)
movl %r8d, 0x4(%rsp)
testq %rdx, %rdx
je 0x2a6900
movl %ecx, %r15d
testl %ecx, %ecx
jle 0x2a6907
cmpl $0x0, 0x4(%rsp)
js 0x2a690e
cmpl $0x0, (%rsp)
js 0x2a6915
movq 0x90(%rsp), %r12
testq %r12, %r12
je 0x2a691c
cmpl $0x0, 0x30(%r12)
je 0x2a65e8
movl 0x34(%r12), %ebp
jmp 0x2a65fb
testq %rdi, %rdi
je 0x2a6923
movl %esi, %ebp
testl %esi, %esi
jle 0x2a692a
movq %rdi, 0x20(%rsp)
movq %rdx, 0x28(%rsp)
movl %ebp, %edi
movl %r15d, %esi
callq 0x20ac53
testq %rax, %rax
je 0x2a692f
movq %rax, %r14
orl $0x1440104, 0xc(%rax)   # imm = 0x1440104
movl %r15d, %esi
movl $0x10, %edi
movq %rsi, 0x10(%rsp)
callq 0x20a617
movq %rax, %r13
leal 0x1(%r15), %esi
movq %rsi, 0x8(%rsp)
movl $0x10, %edi
callq 0x20a617
movq %rax, %rbx
movl $0x10, %edi
movq 0x8(%rsp), %rsi
callq 0x20a617
testq %r13, %r13
sete %dl
testq %rbx, %rbx
sete %cl
orb %dl, %cl
testq %rax, %rax
sete %dl
orb %cl, %dl
jne 0x2a692f
cmpl $0x0, 0x30(%r12)
movq %rax, 0x18(%rsp)
je 0x2a6699
xorl %r8d, %r8d
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %r9
movq 0x10(%rsp), %r11
jmp 0x2a66ec
movslq %ebp, %rsi
movl $0x10, %edi
callq 0x20a617
testq %rax, %rax
je 0x2a692f
movq %rax, %r8
testl %ebp, %ebp
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %r9
movq 0x10(%rsp), %r11
jle 0x2a66e7
movq 0x10(%r12), %rax
movl %ebp, %ecx
xorl %edx, %edx
movq 0x20(%rsp), %r10
movzbl (%r10,%rdx), %esi
movl (%rax,%rsi,4), %esi
movl %esi, (%r8,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x2a66d3
movq 0x18(%rsp), %rax
movq 0x10(%r12), %rsi
xorl %ecx, %ecx
movzbl (%r9,%rcx), %edx
movl (%rsi,%rdx,4), %edx
movl %edx, (%r13,%rcx,4)
incq %rcx
cmpq %rcx, %r11
jne 0x2a66f3
movl $0x0, (%rbx)
movl $0xc0000000, (%rax)     # imm = 0xC0000000
movl $0x1, %ecx
movl $0x0, (%rbx,%rcx,4)
movl $0xc0000000, (%rax,%rcx,4) # imm = 0xC0000000
incq %rcx
cmpq %rcx, %rdi
jne 0x2a6719
movq %r8, 0x30(%rsp)
testl %ebp, %ebp
jle 0x2a68a6
leal 0x1(%rbp), %ecx
movq %rcx, 0x40(%rsp)
movq 0x8(%r12), %rcx
movq %rcx, 0x38(%rsp)
leaq -0x1(%rdi), %rcx
movq %rcx, 0x10(%rsp)
movl $0xc0000000, %r10d      # imm = 0xC0000000
movl $0x1, %esi
movq %r14, 0x48(%rsp)
cmpl $0x0, 0x30(%r12)
movslq 0x18(%r12), %rdx
je 0x2a677a
leaq -0x1(%rsi), %rcx
jmp 0x2a6784
movq 0x30(%rsp), %rcx
movslq -0x4(%rcx,%rsi,4), %rcx
imulq %rdx, %rcx
movq 0x38(%rsp), %rdx
leaq (%rdx,%rcx,4), %rcx
movq %rcx, 0x28(%rsp)
movl (%rbx), %r11d
movl $0x0, (%rbx)
movq %rsi, 0x50(%rsp)
leal -0x1(%rsi), %ecx
movl %ecx, 0x20(%rsp)
xorl %r14d, %r14d
movl $0xc0000000, %ecx       # imm = 0xC0000000
xorl %r8d, %r8d
movq %r15, %r9
movq %rbp, %r12
movl %r11d, %edx
movl 0x4(%rbx,%r14,4), %r11d
movl %r11d, %edi
movq %rbx, %r15
movq %r13, %rbx
movl 0x4(%rsp), %r13d
subl %r13d, %edi
movl 0x4(%rax,%r14,4), %ebp
movl (%rsp), %esi
subl %esi, %ebp
cmpl %ebp, %edi
cmovgl %edi, %ebp
subl %r13d, %r8d
movq %rbx, %r13
movq %r15, %rbx
subl %esi, %ecx
movq 0x18(%rsp), %rax
cmpl %ecx, %r8d
cmovgl %r8d, %ecx
movl %ebp, 0x4(%rax,%r14,4)
movslq (%r13,%r14,4), %rdi
movq 0x28(%rsp), %rsi
addl (%rsi,%rdi,4), %edx
cmpl %ecx, %edx
cmovlel %ecx, %edx
cmpl %ebp, %edx
cmovlel %ebp, %edx
leaq 0x1(%r14), %rdi
testl %edx, %edx
movl %edx, %r8d
movl $0x0, %edx
cmovlel %edx, %r8d
movl %r8d, 0x4(%r15,%r14,4)
cmpl %r10d, %r8d
jle 0x2a683e
movl 0x20(%rsp), %edx
movl %edx, %ebp
movl %r14d, %r15d
jmp 0x2a685d
setne %dl
movq %r9, %r15
movslq %r15d, %r15
cmpq %r15, %rdi
setg %bpl
orb %dl, %bpl
movq %r12, %rbp
cmovel 0x20(%rsp), %ebp
cmovel %r14d, %r15d
cmpl %r8d, %r10d
cmovlel %r8d, %r10d
movq %rdi, %r14
cmpq %rdi, 0x10(%rsp)
jne 0x2a67b6
movq 0x48(%rsp), %r14
movq 0x10(%r14), %rcx
movq 0x8(%rcx), %rcx
movq 0x50(%rsp), %rsi
movl %r8d, -0x4(%rcx,%rsi,4)
incq %rsi
cmpq 0x40(%rsp), %rsi
movq 0x90(%rsp), %r12
movq 0x8(%rsp), %rdi
jne 0x2a6767
jmp 0x2a68ac
movl $0xc0000000, %r10d      # imm = 0xC0000000
movl $0x1, %ecx
movl (%rbx,%rcx,4), %edx
movq 0x10(%r14), %rsi
movq (%rsi), %rsi
movl %edx, -0x4(%rsi,%rcx,4)
incq %rcx
cmpq %rcx, %rdi
jne 0x2a68b1
movl %r10d, (%r14)
movl %ebp, 0x4(%r14)
movl %r15d, 0x8(%r14)
movq 0x18(%rsp), %rdi
callq 0x20a60d
movq %rbx, %rdi
callq 0x20a60d
movq %r13, %rdi
callq 0x20a60d
cmpl $0x0, 0x30(%r12)
jne 0x2a6932
movq 0x30(%rsp), %rdi
callq 0x20a60d
jmp 0x2a6932
callq 0x1a13f3
jmp 0x2a692f
callq 0x1a13cd
jmp 0x2a692f
callq 0x1a13a7
jmp 0x2a692f
callq 0x1a1381
jmp 0x2a692f
callq 0x1a135b
jmp 0x2a692f
callq 0x1a1335
jmp 0x2a692f
callq 0x1a130f
xorl %r14d, %r14d
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq