// File: /workspace/github_c_makefile_star2_O1/nh13[P]ksw/src/parasail/src/sg_scan.c
// Function: parasail_sg_flags_table_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 $0x68, %rsp
testq %rdx, %rdx
je 0x29f96f
movl %ecx, %r14d
testl %ecx, %ecx
jle 0x29f976
movl %r8d, %r12d
testl %r8d, %r8d
js 0x29f97d
movl %r9d, %ebp
testl %r9d, %r9d
js 0x29f984
movq 0xa0(%rsp), %rcx
testq %rcx, %rcx
je 0x29f98b
movq %rdi, %rbx
movl 0x30(%rcx), %eax
testl %eax, %eax
jne 0x29f39d
testq %rbx, %rbx
je 0x29f99c
movl %esi, %r8d
testl %esi, %esi
jle 0x29f9a3
testl %eax, %eax
je 0x29f3a1
movl 0x34(%rcx), %r8d
movq %rdx, 0x30(%rsp)
movl %r8d, %edi
movl %r14d, %esi
movq %r8, %r15
callq 0x20959f
testq %rax, %rax
je 0x29f9a8
movq %rbx, 0x48(%rsp)
movl 0xc0(%rsp), %r8d
xorl %edi, %edi
cmpl $0x0, 0xa8(%rsp)
setne %dil
xorl %ecx, %ecx
cmpl $0x0, 0xb0(%rsp)
setne %cl
shll $0x4, %ecx
xorl %edx, %edx
cmpl $0x0, 0xb8(%rsp)
setne %dl
shll $0xe, %edx
xorl %esi, %esi
movl %r8d, 0x50(%rsp)
testl %r8d, %r8d
setne %sil
shll $0xf, %esi
leal (%rcx,%rdi,8), %ecx
orl %edx, %ecx
orl %esi, %ecx
orl 0xc(%rax), %ecx
orl $0x1420202, %ecx        # imm = 0x1420202
movq %rax, 0x18(%rsp)
movl %ecx, 0xc(%rax)
movl %r14d, %esi
movl $0x10, %edi
movq %rsi, 0x58(%rsp)
callq 0x2094bf
movq %rax, %r13
leal 0x1(%r15), %eax
movslq %eax, %rbx
movl $0x10, %edi
movq %rbx, %rsi
callq 0x2094bf
movq %r15, %rcx
movq %rax, %r15
movq %rcx, 0x8(%rsp)
movslq %ecx, %rsi
movl $0x10, %edi
movq %rsi, 0x40(%rsp)
callq 0x2094bf
movq %r14, 0x20(%rsp)
movq %rax, %r14
movl $0x10, %edi
movq %rbx, %rsi
callq 0x2094bf
movq %rax, %rbx
testq %r13, %r13
sete %al
movq %r15, 0x28(%rsp)
testq %r15, %r15
sete %cl
testq %r14, %r14
sete %dl
orb %al, %dl
orb %cl, %dl
testq %rbx, %rbx
sete %al
orb %dl, %al
jne 0x29f9a8
movq %r13, %r10
movq 0xa0(%rsp), %rdi
cmpl $0x0, 0x30(%rdi)
movq 0x8(%rsp), %r8
movl %r8d, %r15d
movq %r13, 0x10(%rsp)
je 0x29f560
movq $0x0, 0x38(%rsp)
movq 0x18(%rsp), %r9
movq 0x30(%rsp), %r11
movq 0x28(%rsp), %r13
addq $0x4, %r13
movq 0x10(%rdi), %rax
movq 0x20(%rsp), %rdx
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
xorl %edx, %edx
movzbl (%r11,%rdx), %esi
movl (%rax,%rsi,4), %esi
movl %esi, (%r10,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x29f4fc
xorl %eax, %eax
movq 0x28(%rsp), %rcx
movl %eax, (%rcx)
movl %eax, (%rbx)
cmpl $0x0, 0xa8(%rsp)
je 0x29f5c6
testl %r8d, %r8d
jle 0x29f5e1
leaq (,%r15,4), %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x19e090
movq 0x10(%rsp), %r10
movq 0x8(%rsp), %r8
movq 0xa0(%rsp), %rdi
movq 0x18(%rsp), %r9
jmp 0x29f5e1
movl $0x10, %edi
movq 0x40(%rsp), %rsi
callq 0x2094bf
testq %rax, %rax
je 0x29f9a8
movq 0x8(%rsp), %r8
testl %r8d, %r8d
movq 0x18(%rsp), %r9
movq 0x30(%rsp), %r11
movq %rax, 0x38(%rsp)
movq 0xa0(%rsp), %rdi
jle 0x29f992
movq 0x10(%rdi), %rsi
xorl %ecx, %ecx
movq 0x10(%rsp), %r10
movq 0x48(%rsp), %r13
movzbl (%r13,%rcx), %edx
movl (%rsi,%rdx,4), %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
cmpq %rcx, %r15
jne 0x29f5ad
jmp 0x29f4dd
testl %r8d, %r8d
jle 0x29f5e1
movl %r12d, %eax
negl %eax
xorl %ecx, %ecx
movl %eax, (%r13,%rcx,4)
incq %rcx
subl %ebp, %eax
cmpq %rcx, %r15
jne 0x29f5d2
testl %r8d, %r8d
jle 0x29f5f8
xorl %eax, %eax
movl $0xc0000000, (%r14,%rax,4) # imm = 0xC0000000
incq %rax
cmpq %rax, %r15
jne 0x29f5e8
movq 0x20(%rsp), %rax
leal -0x1(%rax), %ecx
movl $0xc0000000, %r11d      # imm = 0xC0000000
cmpl $0x1, %eax
movl %ecx, (%rsp)
jne 0x29f618
movl %r8d, 0x4(%rsp)
jmp 0x29f7a8
leal -0x1(%r8), %eax
movl %eax, 0x54(%rsp)
cltq
movq %rax, 0x60(%rsp)
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
movq %rax, 0x48(%rsp)
xorl %esi, %esi
movl %r8d, 0x4(%rsp)
movq 0x58(%rsp), %rcx
movl %r11d, 0x30(%rsp)
testl %r8d, %r8d
jle 0x29f670
xorl %eax, %eax
movl (%r14,%rax,4), %edx
subl %ebp, %edx
movl (%r13,%rax,4), %r10d
subl %r12d, %r10d
cmpl %r10d, %edx
cmovgl %edx, %r10d
movl %r10d, (%r14,%rax,4)
incq %rax
cmpq %rax, %r15
jne 0x29f64f
testl %r8d, %r8d
jle 0x29f6c9
movq 0x8(%rdi), %r11
xorl %eax, %eax
cmpl $0x0, 0x30(%rdi)
je 0x29f689
movl 0x18(%rdi), %edx
imull %eax, %edx
jmp 0x29f695
movq 0x38(%rsp), %rdx
movl (%rdx,%rax,4), %edx
imull 0x18(%rdi), %edx
movq 0x10(%rsp), %r10
movslq (%r10,%rsi,4), %r10
movslq %edx, %rdx
addq %r10, %rdx
movq 0x28(%rsp), %r10
movl (%r10,%rax,4), %r10d
addl (%r11,%rdx,4), %r10d
movl (%r14,%rax,4), %edx
cmpl %edx, %r10d
cmovlel %edx, %r10d
movl %r10d, 0x4(%rbx,%rax,4)
incq %rax
cmpq %rax, %r15
jne 0x29f67b
movl %esi, %r11d
imull %ebp, %r11d
addl %r12d, %r11d
negl %r11d
cmpl $0x0, 0xb8(%rsp)
movl $0x0, %eax
cmovnel %eax, %r11d
movl %r11d, (%rbx)
testl %r8d, %r8d
jle 0x29f735
movq %r9, %r8
movl $0xc0000000, %eax       # imm = 0xC0000000
movq %rsi, %r10
xorl %edx, %edx
subl %ebp, %eax
movl (%rbx,%rdx,4), %r9d
movl 0x4(%rbx,%rdx,4), %edi
cmpl %eax, %r9d
cmovgl %r9d, %eax
movl %eax, %r9d
subl %r12d, %r9d
cmpl %r9d, %edi
cmovgl %edi, %r9d
movl %r9d, (%r13,%rdx,4)
movq 0x10(%r8), %rdi
movq (%rdi), %rdi
movl %r9d, (%rdi,%r10,4)
incq %rdx
addq %rcx, %r10
cmpq %rdx, %r15
jne 0x29f6fc
movq 0x28(%rsp), %rax
movl %r11d, (%rax)
cmpl $0x0, 0xc0(%rsp)
je 0x29f77e
movq 0x60(%rsp), %rax
movl (%r13,%rax,4), %eax
movl 0x30(%rsp), %r11d
cmpl %r11d, %eax
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %r10
jle 0x29f792
movl %eax, %r11d
movl 0x54(%rsp), %eax
movl %eax, 0x4(%rsp)
movl %esi, %eax
movq %rax, 0x20(%rsp)
jmp 0x29f792
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %r10
movl 0x30(%rsp), %r11d
incq %rsi
cmpq 0x48(%rsp), %rsi
movq 0xa0(%rsp), %rdi
jne 0x29f643
testl %r8d, %r8d
jle 0x29f7ce
xorl %eax, %eax
movl (%r14,%rax,4), %edx
subl %ebp, %edx
movl (%r13,%rax,4), %esi
subl %r12d, %esi
cmpl %esi, %edx
cmovgl %edx, %esi
movl %esi, (%r14,%rax,4)
incq %rax
cmpq %rax, %r15
jne 0x29f7af
testl %r8d, %r8d
jle 0x29f834
movq 0xa0(%rsp), %rax
movq 0x8(%rax), %rsi
movl (%rsp), %edi
xorl %r8d, %r8d
movq 0xa0(%rsp), %rdx
cmpl $0x0, 0x30(%rdx)
je 0x29f7fc
movl 0x18(%rdx), %eax
imull %r8d, %eax
jmp 0x29f809
movq 0x38(%rsp), %rax
movl (%rax,%r8,4), %eax
imull 0x18(%rdx), %eax
movslq (%r10,%rdi,4), %rdx
cltq
addq %rdx, %rax
movq 0x28(%rsp), %rdx
movl (%rdx,%r8,4), %edx
addl (%rsi,%rax,4), %edx
movl (%r14,%r8,4), %eax
cmpl %eax, %edx
cmovlel %eax, %edx
movl %edx, 0x4(%rbx,%r8,4)
incq %r8
cmpq %r8, %r15
jne 0x29f7e5
movl (%rsp), %ecx
movl %ecx, %eax
imull %ebp, %eax
addl %r12d, %eax
negl %eax
xorl %edx, %edx
cmpl $0x0, 0xb8(%rsp)
cmovel %eax, %edx
movl %edx, (%rbx)
cmpl $0x0, 0x8(%rsp)
jle 0x29f8bf
movslq %ecx, %rsi
movl $0xc0000000, %edi       # imm = 0xC0000000
xorl %r8d, %r8d
movq 0x58(%rsp), %r10
subl %ebp, %edi
movl (%rbx,%r8,4), %eax
movl 0x4(%rbx,%r8,4), %edx
cmpl %edi, %eax
cmovgl %eax, %edi
movl %edi, %eax
subl %r12d, %eax
cmpl %eax, %edx
cmovgl %edx, %eax
movl %eax, (%r13,%r8,4)
movq 0x10(%r9), %rdx
movq (%rdx), %rdx
movl %eax, (%rdx,%rsi,4)
cmpl $0x0, 0xb0(%rsp)
je 0x29f8b4
movl (%r13,%r8,4), %eax
cmpl %r11d, %eax
jle 0x29f8b4
movl %eax, %r11d
movl %r8d, 0x4(%rsp)
movl (%rsp), %eax
movq %rax, 0x20(%rsp)
incq %r8
addq %r10, %rsi
cmpq %r8, %r15
jne 0x29f867
cmpl $0x0, 0xc0(%rsp)
je 0x29f8f3
movq 0x40(%rsp), %rax
movl -0x4(%r13,%rax,4), %eax
cmpl %r11d, %eax
movq 0x8(%rsp), %rdx
movq 0x20(%rsp), %rsi
movl 0x4(%rsp), %ecx
jle 0x29f901
leal -0x1(%rdx), %ecx
movl %eax, %r11d
movl (%rsp), %eax
movl %eax, %esi
jmp 0x29f901
movq 0x8(%rsp), %rdx
movq 0x20(%rsp), %rsi
movl 0x4(%rsp), %ecx
movl 0xb0(%rsp), %eax
orl %eax, 0x50(%rsp)
jne 0x29f921
decl %edx
movq 0x40(%rsp), %rax
movl -0x4(%r13,%rax,4), %r11d
movl %edx, %ecx
movl (%rsp), %eax
movl %eax, %esi
movl %r11d, (%r9)
movl %ecx, 0x4(%r9)
movl %esi, 0x8(%r9)
movq %rbx, %rdi
callq 0x2094b5
movq %r14, %rdi
callq 0x2094b5
movq 0x28(%rsp), %rdi
callq 0x2094b5
movq 0x10(%rsp), %rdi
callq 0x2094b5
movq 0xa0(%rsp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x29f968
movq 0x38(%rsp), %rdi
callq 0x2094b5
movq 0x18(%rsp), %rax
jmp 0x29f9aa
callq 0x1a08e1
jmp 0x29f9a8
callq 0x1a08bb
jmp 0x29f9a8
callq 0x1a0895
jmp 0x29f9a8
callq 0x1a086f
jmp 0x29f9a8
callq 0x1a0849
jmp 0x29f9a8
movq 0x10(%rsp), %r10
jmp 0x29f4dd
callq 0x1a0823
jmp 0x29f9a8
callq 0x1a07fd
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq