// File: /workspace/github_c_makefile_star2_O3/nh13[P]ksw/src/parasail/src/sw_scan.c
// Function: parasail_sw_rowcol_scan
parasail_result_t* ENAME(
        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)
{
    /* 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 * restrict FtB= NULL;
    int * restrict Ft = 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_SW | PARASAIL_FLAG_NOVEC_SCAN
        | PARASAIL_FLAG_BITS_INT | PARASAIL_FLAG_LANES_1;
#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;
    FtB= parasail_memalign_int(16, s1Len+1);
    Ft = FtB+1;

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

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

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

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

    parasail_free(FtB);
    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 $0x58, %rsp
testq %rdx, %rdx
je 0x2a7dde
movl %ecx, %ebx
testl %ecx, %ecx
jle 0x2a7de5
movl %r8d, %r12d
testl %r8d, %r8d
js 0x2a7dec
movl %r9d, %ebp
testl %r9d, %r9d
js 0x2a7df3
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0x2a7dfa
movq %rdi, %r14
cmpl $0x0, 0x30(%rax)
je 0x2a78d0
movl 0x34(%rax), %edi
jmp 0x2a78e4
testq %r14, %r14
je 0x2a7e0b
movq %rsi, %rdi
testl %edi, %edi
jle 0x2a7e12
movq %rdx, 0x28(%rsp)
movl %ebx, %esi
movq %rdi, %r15
callq 0x20ac53
testq %rax, %rax
je 0x2a7e17
movl %r12d, 0x24(%rsp)
movq %r14, 0x50(%rsp)
movq %rax, (%rsp)
orl $0x1440204, 0xc(%rax)   # imm = 0x1440204
movl %ebx, %esi
movl $0x10, %edi
movq %rsi, 0x38(%rsp)
callq 0x20a617
movq %rax, 0x40(%rsp)
leal 0x1(%r15), %eax
movslq %eax, %r13
movl $0x10, %edi
movq %r13, %rsi
callq 0x20a617
movq %rax, %r14
movq %r15, 0x8(%rsp)
movslq %r15d, %rsi
movl $0x10, %edi
movq %rsi, 0x48(%rsp)
callq 0x20a617
movq %rax, %r12
movl $0x10, %edi
movq %r13, %rsi
callq 0x20a617
movq %rax, %r15
movl $0x10, %edi
movq %r13, %rsi
callq 0x20a617
movq 0x40(%rsp), %rsi
movq %rax, %r8
movq %rsi, %xmm0
movq %r14, 0x30(%rsp)
movq %r14, %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq %r12, %xmm1
movq %r15, %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, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jne 0x2a7e19
testq %r8, %r8
je 0x2a7e19
movq 0x90(%rsp), %r11
cmpl $0x0, 0x30(%r11)
movl 0x8(%rsp), %r14d
movq %r8, 0x18(%rsp)
je 0x2a7b67
movq $0x0, 0x10(%rsp)
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %r10
movq 0x30(%rsp), %r13
addq $0x4, %r13
movq 0x10(%r11), %rax
xorl %ecx, %ecx
movzbl (%r10,%rcx), %edx
movl (%rax,%rdx,4), %edx
movl %edx, (%rsi,%rcx,4)
incq %rcx
cmpq %rcx, %rdi
jne 0x2a7a0e
xorl %eax, %eax
movq 0x30(%rsp), %rcx
movl %eax, (%rcx)
movl %eax, (%r15)
movq 0x8(%rsp), %rax
testl %eax, %eax
jle 0x2a7bd6
leaq (,%r14,4), %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x19e090
xorl %edx, %edx
movq 0x90(%rsp), %r11
movq 0x18(%rsp), %rax
movl $0xc0000000, (%rax)     # imm = 0xC0000000
movq 0x8(%rsp), %rax
addl $0x3, %eax
leaq -0x1(%r14), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl $0x2, %eax
shlq $0x4, %rax
movdqa 0x3813fa(%rip), %xmm1   # 0x628e80
movdqa 0x381402(%rip), %xmm2   # 0x628e90
movdqa 0x38140a(%rip), %xmm3   # 0x628ea0
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0x38140a(%rip), %xmm5   # 0x628eb0
movq (%rsp), %r10
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %ecx
notl %ecx
testb $0x1, %cl
je 0x2a7ae6
movl $0xc0000000, (%r12,%rdx) # imm = 0xC0000000
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %ecx
testb $0x1, %cl
je 0x2a7afd
movl $0xc0000000, 0x4(%r12,%rdx) # imm = 0xC0000000
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm4, %xmm6
pextrw $0x0, %xmm6, %ecx
testb $0x1, %cl
je 0x2a7b3d
movl $0xc0000000, 0x8(%r12,%rdx) # imm = 0xC0000000
pextrw $0x4, %xmm6, %ecx
testb $0x1, %cl
je 0x2a7b50
movl $0xc0000000, 0xc(%r12,%rdx) # imm = 0xC0000000
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0x10, %rdx
cmpq %rdx, %rax
jne 0x2a7aaa
jmp 0x2a7be1
movq %rsi, %r13
movl $0x10, %edi
movq 0x48(%rsp), %rsi
callq 0x20a617
testq %rax, %rax
je 0x2a7e17
movq %rax, 0x10(%rsp)
cmpl $0x0, 0x8(%rsp)
movq %r13, %rsi
movq 0x38(%rsp), %rdi
movq 0x28(%rsp), %r10
movq 0x90(%rsp), %r11
jle 0x2a7e01
movq 0x10(%r11), %rax
xorl %ecx, %ecx
movq 0x18(%rsp), %r8
movq 0x10(%rsp), %r9
movq 0x50(%rsp), %r13
movzbl (%r13,%rcx), %edx
movl (%rax,%rdx,4), %edx
movl %edx, (%r9,%rcx,4)
incq %rcx
cmpq %rcx, %r14
jne 0x2a7bbc
jmp 0x2a79ff
movl $0xc0000000, (%r8)      # imm = 0xC0000000
movq (%rsp), %r10
leal -0x1(%rbx), %eax
movq %rax, 0x28(%rsp)
movl $0xc0000000, %edi       # imm = 0xC0000000
xorl %esi, %esi
movq 0x8(%rsp), %rax
movl %eax, %edx
movq 0x10(%rsp), %rcx
testl %eax, %eax
jle 0x2a7d34
xorl %r8d, %r8d
movl 0x24(%rsp), %eax
movl (%r12,%r8,4), %r9d
subl %ebp, %r9d
movl (%r13,%r8,4), %r10d
subl %eax, %r10d
cmpl %r10d, %r9d
cmovgl %r9d, %r10d
movl %r10d, (%r12,%r8,4)
incq %r8
cmpq %r8, %r14
jne 0x2a7c0b
movq 0x8(%rsp), %rax
testl %eax, %eax
jle 0x2a7d30
movq 0x8(%r11), %r8
xorl %r9d, %r9d
cmpl $0x0, 0x30(%r11)
movl 0x18(%r11), %r10d
je 0x2a7c52
imull %r9d, %r10d
jmp 0x2a7c57
imull (%rcx,%r9,4), %r10d
movq 0x40(%rsp), %r11
movslq (%r11,%rsi,4), %r11
movslq %r10d, %r10
addq %r11, %r10
movq 0x30(%rsp), %r11
movl (%r11,%r9,4), %r11d
addl (%r8,%r10,4), %r11d
movl (%r12,%r9,4), %r10d
cmpl %r10d, %r11d
cmovlel %r10d, %r11d
movl %r11d, 0x4(%r15,%r9,4)
incq %r9
cmpq %r9, %r14
movq 0x90(%rsp), %r11
jne 0x2a7c41
testl %eax, %eax
jle 0x2a7d30
movq 0x18(%rsp), %rcx
movl (%rcx), %r8d
xorl %r9d, %r9d
subl %ebp, %r8d
movl (%r15,%r9,4), %r10d
cmpl %r10d, %r8d
cmovlel %r10d, %r8d
movl %r8d, 0x4(%rcx,%r9,4)
incq %r9
cmpq %r9, %r14
jne 0x2a7ca6
testl %eax, %eax
jle 0x2a7d59
xorl %r8d, %r8d
movl 0x24(%rsp), %eax
movq 0x18(%rsp), %rcx
movl %edi, %r9d
movl 0x4(%r15,%r8,4), %r10d
movl 0x4(%rcx,%r8,4), %edi
subl %eax, %edi
cmpl %edi, %r10d
cmovgl %r10d, %edi
testl %edi, %edi
movl $0x0, %r10d
cmovlel %r10d, %edi
movl %edi, (%r13,%r8,4)
cmpl %r9d, %edi
cmovlel %r9d, %edi
cmovgl %r8d, %edx
cmovgl %esi, %ebx
incq %r8
cmpq %r8, %r14
jne 0x2a7cd5
movq 0x8(%rsp), %rax
testl %eax, %eax
setle %r8b
cmpq 0x28(%rsp), %rsi
setne %r9b
orb %r8b, %r9b
movq 0x10(%rsp), %rcx
je 0x2a7d64
movq (%rsp), %r10
movq 0x48(%rsp), %r8
movl -0x4(%r13,%r8,4), %r8d
movq 0x10(%r10), %r9
movq (%r9), %r9
movl %r8d, (%r9,%rsi,4)
incq %rsi
cmpq 0x38(%rsp), %rsi
jne 0x2a7bfc
jmp 0x2a7d8a
movq (%rsp), %r10
movq 0x10(%rsp), %rcx
jmp 0x2a7d34
xorl %r8d, %r8d
movl (%r13,%r8,4), %r9d
movq (%rsp), %r10
movq 0x10(%r10), %r10
movq 0x8(%r10), %r10
movl %r9d, (%r10,%r8,4)
movq (%rsp), %r10
incq %r8
cmpq %r8, %r14
jne 0x2a7d67
jmp 0x2a7d34
movl %edi, (%r10)
movl %edx, 0x4(%r10)
movl %ebx, 0x8(%r10)
movq 0x18(%rsp), %rdi
movq %r11, %rbx
movq %r10, %r14
callq 0x20a60d
movq %r15, %rdi
callq 0x20a60d
movq %r12, %rdi
callq 0x20a60d
movq 0x30(%rsp), %rdi
callq 0x20a60d
movq 0x40(%rsp), %rdi
callq 0x20a60d
cmpl $0x0, 0x30(%rbx)
jne 0x2a7dd9
movq 0x10(%rsp), %rdi
callq 0x20a60d
movq %r14, %rax
jmp 0x2a7e19
callq 0x1a1711
jmp 0x2a7e17
callq 0x1a16eb
jmp 0x2a7e17
callq 0x1a16c5
jmp 0x2a7e17
callq 0x1a169f
jmp 0x2a7e17
callq 0x1a1679
jmp 0x2a7e17
movq 0x18(%rsp), %r8
jmp 0x2a79ff
callq 0x1a1653
jmp 0x2a7e17
callq 0x1a162d
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq