// File: /workspace/github_c_makefile_star2_O1/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, 0xc(%rsp)
movl %r8d, 0x10(%rsp)
testq %rdx, %rdx
je 0x2a43b3
movl %ecx, %ebx
testl %ecx, %ecx
jle 0x2a43ba
cmpl $0x0, 0x10(%rsp)
js 0x2a43c1
cmpl $0x0, 0xc(%rsp)
js 0x2a43c8
movq 0x90(%rsp), %rbp
testq %rbp, %rbp
je 0x2a43cf
movl 0x30(%rbp), %eax
testl %eax, %eax
jne 0x2a407e
testq %rdi, %rdi
je 0x2a43e0
testl %esi, %esi
jle 0x2a43e7
testl %eax, %eax
je 0x2a4081
movl 0x34(%rbp), %esi
movq %rdi, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, %r14
movl %esi, %edi
movl %ebx, %esi
callq 0x209630
testq %rax, %rax
je 0x2a43ec
movq %rax, %r13
orl $0x1440104, 0xc(%rax)   # imm = 0x1440104
movl %ebx, %esi
movl $0x10, %edi
callq 0x2094bf
movq %rax, %r12
movq %rbx, 0x18(%rsp)
incl %ebx
movl $0x10, %edi
movq %rbx, %rsi
callq 0x2094bf
movq %rax, %r15
movl $0x10, %edi
movq %rbx, %rsi
callq 0x2094bf
testq %r12, %r12
sete %dl
testq %r15, %r15
sete %cl
orb %dl, %cl
testq %rax, %rax
sete %dl
orb %cl, %dl
jne 0x2a43ec
cmpl $0x0, 0x30(%rbp)
movq %rax, 0x28(%rsp)
je 0x2a42e4
movq $0x0, 0x20(%rsp)
movq %r14, %r8
movq 0x38(%rsp), %r10
movq 0x10(%rbp), %rcx
movq 0x18(%rsp), %rdx
cmpl $0x2, %edx
movl $0x1, %r9d
cmovgel %edx, %r9d
xorl %edx, %edx
movzbl (%r10,%rdx), %esi
movl (%rcx,%rsi,4), %esi
movl %esi, (%r12,%rdx,4)
incq %rdx
cmpq %rdx, %r9
jne 0x2a4131
movl $0x0, (%r15)
movl $0xc0000000, (%rax)     # imm = 0xC0000000
xorl %ecx, %ecx
movl $0x0, 0x4(%r15,%rcx,4)
movl $0xc0000000, 0x4(%rax,%rcx,4) # imm = 0xC0000000
incq %rcx
cmpq %rcx, %r9
jne 0x2a4154
testl %r8d, %r8d
jle 0x2a4341
leal 0x1(%r8), %eax
movq %rax, 0x40(%rsp)
movl $0xc0000000, %ecx       # imm = 0xC0000000
movl $0x1, %esi
movq 0x18(%rsp), %rdi
movl %edi, %r10d
movq %r13, 0x48(%rsp)
movl 0x10(%rsp), %ebx
cmpl $0x0, 0x30(%rbp)
je 0x2a41aa
leaq -0x1(%rsi), %rdx
movslq 0x18(%rbp), %rax
jmp 0x2a41b8
movslq 0x18(%rbp), %rdx
movq 0x20(%rsp), %rax
movslq -0x4(%rax,%rsi,4), %rax
imulq %rdx, %rax
shlq $0x2, %rax
addq 0x8(%rbp), %rax
movq %rax, 0x30(%rsp)
movl (%r15), %r11d
movl $0x0, (%r15)
movq %rsi, 0x50(%rsp)
leal -0x1(%rsi), %eax
movl %eax, 0x14(%rsp)
xorl %edx, %edx
movl $0xc0000000, %esi       # imm = 0xC0000000
xorl %r14d, %r14d
movq %r8, 0x38(%rsp)
movq %r10, %rbp
movq %r9, %rdi
movl %r11d, %r8d
movl 0x4(%r15,%rdx,4), %r11d
movl %r11d, %r13d
subl %ebx, %r13d
movq 0x28(%rsp), %r10
movl 0x4(%r10,%rdx,4), %eax
movq %r15, %r9
movq %r12, %r15
movl 0xc(%rsp), %r12d
subl %r12d, %eax
cmpl %eax, %r13d
cmovgl %r13d, %eax
subl %ebx, %r14d
subl %r12d, %esi
movq %r15, %r12
movq %r9, %r15
cmpl %esi, %r14d
cmovgl %r14d, %esi
movl %eax, 0x4(%r10,%rdx,4)
movslq (%r12,%rdx,4), %r14
movq 0x30(%rsp), %r9
addl (%r9,%r14,4), %r8d
cmpl %esi, %r8d
cmovlel %esi, %r8d
cmpl %eax, %r8d
cmovlel %eax, %r8d
leaq 0x1(%rdx), %r13
testl %r8d, %r8d
movl %r8d, %r14d
movl $0x0, %eax
cmovlel %eax, %r14d
movl %r14d, 0x4(%r15,%rdx,4)
cmpl %ecx, %r14d
jle 0x2a427d
movl 0x14(%rsp), %eax
movl %eax, %r8d
movl %edx, %r10d
jmp 0x2a429f
setne %al
movq %rbp, %r10
movslq %r10d, %r10
cmpq %r10, %r13
setg %r8b
orb %al, %r8b
movq 0x38(%rsp), %r8
cmovel 0x14(%rsp), %r8d
cmovel %edx, %r10d
movq %rdi, %r9
cmpl %r14d, %ecx
cmovlel %r14d, %ecx
movq %r13, %rdx
cmpq %r13, %rdi
jne 0x2a41e9
movq 0x48(%rsp), %r13
movq 0x10(%r13), %rax
movq 0x8(%rax), %rax
movq 0x50(%rsp), %rsi
movl %r14d, -0x4(%rax,%rsi,4)
incq %rsi
cmpq 0x40(%rsp), %rsi
movq 0x90(%rsp), %rbp
jne 0x2a419a
jmp 0x2a434e
movslq %r14d, %rsi
movl $0x10, %edi
callq 0x2094bf
testq %rax, %rax
je 0x2a43ec
movq %rax, 0x20(%rsp)
testl %r14d, %r14d
movq %r14, %r8
movq 0x38(%rsp), %r10
jle 0x2a43d6
movq 0x10(%rbp), %rdi
movl %r8d, %ecx
xorl %edx, %edx
movq 0x28(%rsp), %rax
movq 0x20(%rsp), %r9
movq 0x30(%rsp), %r11
movzbl (%r11,%rdx), %esi
movl (%rdi,%rsi,4), %esi
movl %esi, (%r9,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x2a4328
jmp 0x2a4119
movl $0xc0000000, %ecx       # imm = 0xC0000000
movq 0x18(%rsp), %rdi
movl %edi, %r10d
movq %r8, %r9
movq 0x18(%rsp), %rdx
cmpl $0x2, %edx
movl $0x1, %eax
cmovgel %edx, %eax
xorl %edx, %edx
movl 0x4(%r15,%rdx,4), %esi
movq 0x10(%r13), %r8
movq (%r8), %r8
movl %esi, (%r8,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0x2a4363
movl %ecx, (%r13)
movl %r9d, 0x4(%r13)
movl %r10d, 0x8(%r13)
movq 0x28(%rsp), %rdi
callq 0x2094b5
movq %r15, %rdi
callq 0x2094b5
movq %r12, %rdi
callq 0x2094b5
cmpl $0x0, 0x30(%rbp)
jne 0x2a43ef
movq 0x20(%rsp), %rdi
callq 0x2094b5
jmp 0x2a43ef
callq 0x1a13ff
jmp 0x2a43ec
callq 0x1a13d9
jmp 0x2a43ec
callq 0x1a13b3
jmp 0x2a43ec
callq 0x1a138d
jmp 0x2a43ec
callq 0x1a1367
jmp 0x2a43ec
movq 0x28(%rsp), %rax
jmp 0x2a4119
callq 0x1a1341
jmp 0x2a43ec
callq 0x1a131b
xorl %r13d, %r13d
movq %r13, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)