// File: /workspace/github_c_makefile_star2_O1/nh13[P]ksw/src/parasail/src/sg.c
// Function: parasail_sg_flags_table
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 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_SG | PARASAIL_FLAG_NOVEC
        | 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);
    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 */
    if (s2_beg) {
        for (j=1; j<=s2Len; ++j) {
            H[j] = 0;
            F[j] = NEG_INF_32;
        }
    }
    else {
        for (j=1; j<=s2Len; ++j) {
            H[j] = -open -(j-1)*gap;
            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 = s1_beg ? 0 : (-open - (i-1)*gap);
        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, E);
            WH = MAX(WH, F[j]);
            H[j] = 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
        if (s1_end && WH > score) {
            score = WH;
            end_query = i-1;
            end_ref = s2Len-1;
        }
    }
    {
        /* i == s1Len */
        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 = s1_beg ? 0 : -open - (i-1)*gap;
        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, E);
            WH = MAX(WH, F[j]);
            H[j] = WH;
            if (s1_end && s2_end) {
                if (WH > score) {
                    score = WH;
                    end_query = s1Len-1;
                    end_ref = j-1;
                }
                else if (WH == score && j-1 < end_ref) {
                    end_query = s1Len-1;
                    end_ref = j-1;
                }
            }
            else if (s2_end) {
                if (WH > score) {
                    score = WH;
                    end_query = s1Len-1;
                    end_ref = j-1;
                }
            }
#ifdef PARASAIL_TABLE
            result->tables->score_table[1LL*(i-1)*s2Len + (j-1)] = WH;
#endif
#ifdef PARASAIL_ROWCOL
            result->rowcols->score_row[j-1] = H[j];
#endif
        }
        if ((s1_end && WH > score) || (!s1_end && !s2_end)) {
            score = WH;
            end_query = s1Len-1;
            end_ref = s2Len-1;
        }
#ifdef PARASAIL_ROWCOL
        result->rowcols->score_col[i-1] = WH;
#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 $0x68, %rsp
testq %rdx, %rdx
je 0x29e9f9
movl %ecx, %r14d
testl %ecx, %ecx
jle 0x29ea00
movl %r8d, %r12d
testl %r8d, %r8d
js 0x29ea07
movl %r9d, %ebp
testl %r9d, %r9d
js 0x29ea0e
movq 0xa0(%rsp), %rcx
testq %rcx, %rcx
je 0x29ea15
movl 0x30(%rcx), %eax
testl %eax, %eax
jne 0x29e49f
testq %rdi, %rdi
je 0x29ea26
testl %esi, %esi
jle 0x29ea2d
testl %eax, %eax
je 0x29e4a2
movl 0x34(%rcx), %esi
movq %rdi, 0x8(%rsp)
movq %rdx, (%rsp)
movq %rsi, 0x30(%rsp)
movl %esi, %edi
movl %r14d, %esi
callq 0x20959f
testq %rax, %rax
je 0x29ea32
movq %rax, %rbx
movl 0xc0(%rsp), %edi
xorl %eax, %eax
cmpl $0x0, 0xa8(%rsp)
setne %al
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 %edi, 0x54(%rsp)
testl %edi, %edi
setne %sil
shll $0xf, %esi
leal (%rcx,%rax,8), %eax
orl %edx, %eax
orl %esi, %eax
orl 0xc(%rbx), %eax
orl $0x1420102, %eax        # imm = 0x1420102
movl %eax, 0xc(%rbx)
movl %r14d, %esi
movl $0x10, %edi
movq %rsi, 0x58(%rsp)
callq 0x2094bf
movq %rax, %r13
movq %r14, 0x18(%rsp)
incl %r14d
movl $0x10, %edi
movq %r14, %rsi
callq 0x2094bf
movq %rax, %r15
movl $0x10, %edi
movq %r14, %rsi
callq 0x2094bf
movq %rax, %r14
testq %r13, %r13
sete %al
testq %r15, %r15
sete %cl
orb %al, %cl
testq %r14, %r14
sete %al
orb %cl, %al
jne 0x29ea32
movq 0xa0(%rsp), %r9
cmpl $0x0, 0x30(%r9)
movq %r13, 0x28(%rsp)
je 0x29e5f4
xorl %eax, %eax
movq 0x30(%rsp), %r11
movq (%rsp), %r8
movq 0x10(%r9), %rcx
movq 0x18(%rsp), %rdx
cmpl $0x2, %edx
movl $0x1, %edi
cmovgel %edx, %edi
xorl %edx, %edx
movzbl (%r8,%rdx), %esi
movl (%rcx,%rsi,4), %esi
movl %esi, (%r13,%rdx,4)
incq %rdx
cmpq %rdx, %rdi
jne 0x29e5a9
movl $0x0, (%r15)
movl $0xc0000000, (%r14)     # imm = 0xC0000000
cmpl $0x0, 0xb8(%rsp)
je 0x29e652
xorl %ecx, %ecx
movl $0x0, 0x4(%r15,%rcx,4)
movl $0xc0000000, 0x4(%r14,%rcx,4) # imm = 0xC0000000
incq %rcx
cmpq %rcx, %rdi
jne 0x29e5d8
jmp 0x29e671
movq 0x30(%rsp), %r13
movslq %r13d, %rsi
movl $0x10, %edi
callq 0x2094bf
testq %rax, %rax
je 0x29ea32
testl %r13d, %r13d
movq %r13, %r11
movq (%rsp), %r8
movq 0xa0(%rsp), %r9
jle 0x29ea1c
movq 0x10(%r9), %rdi
movl %r11d, %ecx
xorl %edx, %edx
movq 0x28(%rsp), %r13
movq 0x8(%rsp), %r10
movzbl (%r10,%rdx), %esi
movl (%rdi,%rsi,4), %esi
movl %esi, (%rax,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x29e63a
jmp 0x29e593
movl %r12d, %ecx
negl %ecx
xorl %edx, %edx
movl %ecx, 0x4(%r15,%rdx,4)
movl $0xc0000000, 0x4(%r14,%rdx,4) # imm = 0xC0000000
subl %ebp, %ecx
incq %rdx
cmpq %rdx, %rdi
jne 0x29e659
cmpl $0x2, %r11d
movq %rax, 0x38(%rsp)
jl 0x29e7f8
movq 0x18(%rsp), %rcx
leal -0x1(%rcx), %eax
movl %eax, 0x40(%rsp)
cmpl $0x2, %ecx
movl $0x1, %r8d
cmovgel %ecx, %r8d
movl %r11d, %eax
movq %rax, 0x20(%rsp)
movq 0x58(%rsp), %rax
leaq (,%rax,4), %rax
movq %rax, 0x60(%rsp)
movl $0xc0000000, 0x14(%rsp) # imm = 0xC0000000
movl $0x1, %r10d
movq %r11, %rax
xorl %r11d, %r11d
movl %eax, 0x8(%rsp)
movl %ecx, (%rsp)
movq %rbx, %r13
cmpl $0x0, 0x30(%r9)
je 0x29e6e2
leaq -0x1(%r10), %rax
movslq 0x18(%r9), %rdi
jmp 0x29e6f0
movslq 0x18(%r9), %rax
movq 0x38(%rsp), %rcx
movslq -0x4(%rcx,%r10,4), %rdi
imulq %rax, %rdi
shlq $0x2, %rdi
addq 0x8(%r9), %rdi
movl $0x1, %edx
movq %r10, 0x48(%rsp)
subl %r10d, %edx
imull %ebp, %edx
subl %r12d, %edx
cmpl $0x0, 0xa8(%rsp)
movl $0x0, %eax
cmovnel %eax, %edx
movl (%r15), %ecx
movl %edx, (%r15)
movl $0xc0000000, %ebx       # imm = 0xC0000000
xorl %r10d, %r10d
movl 0x4(%r15,%r10,4), %eax
movl %eax, %esi
subl %r12d, %esi
movl 0x4(%r14,%r10,4), %r9d
subl %ebp, %r9d
cmpl %r9d, %esi
cmovgl %esi, %r9d
movl %r9d, 0x4(%r14,%r10,4)
subl %r12d, %edx
movl %ebx, %esi
subl %ebp, %esi
movl %edx, %ebx
cmpl %esi, %edx
jg 0x29e75a
movl %esi, %ebx
movq 0x28(%rsp), %rdx
movslq (%rdx,%r10,4), %rdx
addl (%rdi,%rdx,4), %ecx
cmpl %ebx, %ecx
cmovlel %ebx, %ecx
movl %ecx, %edx
cmpl %r9d, %ecx
jg 0x29e775
movl %r9d, %edx
movl %edx, 0x4(%r15,%r10,4)
movq 0x10(%r13), %rcx
movq (%rcx), %rcx
addq %r11, %rcx
movl %edx, (%rcx,%r10,4)
incq %r10
movl %eax, %ecx
cmpq %r10, %r8
jne 0x29e72d
cmpl $0x0, 0xb0(%rsp)
setne %al
movl 0x14(%rsp), %edi
cmpl %edi, %edx
setg %cl
movq 0x48(%rsp), %r10
leal -0x1(%r10), %esi
testb %cl, %al
movl (%rsp), %eax
cmovnel 0x40(%rsp), %eax
movl %eax, (%rsp)
movl 0x8(%rsp), %eax
cmovnel %esi, %eax
movl %eax, 0x8(%rsp)
cmovnel %edx, %edi
movl %edi, 0x14(%rsp)
incq %r10
addq 0x60(%rsp), %r11
cmpq 0x20(%rsp), %r10
movq 0xa0(%rsp), %r9
jne 0x29e6d1
movq %r13, %rbx
movq 0x30(%rsp), %r11
movq 0x38(%rsp), %rax
jmp 0x29e813
movl $0x1, %r10d
movl $0xc0000000, 0x14(%rsp) # imm = 0xC0000000
movq 0x18(%rsp), %rcx
movl %ecx, (%rsp)
movl %r11d, 0x8(%rsp)
leal -0x1(%r10), %r13d
cmpl $0x0, 0x30(%r9)
movq 0x8(%r9), %rcx
movl 0x18(%r9), %edx
je 0x29e82c
imull %r13d, %edx
jmp 0x29e833
movslq %r13d, %rsi
imull (%rax,%rsi,4), %edx
cmpl $0x0, 0xc0(%rsp)
setne %dil
cmpl $0x0, 0xb0(%rsp)
setne %al
movl $0x1, %r9d
subl %r10d, %r9d
imull %ebp, %r9d
subl %r12d, %r9d
xorl %esi, %esi
cmpl $0x0, 0xa8(%rsp)
movl $0x1, %r8d
movslq %edx, %rdx
leaq (%rcx,%rdx,4), %rcx
movq %rcx, 0x40(%rsp)
movl (%r15), %r10d
cmovel %r9d, %esi
movl %esi, (%r15)
andb %dil, %al
movb %al, 0x48(%rsp)
leal -0x1(%r11), %eax
movl %eax, 0x20(%rsp)
movslq %r13d, %r11
movq 0x18(%rsp), %rax
cmpl $0x2, %eax
cmovgel %eax, %r8d
imulq 0x58(%rsp), %r11
shlq $0x2, %r11
negq %r8
movl $0xc0000000, %r9d       # imm = 0xC0000000
movl $0x1, %edi
movl 0x14(%rsp), %r13d
movl %r10d, %eax
movl (%r15,%rdi,4), %r10d
movl %r10d, %edx
subl %r12d, %edx
movl (%r14,%rdi,4), %ecx
subl %ebp, %ecx
cmpl %ecx, %edx
cmovgl %edx, %ecx
movl %ecx, (%r14,%rdi,4)
subl %r12d, %esi
movl %r9d, %edx
subl %ebp, %edx
movl %esi, %r9d
cmpl %edx, %esi
jg 0x29e8e9
movl %edx, %r9d
movq 0x28(%rsp), %rdx
movslq -0x4(%rdx,%rdi,4), %rdx
movq 0x40(%rsp), %rsi
addl (%rsi,%rdx,4), %eax
cmpl %r9d, %eax
cmovlel %r9d, %eax
movl %eax, %esi
cmpl %ecx, %eax
jg 0x29e90a
movl %ecx, %esi
movl %esi, (%r15,%rdi,4)
leaq -0x1(%rdi), %rax
cmpb $0x0, 0x48(%rsp)
je 0x29e93f
cmpl %r13d, %esi
jg 0x29e94e
setne %al
movslq (%rsp), %rcx
cmpq %rcx, %rdi
setg %cl
orb %al, %cl
jne 0x29e95c
leal -0x1(%rdi), %eax
movl %eax, (%rsp)
movl 0x20(%rsp), %eax
movl %eax, 0x8(%rsp)
jmp 0x29e95c
cmpl $0x0, 0xc0(%rsp)
je 0x29e95c
cmpl %r13d, %esi
jle 0x29e95c
movl %eax, (%rsp)
movl 0x20(%rsp), %eax
movl %eax, 0x8(%rsp)
movl %esi, %r13d
movq 0x10(%rbx), %rax
movq (%rax), %rax
addq %r11, %rax
movl %esi, -0x4(%rax,%rdi,4)
leaq (%r8,%rdi), %rax
incq %rax
incq %rdi
cmpq $0x1, %rax
jne 0x29e8bb
movl 0xb0(%rsp), %edx
testl %edx, %edx
setne %al
cmpl %r13d, %esi
setg %cl
andb %al, %cl
orl %edx, 0x54(%rsp)
sete %al
orb %cl, %al
movq 0x30(%rsp), %rcx
decl %ecx
movq 0x18(%rsp), %rdx
decl %edx
testb %al, %al
movl (%rsp), %eax
cmovnel %edx, %eax
movl 0x8(%rsp), %edx
cmovnel %ecx, %edx
cmovnel %esi, %r13d
movl %r13d, (%rbx)
movl %edx, 0x4(%rbx)
movl %eax, 0x8(%rbx)
movq %r14, %rdi
callq 0x2094b5
movq %r15, %rdi
callq 0x2094b5
movq 0x28(%rsp), %rdi
callq 0x2094b5
movq 0xa0(%rsp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x29ea34
movq 0x38(%rsp), %rdi
callq 0x2094b5
jmp 0x29ea34
callq 0x1a05c3
jmp 0x29ea32
callq 0x1a059d
jmp 0x29ea32
callq 0x1a0577
jmp 0x29ea32
callq 0x1a0551
jmp 0x29ea32
callq 0x1a052b
jmp 0x29ea32
movq 0x28(%rsp), %r13
jmp 0x29e593
callq 0x1a0505
jmp 0x29ea32
callq 0x1a04df
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq