// File: /workspace/github_c_makefile_star2_O3/nh13[P]ksw/src/parasail/src/pssw.c
// Function: parasail_ssw_profile
parasail_result_ssw_t* parasail_ssw_profile(
        const parasail_profile_t * const restrict profile,
        const char * const restrict s2, const int s2Len_,
        const int open, const int gap)
{
    const char *s1 = profile->s1;
    const parasail_matrix_t *matrix = profile->matrix;
    parasail_result_t *result_forward = NULL;
    parasail_result_t *result_reverse = NULL;
    parasail_result_t *result_final = NULL;
    parasail_result_ssw_t *result_ssw = NULL;
    int has8 = 0;
    int has16 = 0;
    char *s1_reverse = NULL;
    char *s2_reverse = NULL;
    int s1Len = 0;
    int s2Len = 0;
    int s1Off = 0;
    int s2Off = 0;
    parasail_cigar_t *cigar = NULL;

    /* find the end loc first with the faster implementation */
    has8 = (NULL != profile->profile8.score);
    has16 = (NULL != profile->profile16.score);

    /* find the end loc first with the faster implementation */
    if (has8) {
        result_forward = parasail_sw_striped_profile_8(profile, s2, s2Len_, open, gap);
        if (parasail_result_is_saturated(result_forward)) {
            has8 = 0;
            parasail_result_free(result_forward);
            result_forward = NULL;
        }
    }
    if (NULL == result_forward && has16) {
        result_forward = parasail_sw_striped_profile_16(profile, s2, s2Len_, open, gap);
        if (parasail_result_is_saturated(result_forward)) {
            parasail_result_free(result_forward);
            result_forward = NULL;
        }
    }
    /* 8- and/or 16-bit options could fail */
    if (NULL == result_forward) {
        return NULL;
    }

    /* find beginning loc by going in reverse */
    s1Len = result_forward->end_query+1;
    s2Len = result_forward->end_ref+1;
    s1_reverse = parasail_reverse(s1, s1Len);
    s2_reverse = parasail_reverse(s2, s2Len);
    if (has8) {
        result_reverse = parasail_sw_striped_8(
                s1_reverse, s1Len,
                s2_reverse, s2Len,
                open, gap, matrix);
        if (parasail_result_is_saturated(result_reverse)) {
            has8 = 0;
            parasail_result_free(result_reverse);
            result_reverse = NULL;
        }
    }
    if (NULL == result_reverse && has16) {
        result_reverse = parasail_sw_striped_16(
                s1_reverse, s1Len,
                s2_reverse, s2Len,
                open, gap, matrix);
        if (parasail_result_is_saturated(result_reverse)) {
            parasail_result_free(result_reverse);
            result_reverse = NULL;
        }
    }
    free(s2_reverse);
    free(s1_reverse);

    /* 8- and/or 16-bit options could fail */
    if (NULL == result_reverse) {
        parasail_result_free(result_forward); /* free the forward result */
        return NULL;
    }

    /* run trace version of sw on just the aligned portion */
    s1Off = result_forward->end_query - result_reverse->end_query;
    s2Off = result_forward->end_ref - result_reverse->end_ref;
    s1Len = result_reverse->end_query+1;
    s2Len = result_reverse->end_ref+1;
    if (has8) {
        result_final = parasail_sw_trace_striped_8(
                &s1[s1Off], s1Len,
                &s2[s2Off], s2Len,
                open, gap, matrix);
        if (parasail_result_is_saturated(result_final)) {
            has8 = 0;
            parasail_result_free(result_final);
            result_final = NULL;
        }
    }
    if (NULL == result_final && has16) {
        result_final = parasail_sw_trace_striped_16(
                &s1[s1Off], s1Len,
                &s2[s2Off], s2Len,
                open, gap, matrix);
        if (parasail_result_is_saturated(result_final)) {
            parasail_result_free(result_final);
            result_final = NULL;
        }
    }

    /* 8- and/or 16-bit options could fail */
    if (NULL == result_final) {
        parasail_result_free(result_reverse); /* free reverse result */
        parasail_result_free(result_forward); /* free forward result */
        return NULL;
    }

    /* get cigar from traceback */
    cigar = parasail_result_get_cigar(result_final,
            &s1[s1Off], s1Len,
            &s2[s2Off], s2Len,
            matrix);

    result_ssw = (parasail_result_ssw_t*)malloc(sizeof(parasail_result_ssw_t));
    result_ssw->score1 = result_forward->score;
    result_ssw->ref_begin1 = s2Off;
    result_ssw->ref_end1 = result_forward->end_ref;
    result_ssw->read_begin1 = s1Off;
    result_ssw->read_end1 = result_forward->end_query;
    result_ssw->cigar = cigar->seq;
    result_ssw->cigarLen = cigar->len;

    free(cigar);
    parasail_result_free(result_final);
    parasail_result_free(result_reverse);
    parasail_result_free(result_forward);

    return result_ssw;;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %r14
movq (%rdi), %rax
movq %rax, 0x40(%rsp)
movq 0x10(%rdi), %r13
cmpq $0x0, 0x18(%rdi)
movq 0x30(%rdi), %rax
movq %rax, 0x28(%rsp)
movl %r8d, 0x1c(%rsp)
movl %ecx, 0x18(%rsp)
je 0x255561
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x263c77
movq %rax, %rbx
movq %rax, %rdi
callq 0x2542be
testl %eax, %eax
je 0x255568
movq %rbx, %rdi
callq 0x25344c
xorl %ebx, %ebx
xorl %r15d, %r15d
jmp 0x25556b
movb $0x1, %r15b
cmpq $0x0, 0x28(%rsp)
setne %al
testq %rbx, %rbx
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2555aa
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
movl 0x18(%rsp), %ecx
movl 0x1c(%rsp), %r8d
callq 0x263c6e
movq %rax, %rbx
movq %rax, %rdi
callq 0x2542be
testl %eax, %eax
jne 0x255848
testq %rbx, %rbx
je 0x255850
movq %r13, 0x20(%rsp)
movslq 0x4(%rbx), %r13
incq %r13
movslq 0x8(%rbx), %r14
incq %r14
movq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x25418e
movq %r12, %rdi
movq %rax, %r12
movq %rdi, 0x38(%rsp)
movq %r14, %rsi
callq 0x25418e
movq %rax, %rbp
movb $0x1, %al
movl %eax, 0x14(%rsp)
testb %r15b, %r15b
je 0x255633
movq 0x20(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
movl %r13d, %esi
movq %rbp, %rdx
movl %r14d, %ecx
movl 0x18(%rsp), %r8d
movl 0x1c(%rsp), %r9d
callq 0x263983
movq %rax, %r15
movq %rax, %rdi
callq 0x2542be
testl %eax, %eax
je 0x255797
movq %r15, %rdi
callq 0x25344c
xorl %r15d, %r15d
cmpq $0x0, 0x28(%rsp)
setne %al
testq %r15, %r15
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x25568a
movq 0x20(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
movl %r13d, %esi
movq %rbp, %rdx
movl %r14d, %ecx
movl 0x18(%rsp), %r8d
movl 0x1c(%rsp), %r9d
callq 0x26397a
movq %rax, %r15
movq %rax, %rdi
callq 0x2542be
testl %eax, %eax
je 0x25568a
movq %r15, %rdi
callq 0x25344c
xorl %r15d, %r15d
movq %rbp, %rdi
callq 0x1f01c0
movq %r12, %rdi
callq 0x1f01c0
testq %r15, %r15
je 0x255848
movslq 0x4(%rbx), %rdx
movslq 0x4(%r15), %rax
subq %rax, %rdx
movslq 0x8(%rbx), %r13
movslq 0x8(%r15), %rcx
subq %rcx, %r13
leal 0x1(%rax), %r12d
leal 0x1(%rcx), %r8d
cmpb $0x0, 0x14(%rsp)
movq %rdx, 0x30(%rsp)
je 0x2556d6
xorl %ebp, %ebp
movq 0x40(%rsp), %r14
jmp 0x255734
movq 0x40(%rsp), %r14
leaq (%r14,%rdx), %rdi
movq 0x38(%rsp), %rax
leaq (%rax,%r13), %rdx
movq 0x20(%rsp), %rax
movq %rax, (%rsp)
movl %r12d, 0x14(%rsp)
movl %r12d, %esi
movl %r8d, %r12d
movl %r8d, %ecx
movl 0x18(%rsp), %r8d
movl 0x1c(%rsp), %r9d
callq 0x263c0b
movq %rax, %rbp
movq %rax, %rdi
callq 0x2542be
testl %eax, %eax
je 0x255727
movq %rbp, %rdi
callq 0x25344c
xorl %ebp, %ebp
movq 0x30(%rsp), %rdx
movl %r12d, %r8d
movl 0x14(%rsp), %r12d
cmpq $0x0, 0x28(%rsp)
setne %al
testq %rbp, %rbp
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2557ae
movslq %edx, %rdi
addq %r14, %rdi
movslq %r13d, %rdx
addq 0x38(%rsp), %rdx
movq 0x20(%rsp), %rax
movq %rax, (%rsp)
movl %r12d, %esi
movl %r8d, %ecx
movl %r8d, 0x28(%rsp)
movl 0x18(%rsp), %r8d
movl 0x1c(%rsp), %r9d
callq 0x263c02
movq %rax, %rbp
movq %rax, %rdi
callq 0x2542be
testl %eax, %eax
je 0x2557a4
movq %rbp, %rdi
callq 0x25344c
jmp 0x255840
movl $0x0, 0x14(%rsp)
jmp 0x255636
movq 0x30(%rsp), %rdx
movl 0x28(%rsp), %r8d
testq %rbp, %rbp
je 0x255840
movslq %edx, %rax
addq %rax, %r14
movslq %r13d, %rax
movq 0x38(%rsp), %rcx
addq %rax, %rcx
movq %rbp, %rdi
movq %r14, %rsi
movl %r12d, %edx
movq 0x20(%rsp), %r9
callq 0x617e9b
movq %rax, %r12
movl $0x28, %edi
callq 0x1f01f0
movq %rax, %r14
movzwl (%rbx), %eax
movw %ax, (%r14)
movl %r13d, 0x4(%r14)
movl 0x8(%rbx), %eax
movl %eax, 0x8(%r14)
movq 0x30(%rsp), %rax
movl %eax, 0xc(%r14)
movl 0x4(%rbx), %eax
movl %eax, 0x10(%r14)
movq (%r12), %rax
movq %rax, 0x18(%r14)
movl 0x8(%r12), %eax
movl %eax, 0x20(%r14)
movq %r12, %rdi
callq 0x1f01c0
movq %rbp, %rdi
callq 0x25344c
movq %r15, %rdi
callq 0x25344c
movq %rbx, %rdi
callq 0x25344c
jmp 0x255853
movq %r15, %rdi
callq 0x25344c
movq %rbx, %rdi
callq 0x25344c
xorl %r14d, %r14d
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq