// File: /workspace/github_c_makefile_star2_O3/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 $0x78, %rsp
testq %rdx, %rdx
je 0x2a0845
movl %ecx, %r14d
testl %ecx, %ecx
jle 0x2a084c
movl %r8d, %r12d
testl %r8d, %r8d
js 0x2a0853
movl %r9d, %r15d
testl %r9d, %r9d
js 0x2a085a
movq 0xb0(%rsp), %r13
testq %r13, %r13
je 0x2a0861
movq %rdi, %rbp
cmpl $0x0, 0x30(%r13)
je 0x2a02ff
movl 0x34(%r13), %esi
jmp 0x2a0310
testq %rbp, %rbp
je 0x2a0872
testl %esi, %esi
jle 0x2a0879
movq %rdx, 0x10(%rsp)
movl %esi, 0x8(%rsp)
movl %esi, %edi
movl %r14d, %esi
callq 0x20abc2
testq %rax, %rax
je 0x2a087e
movq %rax, %rbx
movq %rbp, 0x18(%rsp)
movl 0xd0(%rsp), %edi
xorl %eax, %eax
cmpl $0x0, 0xb8(%rsp)
setne %al
xorl %ecx, %ecx
cmpl $0x0, 0xc0(%rsp)
setne %cl
shll $0x4, %ecx
xorl %edx, %edx
cmpl $0x0, 0xc8(%rsp)
setne %dl
shll $0xe, %edx
xorl %esi, %esi
movl %edi, 0x50(%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, 0x28(%rsp)
callq 0x20a617
movq %rax, 0x20(%rsp)
movq %r14, 0x30(%rsp)
leal 0x1(%r14), %ebp
movl $0x10, %edi
movq %rbp, %rsi
callq 0x20a617
movq %rax, %r14
movl $0x10, %edi
movq %rbp, 0x48(%rsp)
movq %rbp, %rsi
callq 0x20a617
movq 0x20(%rsp), %rsi
movq %rax, %rbp
testq %rsi, %rsi
sete %al
testq %r14, %r14
sete %cl
orb %al, %cl
testq %rbp, %rbp
sete %al
orb %cl, %al
jne 0x2a087e
cmpl $0x0, 0x30(%r13)
je 0x2a0463
xorl %r8d, %r8d
movl 0x8(%rsp), %edi
movq 0x48(%rsp), %r9
movq 0x28(%rsp), %r10
movq 0x10(%rsp), %r11
movq 0x10(%r13), %rax
xorl %ecx, %ecx
movzbl (%r11,%rcx), %edx
movl (%rax,%rdx,4), %edx
movl %edx, (%rsi,%rcx,4)
incq %rcx
cmpq %rcx, %r10
jne 0x2a0412
movl $0x0, (%r14)
movl $0xc0000000, (%rbp)     # imm = 0xC0000000
cmpl $0x0, 0xc8(%rsp)
je 0x2a04c7
movl $0x1, %eax
movl $0x0, (%r14,%rax,4)
movl $0xc0000000, (%rbp,%rax,4) # imm = 0xC0000000
incq %rax
cmpq %rax, %r9
jne 0x2a0446
jmp 0x2a04e8
movslq 0x8(%rsp), %rsi
movl $0x10, %edi
callq 0x20a617
testq %rax, %rax
je 0x2a087e
movq %rax, %r8
movl 0x8(%rsp), %edi
testl %edi, %edi
movq 0x48(%rsp), %r9
movq 0x28(%rsp), %r10
movq 0x10(%rsp), %r11
jle 0x2a0868
movq 0x10(%r13), %rax
movl %edi, %ecx
xorl %edx, %edx
movq 0x18(%rsp), %rdi
movzbl (%rdi,%rdx), %esi
movl (%rax,%rsi,4), %esi
movl %esi, (%r8,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x2a04a6
movq 0x20(%rsp), %rsi
movl 0x8(%rsp), %edi
jmp 0x2a040c
movl %r12d, %eax
negl %eax
movl $0x1, %ecx
movl %eax, (%r14,%rcx,4)
movl $0xc0000000, (%rbp,%rcx,4) # imm = 0xC0000000
incq %rcx
subl %r15d, %eax
cmpq %rcx, %r9
jne 0x2a04d1
cmpl $0x2, %edi
movq %r8, 0x38(%rsp)
jl 0x2a0676
movq 0x30(%rsp), %rax
leal -0x1(%rax), %ecx
movl %ecx, 0x54(%rsp)
movl %edi, %ecx
movq %rcx, 0x68(%rsp)
movq 0x8(%r13), %rcx
movq %rcx, 0x60(%rsp)
leaq (,%r10,4), %rcx
movq %rcx, 0x58(%rsp)
leaq -0x1(%r9), %r10
movl $0xc0000000, 0x10(%rsp) # imm = 0xC0000000
movl $0x1, %r8d
xorl %esi, %esi
movl %edi, 0xc(%rsp)
movl %eax, 0x18(%rsp)
leaq -0x1(%r8), %rax
cmpl $0x0, 0x30(%r13)
movslq 0x18(%r13), %rcx
movq %rax, 0x70(%rsp)
je 0x2a0558
imulq %rax, %rcx
movq %rcx, %rax
jmp 0x2a0566
movq 0x38(%rsp), %rax
movslq -0x4(%rax,%r8,4), %rax
imulq %rcx, %rax
movl $0x1, %edx
movq %r8, 0x40(%rsp)
subl %r8d, %edx
imull %r15d, %edx
subl %r12d, %edx
cmpl $0x0, 0xb8(%rsp)
movq 0x60(%rsp), %rcx
leaq (%rcx,%rax,4), %r9
movl $0x0, %eax
cmovnel %eax, %edx
movl (%r14), %ecx
movl %edx, (%r14)
movl $0xc0000000, %r11d      # imm = 0xC0000000
xorl %edi, %edi
movq %rbx, %r13
movl 0x4(%r14,%rdi,4), %eax
movl %eax, %ebx
subl %r12d, %ebx
movl 0x4(%rbp,%rdi,4), %r8d
subl %r15d, %r8d
cmpl %r8d, %ebx
cmovgl %ebx, %r8d
movl %r8d, 0x4(%rbp,%rdi,4)
subl %r12d, %edx
movl %r11d, %ebx
subl %r15d, %ebx
movl %edx, %r11d
cmpl %ebx, %edx
jg 0x2a05d5
movl %ebx, %r11d
movq 0x20(%rsp), %rdx
movslq (%rdx,%rdi,4), %rdx
addl (%r9,%rdx,4), %ecx
cmpl %r11d, %ecx
cmovlel %r11d, %ecx
movl %ecx, %edx
cmpl %r8d, %ecx
jg 0x2a05f3
movl %r8d, %edx
movl %edx, 0x4(%r14,%rdi,4)
movq %r13, %rbx
movq 0x10(%r13), %rcx
movq (%rcx), %rcx
addq %rsi, %rcx
movl %edx, (%rcx,%rdi,4)
incq %rdi
movl %eax, %ecx
cmpq %rdi, %r10
jne 0x2a05a1
cmpl $0x0, 0xc0(%rsp)
setne %al
movl 0x10(%rsp), %edi
cmpl %edi, %edx
setg %cl
testb %cl, %al
movl 0x18(%rsp), %eax
cmovnel 0x54(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0xc(%rsp), %eax
cmovnel 0x70(%rsp), %eax
movl %eax, 0xc(%rsp)
cmovnel %edx, %edi
movl %edi, 0x10(%rsp)
movq 0x40(%rsp), %r8
incq %r8
addq 0x58(%rsp), %rsi
cmpq 0x68(%rsp), %r8
movq 0xb0(%rsp), %r13
jne 0x2a053b
movl 0x8(%rsp), %eax
movl %eax, %ecx
movq 0x38(%rsp), %r8
jmp 0x2a0690
movl $0x1, %ecx
movl $0xc0000000, 0x10(%rsp) # imm = 0xC0000000
movq 0x30(%rsp), %rax
movl %eax, 0x18(%rsp)
movl %edi, 0xc(%rsp)
leal -0x1(%rcx), %eax
cmpl $0x0, 0x30(%r13)
movq 0x8(%r13), %rdx
movl 0x18(%r13), %esi
je 0x2a06a7
imull %eax, %esi
jmp 0x2a06af
movslq %eax, %rdi
imull (%r8,%rdi,4), %esi
cmpl $0x0, 0xd0(%rsp)
setne %r10b
cmpl $0x0, 0xc0(%rsp)
setne %r8b
movl $0x1, %r11d
subl %ecx, %r11d
imull %r15d, %r11d
subl %r12d, %r11d
xorl %edi, %edi
cmpl $0x0, 0xb8(%rsp)
movslq %esi, %rcx
leaq (%rdx,%rcx,4), %rcx
movq %rcx, 0x40(%rsp)
movl (%r14), %r9d
cmovel %r11d, %edi
movl %edi, (%r14)
andb %r10b, %r8b
decl 0x8(%rsp)
movslq %eax, %r10
imulq 0x28(%rsp), %r10
shlq $0x2, %r10
movl $0xc0000000, %esi       # imm = 0xC0000000
movl $0x1, %r11d
movl %r9d, %eax
movl (%r14,%r11,4), %r9d
movl %r9d, %edx
subl %r12d, %edx
movl (%rbp,%r11,4), %ecx
subl %r15d, %ecx
cmpl %ecx, %edx
cmovgl %edx, %ecx
movl %ecx, (%rbp,%r11,4)
subl %r12d, %edi
movl %esi, %edx
subl %r15d, %edx
movl %edi, %esi
cmpl %edx, %edi
jg 0x2a0745
movl %edx, %esi
movq 0x20(%rsp), %rdx
movslq -0x4(%rdx,%r11,4), %rdx
movq 0x40(%rsp), %rdi
addl (%rdi,%rdx,4), %eax
cmpl %esi, %eax
cmovlel %esi, %eax
movl %eax, %edi
cmpl %ecx, %eax
jg 0x2a0764
movl %ecx, %edi
movl %edi, (%r14,%r11,4)
leaq -0x1(%r11), %rax
testb %r8b, %r8b
je 0x2a0797
cmpl 0x10(%rsp), %edi
jg 0x2a07a7
setne %cl
movslq 0x18(%rsp), %rdx
cmpq %rdx, %r11
setg %dl
orb %cl, %dl
jne 0x2a07b7
movl %eax, 0x18(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0xc(%rsp)
jmp 0x2a07b7
cmpl $0x0, 0xd0(%rsp)
je 0x2a07b7
cmpl 0x10(%rsp), %edi
jle 0x2a07b7
movl %eax, 0x18(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0xc(%rsp)
movl %edi, 0x10(%rsp)
movq 0x10(%rbx), %rax
movq (%rax), %rax
addq %r10, %rax
movl %edi, -0x4(%rax,%r11,4)
incq %r11
cmpq %r11, 0x48(%rsp)
jne 0x2a0716
movl 0xc0(%rsp), %edx
testl %edx, %edx
setne %al
movl 0x10(%rsp), %esi
cmpl %esi, %edi
setg %cl
andb %al, %cl
orl %edx, 0x50(%rsp)
sete %al
orb %cl, %al
movq 0x30(%rsp), %rcx
decl %ecx
testb %al, %al
movl 0x18(%rsp), %eax
cmovnel %ecx, %eax
movl 0xc(%rsp), %ecx
cmovnel 0x8(%rsp), %ecx
cmovnel %edi, %esi
movl %esi, (%rbx)
movl %ecx, 0x4(%rbx)
movl %eax, 0x8(%rbx)
movq %rbp, %rdi
callq 0x20a60d
movq %r14, %rdi
callq 0x20a60d
movq 0x20(%rsp), %rdi
callq 0x20a60d
cmpl $0x0, 0x30(%r13)
jne 0x2a0880
movq 0x38(%rsp), %rdi
callq 0x20a60d
jmp 0x2a0880
callq 0x1a05b7
jmp 0x2a087e
callq 0x1a0591
jmp 0x2a087e
callq 0x1a056b
jmp 0x2a087e
callq 0x1a0545
jmp 0x2a087e
callq 0x1a051f
jmp 0x2a087e
movq 0x20(%rsp), %rsi
jmp 0x2a040c
callq 0x1a04f9
jmp 0x2a087e
callq 0x1a04d3
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq