// File: /workspace/github_c_makefile_star2_O2/nh13[P]ksw/src/parasail/src/sg.c
// Function: parasail_sg_flags_rowcol
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 $0x58, %rsp
testq %rdx, %rdx
je 0x247adf
movl %ecx, %ebp
testl %ecx, %ecx
jle 0x247b03
movl %r8d, %r12d
testl %r8d, %r8d
js 0x247b27
movl %r9d, %r15d
testl %r9d, %r9d
js 0x247ef2
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0x247f13
cmpl $0x0, 0x30(%rax)
je 0x24796d
movl 0x34(%rax), %ebx
jmp 0x247980
testq %rdi, %rdi
je 0x247f34
movl %esi, %ebx
testl %esi, %esi
jle 0x247f55
movq %rdi, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movl %ebx, %edi
movl %ebp, %esi
callq 0x1ab93b
testq %rax, %rax
je 0x247f7b
movl %ebx, 0x4(%rsp)
movl 0xb0(%rsp), %r9d
xorl %r8d, %r8d
cmpl $0x0, 0x98(%rsp)
setne %r8b
movq %rax, %rdi
xorl %ecx, %ecx
cmpl $0x0, 0xa0(%rsp)
setne %cl
shll $0x4, %ecx
xorl %edx, %edx
cmpl $0x0, 0xa8(%rsp)
setne %dl
shll $0xe, %edx
xorl %esi, %esi
movl %r9d, 0x44(%rsp)
testl %r9d, %r9d
setne %sil
shll $0xf, %esi
leal (%rcx,%r8,8), %eax
orl %edx, %eax
orl %esi, %eax
orl 0xc(%rdi), %eax
orl $0x1440102, %eax        # imm = 0x1440102
movq %rdi, 0x28(%rsp)
movl %eax, 0xc(%rdi)
movl %ebp, %r14d
pushq $0x10
popq %rdi
movq %r14, %rsi
callq 0x1ab76d
movq %rax, %r13
movq %rbp, 0x18(%rsp)
leal 0x1(%rbp), %ebx
pushq $0x10
popq %rdi
movq %rbx, %rsi
callq 0x1ab76d
movq %rax, %rbp
pushq $0x10
popq %rdi
movq %rbx, 0x38(%rsp)
movq %rbx, %rsi
callq 0x1ab76d
movq %rax, %rbx
testq %r13, %r13
sete %al
testq %rbp, %rbp
sete %cl
orb %al, %cl
testq %rbx, %rbx
sete %al
orb %cl, %al
jne 0x247f7b
movq 0x90(%rsp), %r9
cmpl $0x0, 0x30(%r9)
movslq 0x4(%rsp), %rsi
movq %rsi, 0x48(%rsp)
je 0x247a85
movq $0x0, 0x20(%rsp)
movq 0x8(%rsp), %r8
jmp 0x247b50
pushq $0x10
popq %rdi
callq 0x1ab76d
xorl %edi, %edi
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x247f7b
movl 0x4(%rsp), %edx
testl %edx, %edx
movl $0x0, %ecx
cmovgl %edx, %ecx
movq 0x90(%rsp), %r9
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %r10
movq 0x20(%rsp), %rax
cmpq %rdi, %rcx
je 0x247b4b
movq 0x10(%r9), %rdx
movzbl (%r10,%rdi), %esi
movl (%rdx,%rsi,4), %edx
movl %edx, (%rax,%rdi,4)
incq %rdi
jmp 0x247ac2
movq 0x4f34f2(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37f4fb(%rip), %rsi    # 0x5c6feb
leaq 0x37fd5d(%rip), %rdx    # 0x5c7854
leaq 0x37fbff(%rip), %rcx    # 0x5c76fd
jmp 0x247f74
movq 0x4f34ce(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37fbed(%rip), %rsi    # 0x5c7701
leaq 0x37fd39(%rip), %rdx    # 0x5c7854
leaq 0x37fbf3(%rip), %rcx    # 0x5c7715
jmp 0x247f74
movq 0x4f34aa(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37fbe3(%rip), %rsi    # 0x5c771b
leaq 0x37fd15(%rip), %rdx    # 0x5c7854
leaq 0x37fbea(%rip), %rcx    # 0x5c7730
jmp 0x247f74
movq 0x48(%rsp), %rsi
movq 0x10(%r9), %rax
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x247b6d
movzbl (%r8,%rcx), %edx
movl (%rax,%rdx,4), %edx
movl %edx, (%r13,%rcx,4)
incq %rcx
jmp 0x247b56
andl $0x0, (%rbp)
movl $0xc0000000, (%rbx)     # imm = 0xC0000000
cmpl $0x0, 0xa8(%rsp)
je 0x247b9c
pushq $0x1
popq %rax
cmpq %rax, 0x38(%rsp)
je 0x247bbe
andl $0x0, (%rbp,%rax,4)
movl $0xc0000000, (%rbx,%rax,4) # imm = 0xC0000000
incq %rax
jmp 0x247b84
movl %r12d, %eax
negl %eax
pushq $0x1
popq %rcx
cmpq %rcx, 0x38(%rsp)
je 0x247bbe
movl %eax, (%rbp,%rcx,4)
movl $0xc0000000, (%rbx,%rcx,4) # imm = 0xC0000000
incq %rcx
subl %r15d, %eax
jmp 0x247ba4
movq 0x18(%rsp), %rax
decl %eax
movl %eax, 0x34(%rsp)
movq 0x38(%rsp), %rax
leaq -0x1(%rax), %r8
movl $0xc0000000, 0x8(%rsp)  # imm = 0xC0000000
pushq $0x1
popq %r11
movl 0x4(%rsp), %eax
movl %eax, 0x10(%rsp)
cmpq %rsi, %r11
movq %r11, 0x50(%rsp)
jge 0x247d0b
leaq -0x1(%r11), %r10
cmpl $0x0, 0x30(%r9)
movslq 0x18(%r9), %rcx
je 0x247c0c
imulq %r10, %rcx
movq %rcx, %rax
jmp 0x247c1a
movq 0x20(%rsp), %rax
movslq -0x4(%rax,%r11,4), %rax
imulq %rcx, %rax
movq 0x8(%r9), %rcx
pushq $0x1
popq %rdi
subl %r11d, %edi
imull %r15d, %edi
subl %r12d, %edi
cmpl $0x0, 0x98(%rsp)
leaq (%rcx,%rax,4), %r14
movl $0x0, %eax
cmovnel %eax, %edi
movl (%rbp), %r9d
movl %edi, (%rbp)
movl $0xc0000000, %eax       # imm = 0xC0000000
xorl %edx, %edx
cmpq %rdx, %r8
je 0x247ca7
movl 0x4(%rbp,%rdx,4), %ecx
movl %ecx, %esi
subl %r12d, %esi
movl 0x4(%rbx,%rdx,4), %r11d
subl %r15d, %r11d
cmpl %r11d, %esi
cmovgl %esi, %r11d
movl %r11d, 0x4(%rbx,%rdx,4)
subl %r12d, %edi
subl %r15d, %eax
movl %edi, %esi
cmpl %eax, %edi
jg 0x247c7d
movl %eax, %esi
movslq (%r13,%rdx,4), %rax
addl (%r14,%rax,4), %r9d
cmpl %esi, %r9d
cmovlel %esi, %r9d
cmpl %r11d, %r9d
jg 0x247c95
movl %r11d, %r9d
movl %r9d, %edi
movl %r9d, 0x4(%rbp,%rdx,4)
incq %rdx
movl %ecx, %r9d
movl %esi, %eax
jmp 0x247c4d
cmpl $0x0, 0xa0(%rsp)
setne %al
movl 0x8(%rsp), %edx
cmpl %edx, %edi
setg %cl
testb %cl, %al
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq 0x18(%rsp), %rcx
cmovnel 0x34(%rsp), %ecx
movq %rcx, 0x18(%rsp)
movl 0x10(%rsp), %ecx
cmovnel %r10d, %ecx
movl %ecx, 0x10(%rsp)
movq 0x50(%rsp), %r11
movl %edi, -0x4(%rax,%r11,4)
cmovnel %edi, %edx
movl %edx, 0x8(%rsp)
incq %r11
movq 0x90(%rsp), %r9
movq 0x48(%rsp), %rsi
jmp 0x247be6
cmpl $0x0, 0x30(%r9)
movq 0x8(%r9), %rdi
movl 0x18(%r9), %esi
je 0x247d23
leal -0x1(%r11), %eax
imull %eax, %esi
jmp 0x247d44
movq %r11, %rax
shlq $0x20, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rax, %rcx
sarq $0x1e, %rcx
movq 0x20(%rsp), %rax
imull (%rax,%rcx), %esi
cmpl $0x0, 0xb0(%rsp)
setne %al
cmpl $0x0, 0xa0(%rsp)
setne %dl
pushq $0x1
popq %r9
subl %r11d, %r9d
imull %r15d, %r9d
subl %r12d, %r9d
xorl %r8d, %r8d
cmpl $0x0, 0x98(%rsp)
movslq %esi, %rcx
leaq (%rdi,%rcx,4), %r10
movl (%rbp), %r11d
cmovel %r9d, %r8d
movl %r8d, (%rbp)
andb %al, %dl
decl 0x4(%rsp)
movl $0xc0000000, %r14d      # imm = 0xC0000000
pushq $0x1
popq %rdi
movq 0x28(%rsp), %rcx
cmpq %rdi, 0x38(%rsp)
je 0x247e61
movl %r11d, %r9d
movl (%rbp,%rdi,4), %r11d
movl %r11d, %eax
subl %r12d, %eax
movl (%rbx,%rdi,4), %esi
subl %r15d, %esi
cmpl %esi, %eax
cmovgl %eax, %esi
movl %esi, (%rbx,%rdi,4)
subl %r12d, %r8d
movl %r14d, %eax
subl %r15d, %eax
movl %r8d, %r14d
cmpl %eax, %r8d
jg 0x247dd5
movl %eax, %r14d
movslq -0x4(%r13,%rdi,4), %rax
addl (%r10,%rax,4), %r9d
cmpl %r14d, %r9d
cmovlel %r14d, %r9d
movl %r9d, %r8d
cmpl %esi, %r9d
jg 0x247df0
movl %esi, %r8d
movl %r8d, (%rbp,%rdi,4)
leaq -0x1(%rdi), %rsi
testb %dl, %dl
je 0x247e2a
cmpl 0x8(%rsp), %r8d
jg 0x247e3b
setne %al
movslq 0x18(%rsp), %rcx
cmpq %rcx, %rdi
setg %cl
orb %al, %cl
jne 0x247e23
movq %rsi, 0x18(%rsp)
movl 0x4(%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0x28(%rsp), %rcx
jmp 0x247e4d
cmpl $0x0, 0xb0(%rsp)
je 0x247e4d
cmpl 0x8(%rsp), %r8d
jle 0x247e4d
movq %rsi, 0x18(%rsp)
movl 0x4(%rsp), %eax
movl %eax, 0x10(%rsp)
movl %r8d, 0x8(%rsp)
movq 0x10(%rcx), %rax
movq (%rax), %rax
movl %r8d, -0x4(%rax,%rdi,4)
incq %rdi
jmp 0x247d9a
movl 0xa0(%rsp), %esi
testl %esi, %esi
setne %al
movl 0x8(%rsp), %edi
cmpl %edi, %r8d
movq %rcx, %rdx
setg %cl
andb %al, %cl
orl %esi, 0x44(%rsp)
sete %al
orb %cl, %al
movq 0x18(%rsp), %rsi
cmovnel 0x34(%rsp), %esi
movl 0x10(%rsp), %r9d
cmovnel 0x4(%rsp), %r9d
cmovnel %r8d, %edi
movq 0x10(%rdx), %rax
movq 0x8(%rax), %rax
movl 0x50(%rsp), %ecx
movl %r8d, -0x4(%rax,%rcx,4)
movl %edi, (%rdx)
movl %r9d, 0x4(%rdx)
movl %esi, 0x8(%rdx)
movq %rbx, %rdi
callq 0x1ab763
movq %rbp, %rdi
callq 0x1ab763
movq %r13, %rdi
callq 0x1ab763
movq 0x90(%rsp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x247ee8
movq 0x20(%rsp), %rdi
callq 0x1ab763
movq 0x28(%rsp), %rax
jmp 0x247f7d
movq 0x4f30df(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37f818(%rip), %rsi    # 0x5c771b
leaq 0x37f94a(%rip), %rdx    # 0x5c7854
leaq 0x37f824(%rip), %rcx    # 0x5c7735
jmp 0x247f74
movq 0x4f30be(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37f0c7(%rip), %rsi    # 0x5c6feb
leaq 0x37f929(%rip), %rdx    # 0x5c7854
leaq 0x37fa10(%rip), %rcx    # 0x5c7942
jmp 0x247f74
movq 0x4f309d(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37f0a6(%rip), %rsi    # 0x5c6feb
leaq 0x37f908(%rip), %rdx    # 0x5c7854
leaq 0x37f7e6(%rip), %rcx    # 0x5c7739
jmp 0x247f74
movq 0x4f307c(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x37f79b(%rip), %rsi    # 0x5c7701
leaq 0x37f8e7(%rip), %rdx    # 0x5c7854
leaq 0x37f7c9(%rip), %rcx    # 0x5c773d
xorl %eax, %eax
callq 0x19e180
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq