// File: /workspace/github_c_makefile_star2_O2/nh13[P]ksw/src/parasail/src/memory.c
// Function: parasail_matrix_convert_square_to_pssm
parasail_matrix_t* parasail_matrix_convert_square_to_pssm(
        const parasail_matrix_t *matrix,
        const char *s1,
        int s1Len)
{
    parasail_matrix_t *retval = NULL;
    size_t matrix_size = matrix->size*s1Len;
    size_t alphabet_size = matrix->size+1;
    int *new_mapper = NULL;
    int *new_matrix = NULL;
    char *new_alphabet = NULL;
    char *new_query = NULL;
    int i;

    PARASAIL_CHECK_NULL(matrix);

    if (matrix->type != PARASAIL_MATRIX_TYPE_SQUARE) {
        fprintf(stderr, "%s: attempted to convert non-square matrix to pssm\n", __func__);
        return NULL;
    }

    PARASAIL_NEW(retval, parasail_matrix_t);

    PARASAIL_CALLOC(new_mapper, int, 256);
    (void)memcpy(new_mapper, matrix->mapper, sizeof(int)*256);

    PARASAIL_CALLOC(new_matrix, int, matrix_size);

    PARASAIL_CALLOC(new_alphabet, char, alphabet_size);
    (void)memcpy(new_alphabet, matrix->alphabet, sizeof(char)*alphabet_size);

    PARASAIL_CALLOC(new_query, char, s1Len+1);
    (void)memcpy(new_query, s1, sizeof(char)*(s1Len+1));

    for (i=0; i<s1Len; ++i) {
        (void)memcpy(
                &new_matrix[matrix->size*i],
                &matrix->matrix[matrix->size*matrix->mapper[(unsigned char)s1[i]]],
                sizeof(int)*matrix->size);
    }

    retval->name = matrix->name;
    retval->matrix = new_matrix;
    retval->mapper = new_mapper;
    retval->size = matrix->size;
    retval->max = matrix->max;
    retval->min = matrix->min;
    retval->user_matrix = new_matrix;
    retval->type = PARASAIL_MATRIX_TYPE_PSSM;
    retval->length = s1Len;
    retval->alphabet = new_alphabet;
    retval->query = new_query;

    return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, 0x10(%rsp)
cmpl $0x0, 0x30(%rdi)
jne 0x1ac98c
movl %edx, %r13d
movq %rdi, %r12
movl 0x18(%rdi), %ebp
pushq $0x48
popq %rdi
callq 0x19e150
testq %rax, %rax
je 0x1ac9af
movq %rax, %r15
movl $0x400, %edi            # imm = 0x400
callq 0x19e150
testq %rax, %rax
je 0x1ac9ce
movq %rax, %rbx
movl %ebp, %eax
imull %r13d, %eax
movslq %eax, %r14
movq 0x10(%r12), %rsi
movl $0x400, %edx            # imm = 0x400
movq %rbx, %rdi
movq %rsi, 0x40(%rsp)
callq 0x19e0c0
shlq $0x2, %r14
movq %r14, %rdi
callq 0x19e150
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x1ac96d
movq %rbx, 0x38(%rsp)
movslq %ebp, %rbx
leaq 0x1(%rbx), %r14
movq %r14, %rdi
callq 0x19e150
testq %rax, %rax
je 0x1ac96d
movq 0x38(%r12), %rsi
movq %rax, 0x30(%rsp)
movq %rax, %rdi
movq %r14, %rdx
callq 0x19e0c0
leal 0x1(%r13), %eax
movslq %eax, %r14
movq %r14, %rdi
callq 0x19e150
testq %rax, %rax
je 0x1ac96d
movl %ebp, 0x4(%rsp)
movq %r12, %rbp
movq %r15, 0x28(%rsp)
movq %rax, 0x18(%rsp)
movq %rax, %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x19e0c0
leaq (,%rbx,4), %r14
xorl %r12d, %r12d
testl %r13d, %r13d
movl $0x0, %r15d
movq %r13, 0x20(%rsp)
cmovgl %r13d, %r15d
movq 0x8(%rsp), %r13
cmpq %r12, %r15
je 0x1ac916
movq 0x10(%rsp), %rax
movzbl (%rax,%r12), %eax
movq 0x40(%rsp), %rcx
movslq (%rcx,%rax,4), %rsi
imulq %rbx, %rsi
shlq $0x2, %rsi
addq 0x8(%rbp), %rsi
movq %r13, %rdi
movq %r14, %rdx
callq 0x19e0c0
incq %r12
addq %r14, %r13
jmp 0x1ac8df
movq (%rbp), %rax
movq 0x28(%rsp), %rbx
movq %rax, (%rbx)
movq 0x8(%rsp), %rcx
movq %rcx, 0x8(%rbx)
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rbx)
movl 0x4(%rsp), %eax
movl %eax, 0x18(%rbx)
movq 0x1c(%rbp), %rax
movq %rax, 0x1c(%rbx)
movq %rcx, 0x28(%rbx)
movl $0x1, 0x30(%rbx)
movq 0x20(%rsp), %rax
movl %eax, 0x34(%rbx)
movq 0x30(%rsp), %rax
movq %rax, 0x38(%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x40(%rbx)
jmp 0x1ac9f4
movq 0x58e664(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x41a53f(%rip), %rsi    # 0x5c6ebd
leaq 0x41a68b(%rip), %rdx    # 0x5c7010
xorl %ebx, %ebx
movq %r14, %rcx
jmp 0x1ac9ed
movq 0x58e645(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x41a69a(%rip), %rsi    # 0x5c7037
leaq 0x41a66c(%rip), %rdx    # 0x5c7010
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x19e180
jmp 0x1ac9f4
movq 0x58e622(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x41a4fd(%rip), %rsi    # 0x5c6ebd
leaq 0x41a649(%rip), %rdx    # 0x5c7010
xorl %ebx, %ebx
pushq $0x48
popq %rcx
jmp 0x1ac9ed
movq 0x58e603(%rip), %rax    # 0x73afd8
movq (%rax), %rdi
leaq 0x41a4de(%rip), %rsi    # 0x5c6ebd
leaq 0x41a62a(%rip), %rdx    # 0x5c7010
xorl %ebx, %ebx
movl $0x400, %ecx            # imm = 0x400
xorl %eax, %eax
callq 0x19e180
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq