// File: /workspace/github_c_makefile_star2_O1/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 %r8d, %r13d
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %r14
movq (%rdi), %rax
movq %rax, 0x38(%rsp)
movq 0x10(%rdi), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x18(%rdi)
setne %r15b
movq 0x30(%rdi), %rax
movq %rax, 0x20(%rsp)
movl %ecx, 0x14(%rsp)
je 0x2550c7
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
movl %r13d, %r8d
callq 0x2637d3
movq %rax, %rbx
movq %rax, %rdi
callq 0x253d45
testl %eax, %eax
je 0x2550cb
movq %rbx, %rdi
callq 0x252ed9
xorl %ebx, %ebx
xorl %r15d, %r15d
jmp 0x2550ce
xorl %ebx, %ebx
jmp 0x2550ce
movb $0x1, %r15b
cmpq $0x0, 0x20(%rsp)
setne %al
testq %rbx, %rbx
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x255111
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
movl 0x14(%rsp), %ecx
movl %r13d, %r8d
callq 0x2637ca
movq %rax, %rbx
movq %rax, %rdi
callq 0x253d45
testl %eax, %eax
je 0x255111
movq %rbx, %rdi
callq 0x252ed9
xorl %ebx, %ebx
testq %rbx, %rbx
je 0x255238
movl %r13d, 0x1c(%rsp)
movq %r12, %rbp
movslq 0x4(%rbx), %r13
incq %r13
movslq 0x8(%rbx), %r14
incq %r14
movq 0x38(%rsp), %rdi
movq %r13, %rsi
callq 0x253c11
movq %rax, %r12
movq %rbp, 0x40(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
callq 0x253c11
movq %rax, %rbp
movb $0x1, %al
movl %eax, 0x34(%rsp)
testb %r15b, %r15b
je 0x25519d
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
movl %r13d, %esi
movq %rbp, %rdx
movl %r14d, %ecx
movl 0x14(%rsp), %r8d
movl 0x1c(%rsp), %r9d
callq 0x2634df
movq %rax, %r15
movq %rax, %rdi
callq 0x253d45
testl %eax, %eax
je 0x2553b5
movq %r15, %rdi
callq 0x252ed9
xorl %r15d, %r15d
cmpq $0x0, 0x20(%rsp)
setne %al
testq %r15, %r15
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x2551f4
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
movq %r12, %rdi
movl %r13d, %esi
movq %rbp, %rdx
movl %r14d, %ecx
movl 0x14(%rsp), %r8d
movl 0x1c(%rsp), %r9d
callq 0x2634d6
movq %rax, %r15
movq %rax, %rdi
callq 0x253d45
testl %eax, %eax
je 0x2551f4
movq %r15, %rdi
callq 0x252ed9
xorl %r15d, %r15d
movq %rbp, %rdi
callq 0x1f01c0
movq %r12, %rdi
callq 0x1f01c0
testq %r15, %r15
je 0x255240
movslq 0x4(%rbx), %r14
movslq 0x4(%r15), %rax
subq %rax, %r14
movslq 0x8(%rbx), %r13
movslq 0x8(%r15), %rcx
subq %rcx, %r13
leal 0x1(%rax), %r8d
leal 0x1(%rcx), %r9d
cmpb $0x0, 0x34(%rsp)
movl %r8d, 0x18(%rsp)
je 0x255248
xorl %r12d, %r12d
jmp 0x25529b
xorl %r14d, %r14d
jmp 0x2553a3
xorl %r14d, %r14d
jmp 0x25539b
movq %r14, %rdi
addq 0x38(%rsp), %rdi
movq %r13, %rdx
addq 0x40(%rsp), %rdx
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
movl %r8d, %esi
movl %r9d, %ebp
movl %r9d, %ecx
movl 0x14(%rsp), %r8d
movl 0x1c(%rsp), %r9d
callq 0x263767
movq %rax, %r12
movq %rax, %rdi
callq 0x253d45
testl %eax, %eax
je 0x255293
movq %r12, %rdi
callq 0x252ed9
xorl %r12d, %r12d
movl 0x18(%rsp), %r8d
movl %ebp, %r9d
cmpq $0x0, 0x20(%rsp)
setne %al
testq %r12, %r12
sete %cl
andb %al, %cl
movslq %r14d, %rdx
movslq %r13d, %rbp
cmpb $0x1, %cl
movq 0x40(%rsp), %r14
movq %rdx, 0x20(%rsp)
jne 0x255316
movq 0x38(%rsp), %rax
leaq (%rax,%rdx), %rdi
leaq (%r14,%rbp), %rdx
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
movl %r8d, %esi
movl %r9d, %r13d
movl %r9d, %ecx
movl 0x14(%rsp), %r8d
movl 0x1c(%rsp), %r9d
callq 0x26375e
movq %rax, %r12
movq %rax, %rdi
callq 0x253d45
testl %eax, %eax
je 0x255309
movq %r12, %rdi
callq 0x252ed9
xorl %r12d, %r12d
movl 0x18(%rsp), %r8d
movl %r13d, %r9d
movq 0x20(%rsp), %rdx
testq %r12, %r12
je 0x255390
movq 0x38(%rsp), %rsi
addq %rdx, %rsi
addq %rbp, %r14
movq %r12, %rdi
movl %r8d, %edx
movq %r14, %rcx
movl %r9d, %r8d
movq 0x28(%rsp), %r9
callq 0x5e4004
movq %rax, %r13
movl $0x28, %edi
callq 0x1f01f0
movq %rax, %r14
movzwl (%rbx), %eax
movw %ax, (%r14)
movl %ebp, 0x4(%r14)
movl 0x8(%rbx), %eax
movl %eax, 0x8(%r14)
movq 0x20(%rsp), %rax
movl %eax, 0xc(%r14)
movl 0x4(%rbx), %eax
movl %eax, 0x10(%r14)
movq (%r13), %rax
movq %rax, 0x18(%r14)
movl 0x8(%r13), %eax
movl %eax, 0x20(%r14)
movq %r13, %rdi
callq 0x1f01c0
movq %r12, %rdi
callq 0x252ed9
jmp 0x255393
xorl %r14d, %r14d
movq %r15, %rdi
callq 0x252ed9
movq %rbx, %rdi
callq 0x252ed9
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x0, 0x34(%rsp)
jmp 0x2551a0