// File: /workspace/github_c_makefile_star2_O2/nh13[P]ksw/src/parasail/src/sg_scan.c
// Function: parasail_sg_flags_rowcol_scan
parasail_result_t* FNAME(
        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,
        int s1_beg, int s1_end, int s2_beg, int s2_end)
{
    /* 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 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_SG | PARASAIL_FLAG_NOVEC_SCAN
        | PARASAIL_FLAG_BITS_INT | PARASAIL_FLAG_LANES_1;
    result->flag |= s1_beg ? PARASAIL_FLAG_SG_S1_BEG : 0;
    result->flag |= s1_end ? PARASAIL_FLAG_SG_S1_END : 0;
    result->flag |= s2_beg ? PARASAIL_FLAG_SG_S2_BEG : 0;
    result->flag |= s2_end ? PARASAIL_FLAG_SG_S2_END : 0;
#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;

    /* validate heap variables */
    if (!s2) return NULL;
    if (!HB) return NULL;
    if (!E) return NULL;
    if (!HtB) 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;
    if (s1_beg) {
        for (i=0; i<s1Len; ++i) {
            H[i] = 0;
        }
    }
    else {
        for (i=0; i<s1Len; ++i) {
            H[i] = -open -i*gap;
        }
    }

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

    /* iterate over database */
    for (j=0; j<s2Len-1; ++j) {
        int Ft = NEG_INF_32;
        /* 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]);
        }
        Ht[-1] = s2_beg ? 0 : (-open -j*gap);
        /* calculate H */
        for (i=0; i<s1Len; ++i) {
            int Ft_opn;
            int Ht_pre = Ht[i-1];
            int Ft_ext = Ft-gap;
            if (Ht_pre >= Ft_ext) {
                Ft = Ht_pre;
            }
            else {
                Ft = Ft_ext;
            }
            Ft_opn = Ft-open;
            H[i] = MAX(Ht[i], Ft_opn);
#ifdef PARASAIL_TABLE
            result->tables->score_table[i*s2Len + j] = H[i];
#endif
        }
        H[-1] = s2_beg ? 0 : (-open - j*gap);
#ifdef PARASAIL_ROWCOL
        result->rowcols->score_row[j] = H[s1Len-1];
#endif
        if (s2_end && H[s1Len-1] > score) {
            score = H[s1Len-1];
            end_query = s1Len-1;
            end_ref = j;
        }
    }
    j = s2Len - 1;
    {
        int Ft = NEG_INF_32;
        /* 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]);
        }
        Ht[-1] = s2_beg ? 0 : (-open -j*gap);
        /* calculate H */
        for (i=0; i<s1Len; ++i) {
            int Ft_opn;
            int Ht_pre = Ht[i-1];
            int Ft_ext = Ft-gap;
            if (Ht_pre >= Ft_ext) {
                Ft = Ht_pre;
            }
            else {
                Ft = Ft_ext;
            }
            Ft_opn = Ft-open;
            H[i] = MAX(Ht[i], Ft_opn);
#ifdef PARASAIL_TABLE
            result->tables->score_table[i*s2Len + j] = H[i];
#endif
#ifdef PARASAIL_ROWCOL
            result->rowcols->score_col[i] = H[i];
#endif
            if (s1_end && H[i] > score) {
                score = H[i];
                end_query = i;
                end_ref = j;
            }
        }
#ifdef PARASAIL_ROWCOL
        result->rowcols->score_row[j] = H[s1Len-1];
#endif
    }
    if (s2_end && H[s1Len-1] > score) {
        score = H[s1Len-1];
        end_query = s1Len-1;
        end_ref = s2Len-1;
    }
    if (!s1_end && !s2_end) {
        score = H[s1Len-1];
        end_query = s1Len-1;
        end_ref = s2Len-1;
    }

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

    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 0x248c7d
movl %ecx, %ebx
testl %ecx, %ecx
jle 0x248ca1
movl %r8d, %r12d
testl %r8d, %r8d
js 0x248fe3
movl %r9d, %ebp
testl %r9d, %r9d
js 0x249007
movq 0x80(%rsp), %r13
testq %r13, %r13
je 0x249028
cmpl $0x0, 0x30(%r13)
je 0x248a6f
movl 0x34(%r13), %r14d
jmp 0x248a83
testq %rdi, %rdi
je 0x249049
movl %esi, %r14d
testl %esi, %esi
jle 0x24906a
movq %rdi, 0x40(%rsp)
movq %rdx, (%rsp)
movl %r14d, %edi
movl %ebx, %esi
callq 0x1ab93b
testq %rax, %rax
je 0x249090
xorl %edi, %edi
cmpl $0x0, 0x88(%rsp)
setne %dil
xorl %ecx, %ecx
cmpl $0x0, 0x90(%rsp)
setne %cl
shll $0x4, %ecx
xorl %edx, %edx
cmpl $0x0, 0x98(%rsp)
setne %dl
shll $0xe, %edx
xorl %esi, %esi
cmpl $0x0, 0xa0(%rsp)
setne %sil
shll $0xf, %esi
leal (%rcx,%rdi,8), %ecx
orl %edx, %ecx
orl %esi, %ecx
orl 0xc(%rax), %ecx
orl $0x1440202, %ecx        # imm = 0x1440202
movl %ecx, 0xc(%rax)
movl %ebx, %esi
pushq $0x10
popq %rdi
movq %rsi, 0x38(%rsp)
movq %rax, 0x18(%rsp)
callq 0x1ab76d
movq %rax, 0x28(%rsp)
leal 0x1(%r14), %eax
movslq %eax, %r15
pushq $0x10
popq %rdi
movq %r15, %rsi
callq 0x1ab76d
movq %rbx, 0x20(%rsp)
movq %rax, %rbx
movslq %r14d, %rsi
pushq $0x10
popq %rdi
movq %rsi, 0x10(%rsp)
callq 0x1ab76d
movq %r14, 0x8(%rsp)
movq %rax, %r14
pushq $0x10
popq %rdi
movq %r15, %rsi
callq 0x1ab76d
movq 0x28(%rsp), %rcx
movq %rax, %r15
movq %rcx, %xmm0
movq %rbx, %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq %r14, %xmm1
movq %rax, %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
testl %eax, %eax
jne 0x249090
movq 0x10(%rsp), %rsi
movl 0x90(%rsp), %eax
movl %eax, 0x34(%rsp)
cmpl $0x0, 0x30(%r13)
je 0x248c1e
movq $0x0, 0x10(%rsp)
movq 0x18(%rsp), %r11
movl 0x98(%rsp), %r9d
movq (%rsp), %r8
movq 0x10(%r13), %rax
xorl %ecx, %ecx
movl 0x88(%rsp), %edi
movq 0x38(%rsp), %r10
movq 0x28(%rsp), %rsi
cmpq %rcx, %r10
je 0x248bee
movzbl (%r8,%rcx), %edx
movl (%rax,%rdx,4), %edx
movl %edx, (%rsi,%rcx,4)
incq %rcx
jmp 0x248bd9
andl $0x0, (%rbx)
andl $0x0, (%r15)
xorl %eax, %eax
movq 0x8(%rsp), %rcx
testl %ecx, %ecx
cmovgl %ecx, %eax
testl %edi, %edi
je 0x248cc5
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x248cdc
andl $0x0, 0x4(%rbx,%rcx,4)
incq %rcx
jmp 0x248c0b
pushq $0x10
popq %rdi
callq 0x1ab76d
xorl %edi, %edi
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x249090
movq 0x8(%rsp), %rdx
testl %edx, %edx
movl $0x0, %ecx
cmovgl %edx, %ecx
movq 0x18(%rsp), %r11
movl 0x98(%rsp), %r9d
movq (%rsp), %r8
movq 0x40(%rsp), %r10
movq 0x10(%rsp), %rax
cmpq %rdi, %rcx
je 0x248bc2
movq 0x10(%r13), %rdx
movzbl (%r10,%rdi), %esi
movl (%rdx,%rsi,4), %edx
movl %edx, (%rax,%rdi,4)
incq %rdi
jmp 0x248c60
movq 0x4f2354(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37e35d(%rip), %rsi    # 0x5c6feb
leaq 0x37ebd8(%rip), %rdx    # 0x5c786d
leaq 0x37ea61(%rip), %rcx    # 0x5c76fd
jmp 0x249089
movq 0x4f2330(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37ea4f(%rip), %rsi    # 0x5c7701
leaq 0x37ebb4(%rip), %rdx    # 0x5c786d
leaq 0x37ea55(%rip), %rcx    # 0x5c7715
jmp 0x249089
movl %r12d, %ecx
negl %ecx
xorl %edx, %edx
cmpq %rdx, %rax
je 0x248cdc
movl %ecx, 0x4(%rbx,%rdx,4)
incq %rdx
subl %ebp, %ecx
jmp 0x248ccc
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x248cf0
movl $0xc0000000, (%r14,%rcx,4) # imm = 0xC0000000
incq %rcx
jmp 0x248cde
movq 0x20(%rsp), %rcx
decl %ecx
movq %rcx, (%rsp)
movq 0x8(%rsp), %rcx
leal -0x1(%rcx), %edx
movslq %edx, %rdx
movl $0xc0000000, %esi       # imm = 0xC0000000
xorl %r8d, %r8d
cmpq (%rsp), %r8
movq 0x28(%rsp), %rcx
je 0x248e41
xorl %r9d, %r9d
cmpq %r9, %rax
je 0x248d44
movl (%r14,%r9,4), %r10d
subl %ebp, %r10d
movl 0x4(%rbx,%r9,4), %r11d
subl %r12d, %r11d
cmpl %r11d, %r10d
cmovgl %r10d, %r11d
movl %r11d, (%r14,%r9,4)
incq %r9
jmp 0x248d20
xorl %r9d, %r9d
cmpq %r9, %rax
je 0x248d92
cmpl $0x0, 0x30(%r13)
movl 0x18(%r13), %r10d
je 0x248d5d
imull %r9d, %r10d
jmp 0x248d67
movq 0x10(%rsp), %rdi
imull (%rdi,%r9,4), %r10d
movq 0x8(%r13), %r11
movslq (%rcx,%r8,4), %rdi
movslq %r10d, %r10
addq %rdi, %r10
movl (%rbx,%r9,4), %edi
addl (%r11,%r10,4), %edi
movl (%r14,%r9,4), %r10d
cmpl %r10d, %edi
cmovlel %r10d, %edi
movl %edi, 0x4(%r15,%r9,4)
incq %r9
jmp 0x248d47
movl %r8d, %r9d
imull %ebp, %r9d
addl %r12d, %r9d
negl %r9d
cmpl $0x0, 0x98(%rsp)
movl $0x0, %ecx
cmovnel %ecx, %r9d
movl %r9d, (%r15)
movl $0xc0000000, %ecx       # imm = 0xC0000000
xorl %r11d, %r11d
cmpq %r11, %rax
je 0x248de7
subl %ebp, %ecx
movl (%r15,%r11,4), %edi
cmpl %ecx, %edi
cmovgl %edi, %ecx
movl 0x4(%r15,%r11,4), %edi
movl %ecx, %r10d
subl %r12d, %r10d
cmpl %r10d, %edi
cmovgl %edi, %r10d
movl %r10d, 0x4(%rbx,%r11,4)
incq %r11
jmp 0x248dbb
cmpl $0x0, 0xa0(%rsp)
setne %cl
movl %r9d, (%rbx)
movl 0x4(%rbx,%rdx,4), %edi
cmpl %esi, %edi
setg %r9b
testb %r9b, %cl
movq 0x18(%rsp), %r11
movq 0x10(%r11), %rcx
movq (%rcx), %rcx
cmovnel %edi, %esi
movq 0x8(%rsp), %r9
cmovnel %edx, %r9d
movq %r9, 0x8(%rsp)
movl %edi, (%rcx,%r8,4)
movq 0x20(%rsp), %rcx
cmovnel %r8d, %ecx
movq %rcx, 0x20(%rsp)
incq %r8
movl 0x98(%rsp), %r9d
jmp 0x248d0e
xorl %edi, %edi
cmpq %rdi, %rax
je 0x248e66
movl (%r14,%rdi,4), %ecx
subl %ebp, %ecx
movl 0x4(%rbx,%rdi,4), %r8d
subl %r12d, %r8d
cmpl %r8d, %ecx
cmovgl %ecx, %r8d
movl %r8d, (%r14,%rdi,4)
incq %rdi
jmp 0x248e43
movl (%rsp), %edi
xorl %r8d, %r8d
cmpq %r8, %rax
je 0x248ec4
cmpl $0x0, 0x30(%r13)
movl 0x18(%r13), %r9d
je 0x248e82
imull %r8d, %r9d
jmp 0x248e8c
movq 0x10(%rsp), %rcx
imull (%rcx,%r8,4), %r9d
movq 0x8(%r13), %rcx
movq 0x28(%rsp), %r10
movslq (%r10,%rdi,4), %r10
movslq %r9d, %r9
addq %r10, %r9
movl (%rbx,%r8,4), %r10d
addl (%rcx,%r9,4), %r10d
movl (%r14,%r8,4), %ecx
cmpl %ecx, %r10d
cmovlel %ecx, %r10d
movl %r10d, 0x4(%r15,%r8,4)
incq %r8
movl 0x98(%rsp), %r9d
jmp 0x248e6c
movq (%rsp), %rcx
imull %ebp, %ecx
addl %r12d, %ecx
negl %ecx
xorl %r8d, %r8d
testl %r9d, %r9d
cmovnel %r8d, %ecx
movl %ecx, (%r15)
movl $0xc0000000, %r9d       # imm = 0xC0000000
movl 0xa0(%rsp), %ecx
cmpq %r8, %rax
je 0x248f5b
subl %ebp, %r9d
movl (%r15,%r8,4), %ecx
movl 0x4(%r15,%r8,4), %r10d
cmpl %r9d, %ecx
cmovgl %ecx, %r9d
movl %r9d, %ecx
subl %r12d, %ecx
cmpl %ecx, %r10d
cmovgl %r10d, %ecx
movl %ecx, 0x4(%rbx,%r8,4)
movq 0x10(%r11), %r10
movq 0x8(%r10), %r10
movl %ecx, (%r10,%r8,4)
cmpl $0x0, 0x90(%rsp)
je 0x248f4f
movl 0x4(%rbx,%r8,4), %r10d
cmpl %esi, %r10d
movl 0xa0(%rsp), %ecx
jle 0x248f56
movl %r10d, %esi
movl %r8d, %ecx
movq %rcx, 0x8(%rsp)
movq (%rsp), %rcx
movq %rcx, 0x20(%rsp)
movl 0xa0(%rsp), %ecx
incq %r8
jmp 0x248eea
testl %ecx, %ecx
setne %al
movl %ecx, %r9d
movl 0x4(%rbx,%rdx,4), %ecx
cmpl %esi, %ecx
setg %r8b
andb %al, %r8b
movq 0x10(%r11), %rax
movq (%rax), %rax
orl %r9d, 0x34(%rsp)
sete %r9b
orb %r8b, %r9b
cmovnel %ecx, %esi
movq 0x8(%rsp), %r8
cmovnel %edx, %r8d
movq 0x20(%rsp), %rdx
cmovnel (%rsp), %edx
movl %ecx, (%rax,%rdi,4)
movl %esi, (%r11)
movl %r8d, 0x4(%r11)
movl %edx, 0x8(%r11)
movq %r15, %rdi
callq 0x1ab763
movq %r14, %rdi
callq 0x1ab763
movq %rbx, %rdi
callq 0x1ab763
movq 0x28(%rsp), %rdi
callq 0x1ab763
cmpl $0x0, 0x30(%r13)
jne 0x248fd9
movq 0x10(%rsp), %rdi
callq 0x1ab763
movq 0x18(%rsp), %rax
jmp 0x249092
movq 0x4f1fee(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37e727(%rip), %rsi    # 0x5c771b
leaq 0x37e872(%rip), %rdx    # 0x5c786d
leaq 0x37e72e(%rip), %rcx    # 0x5c7730
jmp 0x249089
movq 0x4f1fca(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37e703(%rip), %rsi    # 0x5c771b
leaq 0x37e84e(%rip), %rdx    # 0x5c786d
leaq 0x37e70f(%rip), %rcx    # 0x5c7735
jmp 0x249089
movq 0x4f1fa9(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37dfb2(%rip), %rsi    # 0x5c6feb
leaq 0x37e82d(%rip), %rdx    # 0x5c786d
leaq 0x37e8fb(%rip), %rcx    # 0x5c7942
jmp 0x249089
movq 0x4f1f88(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37df91(%rip), %rsi    # 0x5c6feb
leaq 0x37e80c(%rip), %rdx    # 0x5c786d
leaq 0x37e6d1(%rip), %rcx    # 0x5c7739
jmp 0x249089
movq 0x4f1f67(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37e686(%rip), %rsi    # 0x5c7701
leaq 0x37e7eb(%rip), %rdx    # 0x5c786d
leaq 0x37e6b4(%rip), %rcx    # 0x5c773d
xorl %eax, %eax
callq 0x19e180
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq