// File: /workspace/github_c_makefile_star2_O2/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, 0x10(%rsp)
movl %r8d, 0x14(%rsp)
testq %rdx, %rdx
je 0x248484
movl %ecx, %r14d
testl %ecx, %ecx
jle 0x2484a8
cmpl $0x0, 0x14(%rsp)
js 0x2484cc
cmpl $0x0, 0x10(%rsp)
js 0x2484f0
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0x248511
movq %rdx, %rbx
movq %rdi, %r12
cmpl $0x0, 0x30(%rax)
je 0x24812d
movl 0x34(%rax), %r15d
jmp 0x248141
testq %r12, %r12
je 0x248532
movl %esi, %r15d
testl %esi, %esi
jle 0x248553
movl %r15d, %edi
movl %r14d, %esi
callq 0x1ab93b
testq %rax, %rax
je 0x248579
movq %r12, 0x40(%rsp)
movq %rbx, 0x20(%rsp)
movq %rax, 0x8(%rsp)
orl $0x1440104, 0xc(%rax)   # imm = 0x1440104
movl %r14d, %esi
pushq $0x10
popq %r13
movq %r13, %rdi
movq %rsi, 0x38(%rsp)
callq 0x1ab76d
movq %rax, %r12
leal 0x1(%r14), %ebp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x1ab76d
movq %rax, %rbx
movq %r13, %rdi
movq %rbp, 0x30(%rsp)
movq %rbp, %rsi
callq 0x1ab76d
movq %r12, 0x48(%rsp)
testq %r12, %r12
sete %dl
movq %rbx, (%rsp)
testq %rbx, %rbx
sete %cl
orb %dl, %cl
movq %rax, 0x28(%rsp)
testq %rax, %rax
sete %al
orb %cl, %al
jne 0x248579
movq 0x90(%rsp), %r9
cmpl $0x0, 0x30(%r9)
movq 0x40(%rsp), %rbx
je 0x24841f
movq $0x0, 0x18(%rsp)
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %r8
movq 0x20(%rsp), %r11
movq %r14, %r13
movq 0x10(%r9), %rax
xorl %ecx, %ecx
movq 0x38(%rsp), %r10
movq 0x48(%rsp), %rsi
cmpq %rcx, %r10
je 0x248226
movzbl (%r11,%rcx), %edx
movl (%rax,%rdx,4), %edx
movl %edx, (%rsi,%rcx,4)
incq %rcx
jmp 0x248211
movq (%rsp), %rax
andl $0x0, (%rax)
movq 0x28(%rsp), %rax
movl $0xc0000000, (%rax)     # imm = 0xC0000000
pushq $0x1
popq %rax
cmpq %rax, %r8
je 0x248259
movq (%rsp), %rcx
andl $0x0, (%rcx,%rax,4)
movq 0x28(%rsp), %rcx
movl $0xc0000000, (%rcx,%rax,4) # imm = 0xC0000000
incq %rax
jmp 0x24823b
testl %r15d, %r15d
movl $0x0, %eax
cmovgl %r15d, %eax
incl %eax
movq %rax, 0x50(%rsp)
leaq -0x1(%r8), %rax
movq %rax, 0x20(%rsp)
movl $0xc0000000, %eax       # imm = 0xC0000000
pushq $0x1
popq %rsi
movq 0x28(%rsp), %rbx
cmpq 0x50(%rsp), %rsi
je 0x2483bb
leaq -0x1(%rsi), %r14
cmpl $0x0, 0x30(%r9)
movslq 0x18(%r9), %rdx
movq %rsi, 0x38(%rsp)
je 0x2482aa
imulq %r14, %rdx
movq %rdx, %rcx
jmp 0x2482b8
movq 0x18(%rsp), %rcx
movslq -0x4(%rcx,%rsi,4), %rcx
imulq %rdx, %rcx
movq 0x8(%r9), %rdx
movq (%rsp), %rsi
movl (%rsi), %edi
andl $0x0, (%rsi)
leaq (%rdx,%rcx,4), %rcx
movq %rcx, 0x40(%rsp)
movl $0xc0000000, %r10d      # imm = 0xC0000000
xorl %r11d, %r11d
xorl %edx, %edx
cmpq %r11, 0x20(%rsp)
je 0x248390
movq %r13, %r9
movl %r15d, %r12d
movq (%rsp), %r8
movl 0x4(%r8,%r11,4), %ecx
movl %ecx, %ebp
movl 0x14(%rsp), %r13d
subl %r13d, %ebp
movl 0x4(%rbx,%r11,4), %r15d
movl 0x10(%rsp), %esi
subl %esi, %r15d
cmpl %r15d, %ebp
cmovgl %ebp, %r15d
subl %r13d, %edx
subl %esi, %r10d
cmpl %r10d, %edx
cmovgl %edx, %r10d
movl %r15d, 0x4(%rbx,%r11,4)
movq 0x48(%rsp), %rdx
movslq (%rdx,%r11,4), %rdx
movq 0x40(%rsp), %rsi
addl (%rsi,%rdx,4), %edi
cmpl %r10d, %edi
cmovlel %r10d, %edi
cmpl %r15d, %edi
cmovlel %r15d, %edi
leaq 0x1(%r11), %rbp
testl %edi, %edi
movl %edi, %edx
movl $0x0, %esi
cmovlel %esi, %edx
movl %edx, 0x4(%r8,%r11,4)
cmpl %eax, %edx
jle 0x248362
movl %r14d, %r15d
movl %r11d, %r13d
jmp 0x248381
setne %dil
movq %r9, %r13
movslq %r13d, %r13
cmpq %r13, %rbp
setg %r15b
orb %dil, %r15b
movl %r12d, %r15d
cmovel %r14d, %r15d
cmovel %r11d, %r13d
cmpl %edx, %eax
cmovlel %edx, %eax
movq %rbp, %r11
movl %ecx, %edi
jmp 0x2482d9
movq 0x8(%rsp), %rdi
movq 0x10(%rdi), %rcx
movq 0x8(%rcx), %rcx
movq 0x38(%rsp), %rsi
movl %edx, -0x4(%rcx,%rsi,4)
incq %rsi
movq 0x90(%rsp), %r9
movq 0x30(%rsp), %r8
jmp 0x248282
pushq $0x1
popq %rcx
cmpq %rcx, %r8
je 0x2483da
movq (%rsp), %rdx
movl (%rdx,%rcx,4), %edx
movq 0x10(%rdi), %rsi
movq (%rsi), %rsi
movl %edx, -0x4(%rsi,%rcx,4)
incq %rcx
jmp 0x2483be
movl %eax, (%rdi)
movl %r15d, 0x4(%rdi)
movl %r13d, 0x8(%rdi)
movq 0x28(%rsp), %rdi
movq %r9, %r14
callq 0x1ab763
movq (%rsp), %rdi
callq 0x1ab763
movq 0x48(%rsp), %rdi
callq 0x1ab763
cmpl $0x0, 0x30(%r14)
jne 0x248415
movq 0x18(%rsp), %rdi
callq 0x1ab763
movq 0x8(%rsp), %rax
jmp 0x24857b
movslq %r15d, %rsi
pushq $0x10
popq %rdi
callq 0x1ab76d
xorl %r10d, %r10d
movq %rax, 0x18(%rsp)
testq %rax, %rax
movq 0x20(%rsp), %r11
je 0x248579
movq %r14, %r13
testl %r15d, %r15d
movl $0x0, %ecx
cmovgl %r15d, %ecx
movq 0x8(%rsp), %rdi
movq 0x90(%rsp), %r9
movq 0x30(%rsp), %r8
movq 0x18(%rsp), %rax
cmpq %r10, %rcx
je 0x248201
movq 0x10(%r9), %rdx
movzbl (%rbx,%r10), %esi
movl (%rdx,%rsi,4), %edx
movl %edx, (%rax,%r10,4)
incq %r10
jmp 0x248466
movq 0x4f2b4d(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37eb56(%rip), %rsi    # 0x5c6feb
leaq 0x33eaf9(%rip), %rdx    # 0x586f95
leaq 0x37f25a(%rip), %rcx    # 0x5c76fd
jmp 0x248572
movq 0x4f2b29(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37f248(%rip), %rsi    # 0x5c7701
leaq 0x33ead5(%rip), %rdx    # 0x586f95
leaq 0x37f24e(%rip), %rcx    # 0x5c7715
jmp 0x248572
movq 0x4f2b05(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37f23e(%rip), %rsi    # 0x5c771b
leaq 0x33eab1(%rip), %rdx    # 0x586f95
leaq 0x37f245(%rip), %rcx    # 0x5c7730
jmp 0x248572
movq 0x4f2ae1(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37f21a(%rip), %rsi    # 0x5c771b
leaq 0x33ea8d(%rip), %rdx    # 0x586f95
leaq 0x37f226(%rip), %rcx    # 0x5c7735
jmp 0x248572
movq 0x4f2ac0(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37eac9(%rip), %rsi    # 0x5c6feb
leaq 0x33ea6c(%rip), %rdx    # 0x586f95
leaq 0x37f412(%rip), %rcx    # 0x5c7942
jmp 0x248572
movq 0x4f2a9f(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37eaa8(%rip), %rsi    # 0x5c6feb
leaq 0x33ea4b(%rip), %rdx    # 0x586f95
leaq 0x37f1e8(%rip), %rcx    # 0x5c7739
jmp 0x248572
movq 0x4f2a7e(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37f19d(%rip), %rsi    # 0x5c7701
leaq 0x33ea2a(%rip), %rdx    # 0x586f95
leaq 0x37f1cb(%rip), %rcx    # 0x5c773d
xorl %eax, %eax
callq 0x19e180
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop