// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
testq %rdi, %rdi
je 0x20a4a6
movq %rdi, %rbp
cmpl $0x0, 0x30(%rdi)
jne 0x20a4ad
movl %edx, %r12d
movq %rsi, %r13
movl 0x18(%rbp), %r15d
movl $0x48, %edi
callq 0x19e150
testq %rax, %rax
je 0x20a4b4
movq %rax, %rbx
movl $0x400, %edi            # imm = 0x400
callq 0x19e150
testq %rax, %rax
je 0x20a4bb
movl %r15d, %ecx
imull %r12d, %ecx
movslq %ecx, %r14
movq 0x10(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
movq %rax, 0x48(%rsp)
movq %rax, %rdi
movq %rsi, 0x40(%rsp)
callq 0x19e0c0
shlq $0x2, %r14
movq %r14, %rdi
callq 0x19e150
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x20a487
movslq %r15d, %rax
movq %rax, 0x20(%rsp)
leaq 0x1(%rax), %r14
movq %r14, %rdi
callq 0x19e150
testq %rax, %rax
je 0x20a487
movl %r15d, 0x4(%rsp)
movq %r13, %r15
movq 0x38(%rbp), %rsi
movq %rax, 0x38(%rsp)
movq %rax, %rdi
movq %r14, %rdx
callq 0x19e0c0
leal 0x1(%r12), %eax
movslq %eax, %r13
movq %r13, %rdi
callq 0x19e150
testq %rax, %rax
je 0x20a4c4
movq %rbp, 0x8(%rsp)
movq %rbx, 0x30(%rsp)
movq %rax, 0x28(%rsp)
movq %rax, %rdi
movq %r15, %rsi
movq %r15, 0x50(%rsp)
movq %r13, %rdx
callq 0x19e0c0
movq %r12, 0x10(%rsp)
testl %r12d, %r12d
movq 0x40(%rsp), %r15
movq 0x20(%rsp), %rcx
jle 0x20a42b
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rbx
leaq (,%rcx,4), %r13
movl 0x10(%rsp), %r12d
xorl %ebp, %ebp
movq 0x18(%rsp), %r14
movq 0x50(%rsp), %rax
movzbl (%rax,%rbp), %eax
movslq (%r15,%rax,4), %rax
imulq %rcx, %rax
leaq (%rbx,%rax,4), %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0x19e0c0
movq 0x20(%rsp), %rcx
incq %rbp
addq %r13, %r14
cmpq %rbp, %r12
jne 0x20a3fb
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq 0x30(%rsp), %rbx
movq %rax, (%rbx)
movq 0x18(%rsp), %rdx
movq %rdx, 0x8(%rbx)
movq 0x48(%rsp), %rax
movq %rax, 0x10(%rbx)
movl 0x4(%rsp), %eax
movl %eax, 0x18(%rbx)
movl 0x1c(%rcx), %eax
movl %eax, 0x1c(%rbx)
movl 0x20(%rcx), %eax
movl %eax, 0x20(%rbx)
movq %rdx, 0x28(%rbx)
movl $0x1, 0x30(%rbx)
movq 0x10(%rsp), %rax
movl %eax, 0x34(%rbx)
movq 0x38(%rsp), %rax
movq %rax, 0x38(%rbx)
movq 0x28(%rsp), %rax
movq %rax, 0x40(%rbx)
jmp 0x20a4e8
movq 0x597b4a(%rip), %rax    # 0x7a1fd8
movq (%rax), %rdi
leaq 0x3eaa15(%rip), %rsi    # 0x5f4ead
leaq 0x3eab61(%rip), %rdx    # 0x5f5000
xorl %ebx, %ebx
movq %r14, %rcx
jmp 0x20a4e1
callq 0x19ed54
jmp 0x20a4c0
callq 0x19ecef
jmp 0x20a4c0
callq 0x19ed32
jmp 0x20a4c0
callq 0x19ed0e
xorl %ebx, %ebx
jmp 0x20a4e8
movq 0x597b0d(%rip), %rax    # 0x7a1fd8
movq (%rax), %rdi
leaq 0x3ea9d8(%rip), %rsi    # 0x5f4ead
leaq 0x3eab24(%rip), %rdx    # 0x5f5000
xorl %ebx, %ebx
movq %r13, %rcx
xorl %eax, %eax
callq 0x19e180
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq