// File: /workspace/github_c_makefile_star2_O2/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
movl %r9d, 0x8(%rsp)
movl %r8d, 0xc(%rsp)
testq %rdx, %rdx
je 0x2495b8
movl %ecx, %ebx
testl %ecx, %ecx
jle 0x2495dc
cmpl $0x0, 0xc(%rsp)
js 0x249600
cmpl $0x0, 0x8(%rsp)
js 0x249624
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0x249645
cmpl $0x0, 0x30(%rax)
je 0x24923a
movl 0x34(%rax), %r15d
jmp 0x24924e
testq %rdi, %rdi
je 0x249666
movl %esi, %r15d
testl %esi, %esi
jle 0x249687
movq %rdi, 0x40(%rsp)
movq %rdx, 0x30(%rsp)
movl %r15d, %edi
movl %ebx, %esi
callq 0x1ab93b
testq %rax, %rax
je 0x2496ad
movq %rax, 0x28(%rsp)
orl $0x1440204, 0xc(%rax)   # imm = 0x1440204
movq %rbx, %r14
movl %ebx, %esi
pushq $0x10
popq %rbp
movq %rbp, %rdi
movq %rsi, 0x20(%rsp)
callq 0x1ab76d
movq %rax, 0x18(%rsp)
leal 0x1(%r15), %eax
movslq %eax, %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1ab76d
movq %rax, %r12
movslq %r15d, %rsi
movq %rbp, %rdi
movq %rsi, 0x38(%rsp)
callq 0x1ab76d
movq %rax, %r13
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1ab76d
movq %rax, %rbp
pushq $0x10
popq %rdi
movq %rbx, %rsi
callq 0x1ab76d
movq %rax, %rbx
movq 0x18(%rsp), %xmm0
movq %r12, %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq %r13, %xmm1
movq %rbp, %xmm2
punpcklqdq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0]
pxor %xmm2, %xmm2
pcmpeqd %xmm2, %xmm0
pcmpeqd %xmm2, %xmm1
movdqa %xmm0, %xmm2
shufps $0xdd, %xmm1, %xmm2     # xmm2 = xmm2[1,3],xmm1[1,3]
shufps $0x88, %xmm1, %xmm0     # xmm0 = xmm0[0,2],xmm1[0,2]
andps %xmm2, %xmm0
movmskps %xmm0, %eax
xorl %r9d, %r9d
testl %eax, %eax
jne 0x2496b0
testq %rbx, %rbx
je 0x2496b0
movq 0x80(%rsp), %r11
cmpl $0x0, 0x30(%r11)
je 0x249554
movq $0x0, 0x10(%rsp)
movq 0x20(%rsp), %r8
movq 0x30(%rsp), %rdi
movq 0x10(%r11), %rax
xorl %ecx, %ecx
movq 0x18(%rsp), %rsi
cmpq %rcx, %r8
je 0x249369
movzbl (%rdi,%rcx), %edx
movl (%rax,%rdx,4), %edx
movl %edx, (%rsi,%rcx,4)
incq %rcx
jmp 0x249355
andl $0x0, (%r12)
andl $0x0, (%rbp)
xorl %ecx, %ecx
testl %r15d, %r15d
movl $0x0, %eax
cmovgl %r15d, %eax
cmpq %rcx, %rax
je 0x249390
andl $0x0, 0x4(%r12,%rcx,4)
incq %rcx
jmp 0x249380
movl $0xc0000000, (%rbx)     # imm = 0xC0000000
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x2493ab
movl $0xc0000000, (%r13,%rcx,4) # imm = 0xC0000000
incq %rcx
jmp 0x249398
leal -0x1(%r14), %ecx
movl $0xc0000000, %edx       # imm = 0xC0000000
xorl %esi, %esi
xorl %edi, %edi
cmpq %r8, %rdi
je 0x2494fd
xorl %r8d, %r8d
cmpq %r8, %rax
je 0x2493ee
movl (%r13,%r8,4), %r9d
subl 0x8(%rsp), %r9d
movl 0x4(%r12,%r8,4), %r10d
subl 0xc(%rsp), %r10d
cmpl %r10d, %r9d
cmovgl %r9d, %r10d
movl %r10d, (%r13,%r8,4)
incq %r8
jmp 0x2493c4
xorl %r8d, %r8d
cmpq %r8, %rax
je 0x24944a
cmpl $0x0, 0x30(%r11)
movl 0x18(%r11), %r9d
je 0x249407
imull %r8d, %r9d
jmp 0x249411
movq 0x10(%rsp), %r10
imull (%r10,%r8,4), %r9d
movq 0x8(%r11), %r10
movq 0x18(%rsp), %r11
movslq (%r11,%rdi,4), %r11
movslq %r9d, %r9
addq %r11, %r9
movl (%r12,%r8,4), %r11d
addl (%r10,%r9,4), %r11d
movl (%r13,%r8,4), %r9d
cmpl %r9d, %r11d
cmovlel %r9d, %r11d
movl %r11d, 0x4(%rbp,%r8,4)
movq 0x80(%rsp), %r11
incq %r8
jmp 0x2493f1
xorl %r8d, %r8d
cmpq %r8, %rax
je 0x249471
movl (%rbx,%r8,4), %r9d
subl 0x8(%rsp), %r9d
movl (%rbp,%r8,4), %r10d
cmpl %r10d, %r9d
cmovlel %r10d, %r9d
movl %r9d, 0x4(%rbx,%r8,4)
incq %r8
jmp 0x24944d
xorl %r8d, %r8d
cmpq %r8, %rax
je 0x2494af
movl 0x4(%rbp,%r8,4), %r9d
movl 0x4(%rbx,%r8,4), %r10d
subl 0xc(%rsp), %r10d
cmpl %r10d, %r9d
cmovgl %r9d, %r10d
testl %r10d, %r10d
cmovlel %esi, %r10d
cmpl %edx, %r10d
cmovgl %r10d, %edx
cmovgl %r8d, %r15d
movl %r10d, 0x4(%r12,%r8,4)
cmovgl %edi, %r14d
incq %r8
jmp 0x249474
cmpq %rcx, %rdi
jne 0x2494d7
xorl %r8d, %r8d
cmpq %r8, %rax
je 0x2494d7
movl 0x4(%r12,%r8,4), %r9d
movq 0x28(%rsp), %r10
movq 0x10(%r10), %r10
movq 0x8(%r10), %r10
movl %r9d, (%r10,%r8,4)
incq %r8
jmp 0x2494b7
movq 0x38(%rsp), %r8
movl (%r12,%r8,4), %r8d
movq 0x28(%rsp), %r9
movq 0x10(%r9), %r9
movq (%r9), %r9
movl %r8d, (%r9,%rdi,4)
incq %rdi
movq 0x20(%rsp), %r8
jmp 0x2493b8
movq 0x28(%rsp), %rax
movl %edx, (%rax)
movl %r15d, 0x4(%rax)
movl %r14d, 0x8(%rax)
movq %rax, %r14
movq %rbx, %rdi
movq %r11, %rbx
callq 0x1ab763
movq %rbp, %rdi
callq 0x1ab763
movq %r13, %rdi
callq 0x1ab763
movq %r12, %rdi
callq 0x1ab763
movq 0x18(%rsp), %rdi
callq 0x1ab763
cmpl $0x0, 0x30(%rbx)
jne 0x24954c
movq 0x10(%rsp), %rdi
callq 0x1ab763
movq %r14, %r9
jmp 0x2496b0
pushq $0x10
popq %rdi
movq 0x38(%rsp), %rsi
callq 0x1ab76d
xorl %r9d, %r9d
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x2496b0
testl %r15d, %r15d
movl $0x0, %eax
cmovgl %r15d, %eax
movq 0x80(%rsp), %r11
movq 0x20(%rsp), %r8
movq 0x30(%rsp), %rdi
movq 0x40(%rsp), %rsi
cmpq %r9, %rax
je 0x24934a
movq 0x10(%r11), %rcx
movzbl (%rsi,%r9), %edx
movl (%rcx,%rdx,4), %ecx
movq 0x10(%rsp), %rdx
movl %ecx, (%rdx,%r9,4)
incq %r9
jmp 0x249595
movq 0x4f1a19(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37da22(%rip), %rsi    # 0x5c6feb
leaq 0x33d9d8(%rip), %rdx    # 0x586fa8
leaq 0x37e126(%rip), %rcx    # 0x5c76fd
jmp 0x2496a6
movq 0x4f19f5(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37e114(%rip), %rsi    # 0x5c7701
leaq 0x33d9b4(%rip), %rdx    # 0x586fa8
leaq 0x37e11a(%rip), %rcx    # 0x5c7715
jmp 0x2496a6
movq 0x4f19d1(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37e10a(%rip), %rsi    # 0x5c771b
leaq 0x33d990(%rip), %rdx    # 0x586fa8
leaq 0x37e111(%rip), %rcx    # 0x5c7730
jmp 0x2496a6
movq 0x4f19ad(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37e0e6(%rip), %rsi    # 0x5c771b
leaq 0x33d96c(%rip), %rdx    # 0x586fa8
leaq 0x37e0f2(%rip), %rcx    # 0x5c7735
jmp 0x2496a6
movq 0x4f198c(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37d995(%rip), %rsi    # 0x5c6feb
leaq 0x33d94b(%rip), %rdx    # 0x586fa8
leaq 0x37e2de(%rip), %rcx    # 0x5c7942
jmp 0x2496a6
movq 0x4f196b(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37d974(%rip), %rsi    # 0x5c6feb
leaq 0x33d92a(%rip), %rdx    # 0x586fa8
leaq 0x37e0b4(%rip), %rcx    # 0x5c7739
jmp 0x2496a6
movq 0x4f194a(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37e069(%rip), %rsi    # 0x5c7701
leaq 0x33d909(%rip), %rdx    # 0x586fa8
leaq 0x37e097(%rip), %rcx    # 0x5c773d
xorl %eax, %eax
callq 0x19e180
xorl %r9d, %r9d
movq %r9, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop