// File: /workspace/github_c_makefile_star2_O3/nh13[P]ksw/src/parasail/src/sw_trace_scan.c
// Function: parasail_sw_trace_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;
    int8_t * restrict HT = NULL;
    int * restrict Ex = NULL;
    int i = 0;
    int j = 0;
    int s1Len = 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 */
    i = 0;
    j = 0;
    s1Len = matrix->type == PARASAIL_MATRIX_TYPE_SQUARE ? _s1Len : matrix->length;
    score = NEG_INF_32;
    end_query = s1Len;
    end_ref = s2Len;

    /* initialize result */
    result = parasail_result_new_trace(s1Len, s2Len, 16, sizeof(int8_t));
    if (!result) return NULL;

    /* set known flags */
    result->flag |= PARASAIL_FLAG_SW | PARASAIL_FLAG_NOVEC_SCAN
        | PARASAIL_FLAG_TRACE
        | PARASAIL_FLAG_BITS_INT | PARASAIL_FLAG_LANES_1;

    /* 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;
    Ex = parasail_memalign_int(16, s1Len);
    HT = (int8_t* restrict)result->trace->trace_table;

    /* validate heap variables */
    if (!s2) return NULL;
    if (!HB) return NULL;
    if (!E) return NULL;
    if (!HtB) return NULL;
    if (!Ex) 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;
    }

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

    /* iterate over database */
    for (j=0; j<s2Len; ++j) {
        int Ft = NEG_INF_32;
        /* calculate E */
        for (i=0; i<s1Len; ++i) {
            int E_opn = H[i]-open;
            int E_ext = E[i]-gap;
            E[i] = MAX(E_ext, E_opn);
            HT[1LL*i*s2Len + j] = (E_opn > E_ext) ? PARASAIL_DIAG_E
                                                  : PARASAIL_INS_E;
        }
        /* calculate Ht */
        Ht[-1] = 0;
        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]];
            int H_dag = H[i-1]+matval;
            Ht[i] = MAX(H_dag, E[i]);
            Ex[i] = (E[i] > H_dag);
        }
        /* 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;
            if (H[i-1] > Ft_ext) {
                HT[1LL*i*s2Len + j] |= PARASAIL_DIAG_F;
            }
            else {
                HT[1LL*i*s2Len + j] |= PARASAIL_DEL_F;
            }
            if (Ht[i] > Ft_opn) {
                H[i] = Ht[i];
                HT[1LL*i*s2Len + j] |= Ex[i] ? PARASAIL_INS : PARASAIL_DIAG;
            }
            else {
                H[i] = Ft_opn;
                if (Ht[i] == Ft_opn) {
                    if (Ex[i]) {
                        HT[1LL*i*s2Len + j] |= PARASAIL_DEL;
                    }
                    else {
                        HT[1LL*i*s2Len + j] |= PARASAIL_DIAG;
                    }
                }
                else {
                    HT[1LL*i*s2Len + j] |= PARASAIL_DEL;
                }
            }
            if (0 >= H[i]) {
                H[i] = 0;
                HT[1LL*i*s2Len + j] &= PARASAIL_ZERO_MASK;
            }
            if (H[i] > score) {
                score = H[i];
                end_query = i;
                end_ref = j;
            }
        }
    }

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

    parasail_free(Ex);
    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 0x2adff0
movl %ecx, %ebx
testl %ecx, %ecx
jle 0x2adff7
movl %r8d, %ebp
testl %r8d, %r8d
js 0x2adffe
testl %r9d, %r9d
js 0x2ae005
movq 0x90(%rsp), %rax
testq %rax, %rax
je 0x2ae00c
movq %rdx, %r14
cmpl $0x0, 0x30(%rax)
je 0x2adab2
movl 0x34(%rax), %r15d
jmp 0x2adac6
testq %rdi, %rdi
je 0x2ae026
movl %esi, %r15d
testl %esi, %esi
jle 0x2ae02d
movq %rdi, 0x28(%rsp)
movl %r9d, 0x1c(%rsp)
movl $0x10, %edx
movl $0x1, %ecx
movl %r15d, %edi
movl %ebx, %esi
callq 0x20adf4
testq %rax, %rax
je 0x2ae032
movl %ebp, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq %rax, 0x38(%rsp)
orl $0x1480204, 0xc(%rax)   # imm = 0x1480204
movl %ebx, %esi
movl $0x10, %edi
movq %rsi, 0x8(%rsp)
callq 0x20a617
movq %rax, 0x10(%rsp)
leal 0x1(%r15), %eax
movslq %eax, %rbp
movl $0x10, %edi
movq %rbp, %rsi
callq 0x20a617
movq %rax, %r12
movslq %r15d, %r14
movl $0x10, %edi
movq %r14, %rsi
callq 0x20a617
movq %rax, %r13
movl $0x10, %edi
movq %rbp, %rsi
callq 0x20a617
movq %rax, %rbp
movl $0x10, %edi
movq %r14, 0x48(%rsp)
movq %r14, %rsi
callq 0x20a617
movq 0x10(%rsp), %rsi
movq %rax, %rdx
movq %rsi, %xmm0
movq %r12, %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movq %r13, %xmm1
movq %rbp, %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 0x2ae034
testq %rdx, %rdx
je 0x2ae034
movq %rdx, 0x30(%rsp)
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax), %r9
movq 0x90(%rsp), %r10
cmpl $0x0, 0x30(%r10)
movl %r15d, %r14d
movq %r15, 0x40(%rsp)
movq %r9, (%rsp)
je 0x2adf9a
xorl %eax, %eax
movq 0x8(%rsp), %r11
movq %r12, %rdi
addq $0x4, %rdi
movq 0x10(%r10), %r8
xorl %ecx, %ecx
movq 0x20(%rsp), %r15
movzbl (%r15,%rcx), %edx
movl (%r8,%rdx,4), %edx
movl %edx, (%rsi,%rcx,4)
incq %rcx
cmpq %rcx, %r11
jne 0x2adc02
xorl %ecx, %ecx
movl %ecx, (%r12)
movl %ecx, (%rbp)
movq 0x40(%rsp), %r15
testl %r15d, %r15d
movq %rax, 0x20(%rsp)
movq %rdi, 0x28(%rsp)
jle 0x2add51
leaq (,%r14,4), %rdx
xorl %esi, %esi
callq 0x19e090
xorl %edx, %edx
movq (%rsp), %r9
movq 0x90(%rsp), %r10
leal 0x3(%r15), %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 0x37b20b(%rip), %xmm1   # 0x628e80
movdqa 0x37b213(%rip), %xmm2   # 0x628e90
movdqa 0x37b21b(%rip), %xmm3   # 0x628ea0
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0x37b21b(%rip), %xmm5   # 0x628eb0
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 0x2adcd2
movl $0xc0000000, (%r13,%rdx) # imm = 0xC0000000
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %ecx
testb $0x1, %cl
je 0x2adce9
movl $0xc0000000, 0x4(%r13,%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 0x2add29
movl $0xc0000000, 0x8(%r13,%rdx) # imm = 0xC0000000
pextrw $0x4, %xmm6, %ecx
testb $0x1, %cl
je 0x2add3c
movl $0xc0000000, 0xc(%r13,%rdx) # imm = 0xC0000000
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0x10, %rdx
cmpq %rdx, %rax
jne 0x2adc95
movl $0xc0000000, %eax       # imm = 0xC0000000
xorl %ecx, %ecx
movl %r15d, %edx
movq %rbp, 0x50(%rsp)
testl %r15d, %r15d
movl 0x1c(%rsp), %r11d
movq %r9, (%rsp)
jle 0x2adf27
movq %r9, %rsi
xorl %edi, %edi
movl 0x18(%rsp), %r15d
movq 0x8(%rsp), %rbp
movl 0x4(%r12,%rdi,4), %r8d
subl %r15d, %r8d
movl (%r13,%rdi,4), %r9d
subl %r11d, %r9d
cmpl %r8d, %r9d
cmovlel %r8d, %r9d
movl %r9d, (%r13,%rdi,4)
setge %r8b
shlb $0x3, %r8b
addb $0x8, %r8b
movb %r8b, (%rsi)
incq %rdi
addq %rbp, %rsi
cmpq %rdi, %r14
jne 0x2add81
movq 0x50(%rsp), %rbp
movl $0x0, (%rbp)
movq 0x40(%rsp), %r15
testl %r15d, %r15d
jle 0x2adf2e
movq 0x8(%r10), %rsi
xorl %edi, %edi
movq 0x10(%rsp), %r11
cmpl $0x0, 0x30(%r10)
movl 0x18(%r10), %r8d
je 0x2added
imull %edi, %r8d
jmp 0x2addf7
movq 0x20(%rsp), %r9
imull (%r9,%rdi,4), %r8d
movslq (%r11,%rcx,4), %r9
movslq %r8d, %r8
addq %r9, %r8
movl (%r12,%rdi,4), %r9d
addl (%rsi,%r8,4), %r9d
movl (%r13,%rdi,4), %r8d
cmpl %r8d, %r9d
cmovgl %r9d, %r8d
movl %r8d, 0x4(%rbp,%rdi,4)
xorl %r8d, %r8d
cmpl %r9d, (%r13,%rdi,4)
setg %r8b
movq 0x30(%rsp), %r9
movl %r8d, (%r9,%rdi,4)
incq %rdi
cmpq %rdi, %r14
jne 0x2adddc
testl %r15d, %r15d
jle 0x2adf2e
movl (%r12), %r9d
movl $0xc0000000, %r8d       # imm = 0xC0000000
movq (%rsp), %rsi
xorl %edi, %edi
movl %r8d, %r11d
movl (%rbp,%rdi,4), %r8d
subl 0x1c(%rsp), %r11d
cmpl %r11d, %r8d
cmovlel %r11d, %r8d
movl %r8d, %r10d
subl 0x18(%rsp), %r10d
cmpl %r11d, %r9d
setle %r9b
shlb $0x5, %r9b
addb $0x20, %r9b
orb %r9b, (%rsi)
movl 0x4(%rbp,%rdi,4), %r9d
cmpl %r10d, %r9d
jle 0x2adeae
movq 0x28(%rsp), %r11
movl %r9d, (%r11,%rdi,4)
xorl %r9d, %r9d
movq 0x30(%rsp), %r10
cmpl $0x0, (%r10,%rdi,4)
sete %r9b
leal (%r9,%r9,2), %r9d
incl %r9d
orb %r9b, (%rsi)
jmp 0x2adede
movq 0x28(%rsp), %r11
movl %r10d, (%r11,%rdi,4)
cmpl %r10d, 0x4(%rbp,%rdi,4)
jne 0x2adedb
movq 0x30(%rsp), %r9
cmpl $0x0, (%r9,%rdi,4)
movb (%rsi), %r9b
movq 0x90(%rsp), %r10
je 0x2adee8
orb $0x2, %r9b
jmp 0x2adeec
orb $0x2, (%rsi)
movq 0x90(%rsp), %r10
jmp 0x2adeef
orb $0x4, %r9b
movb %r9b, (%rsi)
movl (%r11,%rdi,4), %r9d
testl %r9d, %r9d
jg 0x2adf07
movl $0x0, (%r11,%rdi,4)
andb $0x78, (%rsi)
movl (%r11,%rdi,4), %r9d
cmpl %eax, %r9d
cmovgl %r9d, %eax
cmovgl %edi, %edx
cmovgl %ecx, %ebx
incq %rdi
addq 0x8(%rsp), %rsi
cmpq %rdi, %r14
jne 0x2ade50
jmp 0x2adf2e
movl $0x0, (%rbp)
incq %rcx
movq (%rsp), %r9
incq %r9
cmpq 0x8(%rsp), %rcx
jne 0x2add60
movq 0x38(%rsp), %r14
movl %eax, (%r14)
movl %edx, 0x4(%r14)
movl %ebx, 0x8(%r14)
movq 0x30(%rsp), %rdi
movq %r10, %rbx
callq 0x20a60d
movq %rbp, %rdi
callq 0x20a60d
movq %r13, %rdi
callq 0x20a60d
movq %r12, %rdi
callq 0x20a60d
movq 0x10(%rsp), %rdi
callq 0x20a60d
cmpl $0x0, 0x30(%rbx)
jne 0x2adf92
movq 0x20(%rsp), %rdi
callq 0x20a60d
movq %r14, %rax
jmp 0x2ae034
movl $0x10, %edi
movq 0x48(%rsp), %rsi
callq 0x20a617
testq %rax, %rax
je 0x2ae032
movq 0x90(%rsp), %r10
testl %r15d, %r15d
jle 0x2ae013
movq 0x10(%r10), %r8
xorl %ecx, %ecx
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %r11
movq (%rsp), %r9
movq 0x28(%rsp), %rdi
movzbl (%rdi,%rcx), %edx
movl (%r8,%rdx,4), %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
cmpq %rcx, %r14
jne 0x2adfd8
jmp 0x2adbf0
callq 0x1a2443
jmp 0x2ae032
callq 0x1a241d
jmp 0x2ae032
callq 0x1a23f7
jmp 0x2ae032
callq 0x1a23d1
jmp 0x2ae032
callq 0x1a23ab
jmp 0x2ae032
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %r11
movq (%rsp), %r9
jmp 0x2adbf0
callq 0x1a2385
jmp 0x2ae032
callq 0x1a235f
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop