// File: /workspace/github_c_makefile_star2_O1/nh13[P]ksw/src/parasail/src/sw_scan.c
// Function: parasail_sw_rowcol_scan
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 HB = NULL;
    int * restrict H  = NULL;
    int * restrict E  = NULL;
    int * restrict HtB= NULL;
    int * restrict Ht = NULL;
    int * restrict FtB= NULL;
    int * restrict Ft = 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_SCAN
        | 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);
    HB = parasail_memalign_int(16, s1Len+1);
    H  = HB+1;
    E  = parasail_memalign_int(16, s1Len);
    HtB= parasail_memalign_int(16, s1Len+1);
    Ht = HtB+1;
    FtB= parasail_memalign_int(16, s1Len+1);
    Ft = FtB+1;

    /* validate heap variables */
    if (!s2) return NULL;
    if (!HB) return NULL;
    if (!E) return NULL;
    if (!HtB) return NULL;
    if (!FtB) 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]];
    }

    /* initialize H */
    H[-1] = 0;
    Ht[-1] = 0;
    for (i=0; i<s1Len; ++i) {
        H[i] = 0;
    }
    Ft[-1] = NEG_INF_32;

    /* initialize E */
    for (i=0; i<s1Len; ++i) {
        E[i] = NEG_INF_32;
    }

    /* iterate over database */
    for (j=0; j<s2Len; ++j) {
        /* calculate E */
        for (i=0; i<s1Len; ++i) {
            E[i] = MAX(E[i]-gap, H[i]-open);
        }
        /* calculate Ht */
        for (i=0; i<s1Len; ++i) {
            int matval = matrix->type == PARASAIL_MATRIX_TYPE_SQUARE ?
                         matrix->matrix[matrix->size*s1[i]+s2[j]] :
                         matrix->matrix[matrix->size*i+s2[j]];
            Ht[i] = MAX(H[i-1]+matval, E[i]);
        }
        /* calculate Ft */
        for (i=0; i<s1Len; ++i) {
            Ft[i] = MAX(Ft[i-1]-gap, Ht[i-1]);
        }
        /* calculate H */
        for (i=0; i<s1Len; ++i) {
            H[i] = MAX(Ht[i], Ft[i]-open);
            H[i] = MAX(H[i], 0);
#ifdef PARASAIL_TABLE
            result->tables->score_table[i*s2Len + j] = H[i];
#endif
            if (H[i] > score) {
                score = H[i];
                end_query = i;
                end_ref = j;
            }
        }
#ifdef PARASAIL_ROWCOL
        if (j == s2Len-1) {
            for (i=0; i<s1Len; ++i) {
                result->rowcols->score_col[i] = H[i];
            }
        }
        result->rowcols->score_row[j] = H[s1Len-1];
#endif
    }

    result->score = score;
    result->end_query = end_query;
    result->end_ref = end_ref;

    parasail_free(FtB);
    parasail_free(HtB);
    parasail_free(E);
    parasail_free(HB);
    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 0x2a5390
movl %ecx, %ebx
testl %ecx, %ecx
jle 0x2a5397
testl %r8d, %r8d
js 0x2a539e
testl %r9d, %r9d
js 0x2a53a5
movl %r9d, 0xc(%rsp)
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0x2a53ac
movq %rdi, %r15
movl 0x30(%rax), %eax
testl %eax, %eax
jne 0x2a4fe2
testq %r15, %r15
je 0x2a53b3
movl %esi, %ecx
testl %esi, %esi
jle 0x2a53ba
testl %eax, %eax
je 0x2a4fed
movq 0x80(%rsp), %rax
movl 0x34(%rax), %ecx
movq %rdx, 0x10(%rsp)
movl %r8d, 0x8(%rsp)
movl %ecx, %edi
movl %ebx, %esi
movq %rcx, %r14
callq 0x209630
testq %rax, %rax
je 0x2a53bf
movq %r15, 0x18(%rsp)
movq %rax, 0x40(%rsp)
orl $0x1440204, 0xc(%rax)   # imm = 0x1440204
movl %ebx, %esi
movl $0x10, %edi
callq 0x2094bf
movq %rax, 0x30(%rsp)
leal 0x1(%r14), %eax
movslq %eax, %r13
movl $0x10, %edi
movq %r13, %rsi
callq 0x2094bf
movq %rax, %rbp
movq %r14, (%rsp)
movslq %r14d, %rsi
movl $0x10, %edi
movq %rsi, 0x38(%rsp)
callq 0x2094bf
movq %rax, %r12
movl $0x10, %edi
movq %r13, %rsi
callq 0x2094bf
movq %rax, %r15
movl $0x10, %edi
movq %r13, %rsi
callq 0x2094bf
movq 0x30(%rsp), %rdi
movq %rax, %r13
xorl %eax, %eax
testq %rdi, %rdi
je 0x2a53c1
testq %rbp, %rbp
je 0x2a53c1
testq %r12, %r12
je 0x2a53c1
testq %r15, %r15
je 0x2a53c1
testq %r13, %r13
je 0x2a53c1
movq %rbp, %r8
movq 0x80(%rsp), %rax
cmpl $0x0, 0x30(%rax)
movl (%rsp), %r14d
movq %rbp, 0x28(%rsp)
je 0x2a50dc
movq $0x0, 0x20(%rsp)
movq 0x10(%rsp), %r9
jmp 0x2a5140
movq %rdi, %rbp
movl $0x10, %edi
movq 0x38(%rsp), %rsi
callq 0x2094bf
testq %rax, %rax
je 0x2a53bf
movq %rax, %rsi
cmpl $0x0, (%rsp)
movq %rbp, %rdi
movq 0x28(%rsp), %r8
movq 0x10(%rsp), %r9
movq %rax, 0x20(%rsp)
jle 0x2a5138
movq 0x80(%rsp), %rax
movq 0x10(%rax), %rax
xorl %ecx, %ecx
movq 0x18(%rsp), %r10
movzbl (%r10,%rcx), %edx
movl (%rax,%rdx,4), %edx
movl %edx, (%rsi,%rcx,4)
incq %rcx
cmpq %rcx, %r14
jne 0x2a5125
movq 0x80(%rsp), %rax
movq %r8, %rbp
addq $0x4, %rbp
movq 0x10(%rax), %rax
cmpl $0x2, %ebx
movl $0x1, %ecx
cmovgel %ebx, %ecx
xorl %edx, %edx
movzbl (%r9,%rdx), %esi
movl (%rax,%rsi,4), %esi
movl %esi, (%rdi,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x2a5158
xorl %eax, %eax
movl %eax, (%r8)
movl %eax, (%r15)
movq (%rsp), %rcx
testl %ecx, %ecx
jle 0x2a5191
leaq (,%r14,4), %rdx
movq %rbp, %rdi
xorl %esi, %esi
callq 0x19e090
movq (%rsp), %rcx
movl $0xc0000000, (%r13)     # imm = 0xC0000000
testl %ecx, %ecx
jle 0x2a51af
xorl %eax, %eax
movl $0xc0000000, (%r12,%rax,4) # imm = 0xC0000000
incq %rax
cmpq %rax, %r14
jne 0x2a519f
leal -0x1(%rbx), %eax
movq %rax, 0x10(%rsp)
cmpl $0x2, %ebx
movl $0x1, %eax
cmovgel %ebx, %eax
movq %rax, 0x18(%rsp)
movl $0xc0000000, %edx       # imm = 0xC0000000
xorl %esi, %esi
xorl %r8d, %r8d
movl %ecx, %edi
testl %ecx, %ecx
movl 0xc(%rsp), %eax
movl 0x8(%rsp), %ecx
jle 0x2a5204
xorl %r9d, %r9d
movl (%r12,%r9,4), %r10d
subl %eax, %r10d
movl (%rbp,%r9,4), %r11d
subl %ecx, %r11d
cmpl %r11d, %r10d
cmovgl %r10d, %r11d
movl %r11d, (%r12,%r9,4)
incq %r9
cmpq %r9, %r14
jne 0x2a51e2
movq (%rsp), %rcx
testl %ecx, %ecx
movq 0x80(%rsp), %rax
jle 0x2a5275
movq 0x8(%rax), %r9
xorl %r10d, %r10d
cmpl $0x0, 0x30(%rax)
je 0x2a522b
movl 0x18(%rax), %r11d
imull %r10d, %r11d
jmp 0x2a5239
movq 0x20(%rsp), %r11
movl (%r11,%r10,4), %r11d
imull 0x18(%rax), %r11d
movq 0x30(%rsp), %rax
movslq (%rax,%r8,4), %rax
movslq %r11d, %r11
addq %rax, %r11
movq 0x28(%rsp), %rax
movl (%rax,%r10,4), %eax
addl (%r9,%r11,4), %eax
movl (%r12,%r10,4), %r11d
cmpl %r11d, %eax
cmovlel %r11d, %eax
movl %eax, 0x4(%r15,%r10,4)
incq %r10
cmpq %r10, %r14
movq 0x80(%rsp), %rax
jne 0x2a521b
testl %ecx, %ecx
movl 0xc(%rsp), %r11d
jle 0x2a52a0
movl (%r13), %r9d
xorl %r10d, %r10d
subl %r11d, %r9d
movl (%r15,%r10,4), %eax
cmpl %eax, %r9d
cmovlel %eax, %r9d
movl %r9d, 0x4(%r13,%r10,4)
incq %r10
cmpq %r10, %r14
jne 0x2a5285
testl %ecx, %ecx
jle 0x2a52e3
xorl %r9d, %r9d
movl 0x8(%rsp), %r11d
movl 0x4(%r15,%r9,4), %eax
movl 0x4(%r13,%r9,4), %r10d
subl %r11d, %r10d
cmpl %r10d, %eax
cmovgl %eax, %r10d
testl %r10d, %r10d
cmovlel %esi, %r10d
movl %r10d, (%rbp,%r9,4)
cmpl %edx, %r10d
cmovgl %r10d, %edx
cmovgl %r9d, %edi
cmovgl %r8d, %ebx
incq %r9
cmpq %r9, %r14
jne 0x2a52ac
testl %ecx, %ecx
setle %al
cmpq 0x10(%rsp), %r8
setne %r9b
orb %al, %r9b
movq 0x40(%rsp), %r11
jne 0x2a5317
xorl %r9d, %r9d
movl (%rbp,%r9,4), %eax
movq 0x10(%r11), %r10
movq 0x8(%r10), %r10
movl %eax, (%r10,%r9,4)
incq %r9
cmpq %r9, %r14
jne 0x2a52fe
movq 0x38(%rsp), %rax
movl -0x4(%rbp,%rax,4), %eax
movq 0x10(%r11), %r9
movq (%r9), %r9
movl %eax, (%r9,%r8,4)
incq %r8
cmpq 0x18(%rsp), %r8
jne 0x2a51d3
movl %edx, (%r11)
movl %edi, 0x4(%r11)
movl %ebx, 0x8(%r11)
movq %r13, %rdi
movq %r11, %rbx
callq 0x2094b5
movq %r15, %rdi
callq 0x2094b5
movq %r12, %rdi
callq 0x2094b5
movq 0x28(%rsp), %rdi
callq 0x2094b5
movq 0x30(%rsp), %rdi
callq 0x2094b5
movq 0x80(%rsp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x2a538b
movq 0x20(%rsp), %rdi
callq 0x2094b5
movq %rbx, %rax
jmp 0x2a53c1
callq 0x1a171d
jmp 0x2a53bf
callq 0x1a16f7
jmp 0x2a53bf
callq 0x1a16d1
jmp 0x2a53bf
callq 0x1a16ab
jmp 0x2a53bf
callq 0x1a1685
jmp 0x2a53bf
callq 0x1a165f
jmp 0x2a53bf
callq 0x1a1639
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq