// File: /workspace/github_c_makefile_star2_O1/kkanellis[P]matvec-sparse/matvec_mpi_p2p.c
// Function: mat_vec_mult_parallel
double* mat_vec_mult_parallel(int rank, int nprocs, proc_info_t *all_proc_info,
                            int *buf_i_idx, int *buf_j_idx, double *buf_values, double *buf_x)
{
    proc_info_t *proc_info; /* info about submatrix; different per process */
    double *res;            /* result of multiplication res = A*x */

    /***** MPI MASTER (root) process only ******/
    int *nz_count, *nz_offset,    /* auxilliary arrays used for Scatterv/Gatherv */
        *row_count, *row_offset;

    /* scatter to processors all info that will be needed */
    if (rank == MASTER)
        proc_info = all_proc_info;
    else
        proc_info = (proc_info_t *)malloc( nprocs * sizeof(proc_info_t) );
    MPI_Bcast(proc_info, nprocs, proc_info_type, MASTER, MPI_COMM_WORLD);

    /* allocate memory for vectors and submatrixes */
    double *y = (double *)calloc_or_exit( proc_info[rank].row_count, sizeof(double) );
    double *x = (double *)malloc_or_exit( proc_info[rank].N * sizeof(double) );
    int *i_idx = (int *)malloc_or_exit( proc_info[rank].nz_count * sizeof(int) );
    int *j_idx = (int *)malloc_or_exit( proc_info[rank].nz_count * sizeof(int) );
    double *values = (double *)malloc_or_exit( proc_info[rank].nz_count * sizeof(double) );
    if (rank == MASTER) {
        res = (double *)malloc_or_exit( proc_info[rank].N * sizeof(double) );
    }
    
    /* process auxilliary arrays for scatterv/gatherv ops */
    if (rank == MASTER) { 
        row_count = (int *)malloc_or_exit( nprocs * sizeof(int) );
        row_offset = (int *)malloc_or_exit( nprocs * sizeof(int) );
        nz_count = (int *)malloc_or_exit( nprocs * sizeof(int) );
        nz_offset = (int *)malloc_or_exit( nprocs * sizeof(int) );

        for (int p = 0; p < nprocs; p++) {
            row_count[p] = proc_info[p].row_count;
            row_offset[p] = proc_info[p].row_start_idx;
            nz_count[p] = proc_info[p].nz_count;
            nz_offset[p] = proc_info[p].nz_start_idx;
        }
    }
        
    /* allocate buffers for requests sending */
    int **send_buf = (int **)malloc_or_exit( nprocs * sizeof(int*) );
    for (int i =0; i < nprocs; i++) {
        if (i != rank && proc_info[i].row_count > 0)
            send_buf[i] = (int *)malloc_or_exit( proc_info[i].row_count * sizeof(int) );
    }

    /* scatter x vector to processes */
    MPI_Scatterv(buf_x, row_count, row_offset, MPI_DOUBLE, &x[ proc_info[rank].row_start_idx ], 
                proc_info[rank].row_count, MPI_DOUBLE, MASTER, MPI_COMM_WORLD);

    /* scatter j_idx elements to processes */
    MPI_Scatterv(buf_j_idx, nz_count, nz_offset, MPI_INT, j_idx, 
                    proc_info[rank].nz_count, MPI_INT, MASTER, MPI_COMM_WORLD);

    int *to_send = (int *)calloc_or_exit( nprocs, sizeof(int) );    /* # of req to each proc */
    char* map = (char *)malloc_or_exit( proc_info[rank].N * sizeof(char) );

    /* build sending blocks to processors */
    int dest, col;
    for (int i = 0; i < proc_info[rank].nz_count; i++) {
        col = j_idx[i];

        /* check whether I need to send a request */
        if ( in_range(col, proc_info[rank].row_start_idx, proc_info[rank].row_count) ||
                map[col] > 0) 
            continue;

        /* search which process has the element
         * NOTE: Due to small number or processes, serial search is faster
         */
        dest = -1;
        for (int p = 0; p < nprocs; p++) {
            if ( in_range(col, proc_info[p].row_start_idx, proc_info[p].row_count) ) {
                dest = p;
                break;
            }
        }
        assert( dest >= 0 );

        /* insert new request */
        send_buf[dest][ to_send[dest]++ ] = col;
        map[col] = 1;
    }

    /* MPI request storage */
    MPI_Request *send_reqs = (MPI_Request*)malloc_or_exit( nprocs * sizeof(MPI_Request) );
    MPI_Request *recv_reqs = (MPI_Request*)malloc_or_exit( nprocs * sizeof(MPI_Request) );

    /* receiving blocks storage */
    double **recv_buf = (double **)malloc_or_exit( nprocs * sizeof(double*) );
    for (int p =0; p < nprocs; p++) {
        if (to_send[p] > 0)
            recv_buf[p] = (double *)malloc_or_exit( to_send[p] * sizeof(double) );
    }

    /* sending requests to processes in blocks */
    int req_made = 0;
    int *expect = (int *)calloc_or_exit( nprocs, sizeof(int) );
    for (int p = 0; p < nprocs; p++) {
        /* need to send to this proc? */
        if (p == rank || to_send[p] == 0) {
            send_reqs[p] = recv_reqs[p] = MPI_REQUEST_NULL;
            continue;
        }
        debug("[%d] Sending requests to process %2d \t[%5d]\n", rank, p, to_send[p]);

        /* logistics */
        expect[p] = 1;
        req_made++;

        /* send the request */
        MPI_Isend(send_buf[p], to_send[p], MPI_INT, p, REQUEST_TAG, 
                    MPI_COMM_WORLD, &send_reqs[p]);
        /* recv the block (when it comes) */
        MPI_Irecv(recv_buf[p], to_send[p], MPI_DOUBLE, p, REPLY_TAG, 
                    MPI_COMM_WORLD, &recv_reqs[p]);
    }
    debug("[%d] Sent all requests! [%4d]\n", rank, req_made);

    /* notify the processes about the number of requests they should expect */
    if (rank == MASTER)
        MPI_Reduce(MPI_IN_PLACE, expect, nprocs, MPI_INT, MPI_SUM, MASTER, MPI_COMM_WORLD);
    else
        MPI_Reduce(expect, expect, nprocs, MPI_INT, MPI_SUM, MASTER, MPI_COMM_WORLD);
    MPI_Scatter(expect, 1, MPI_INT, &expect[rank], 1, MPI_INT, MASTER, MPI_COMM_WORLD);

    /**** reply to requests ****/
    int *reqs = (int *) malloc_or_exit( proc_info[rank].row_count * sizeof(int) ); 
    double **rep_buf = (double **)malloc_or_exit( nprocs * sizeof(double*) ); /* reply blocks storage */

    MPI_Status status;
    int req_count;
    for (int p = 0; p < expect[rank]; p++) {
        /* Wait until a request comes */
        MPI_Probe(MPI_ANY_SOURCE, REQUEST_TAG, MPI_COMM_WORLD, &status);
        MPI_Get_count(&status, MPI_INT, &req_count);
        rep_buf[p] = (double *)malloc_or_exit( req_count * sizeof(double) );

        /* fill rep_buf[p] with requested x elements */
        MPI_Recv(reqs, req_count, MPI_INT, status.MPI_SOURCE, REQUEST_TAG, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
        for (int i = 0; i < req_count; i++) {
            rep_buf[p][i] = x[ reqs[i] ];
        }
        
        /* send the requested block */
        MPI_Isend(rep_buf[p], req_count, MPI_DOUBLE, status.MPI_SOURCE, REPLY_TAG, MPI_COMM_WORLD, &send_reqs[0]);
        debug("[%d] Replying requests from process %2d \t[%5d]\n", rank, status.MPI_SOURCE, req_count);
    }
    debug("[%d] Replied to all requests! [%4d]\n", rank, to_send[rank]);
    
    /* scatter j_idx & values to processes */
    MPI_Scatterv(buf_i_idx, nz_count, nz_offset, MPI_INT, i_idx, 
                    proc_info[rank].nz_count, MPI_INT, MASTER, MPI_COMM_WORLD);
    MPI_Scatterv(buf_values, nz_count, nz_offset, MPI_DOUBLE, values, 
                    proc_info[rank].nz_count, MPI_DOUBLE, MASTER, MPI_COMM_WORLD);

    /* Local elements multiplication */
    for (int k = 0 ; k < proc_info[rank].nz_count; k++) {
        if ( in_range( j_idx[k], proc_info[rank].row_start_idx, proc_info[rank].row_count) ) {
            y[ i_idx[k] - proc_info[rank].row_start_idx ] += values[k] * x[ j_idx[k] ];
        }
    }

    /* wait for all blocks to arrive */
    int p;
    debug("[%d] Waiting for %d requests\n", rank, req_made);
    for (int q = 0; q < req_made; q++) {
        MPI_Waitany(nprocs, recv_reqs, &p, MPI_STATUS_IGNORE);
        assert(p != MPI_UNDEFINED);

        /* fill x array with new elements */
        for (int i = 0; i < to_send[p]; i++) 
            x[ send_buf[p][i] ] = recv_buf[p][i];
    }

    /* Global elements multiplication */ 
    for (int k = 0 ; k < proc_info[rank].nz_count; k++) {
        if ( !in_range( j_idx[k], proc_info[rank].row_start_idx, proc_info[rank].row_count) ) {
            y[ i_idx[k] - proc_info[rank].row_start_idx ] += values[k] * x[ j_idx[k] ];
        }
    }

    /* gather y elements from processes and save it to res */
    debug("[%d] Gathering results...\n", rank);
    MPI_Gatherv(y, proc_info[rank].row_count, MPI_DOUBLE, res, row_count, 
                row_offset, MPI_DOUBLE, MASTER, MPI_COMM_WORLD);

    /* return final result */
    return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %r9, 0xb8(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, 0xb0(%rsp)
movq %rdx, %r15
movl %esi, %ebp
movl %edi, %r14d
movslq %esi, %rbx
testl %edi, %edi
je 0x3749
leaq (,%rbx,8), %rax
leaq (%rax,%rax,2), %rdi
callq 0x20e0
movq %rax, %r15
movq %rbx, 0x8(%rsp)
movq 0x4a2b(%rip), %rdx      # 0x8180
movq 0x487c(%rip), %r8       # 0x7fd8
movq %r15, %rdi
movl %ebp, %esi
xorl %ecx, %ecx
callq 0x21c0
movslq %r14d, %rax
movq %rax, 0xa8(%rsp)
leaq (%rax,%rax,2), %rax
movq %r15, 0x10(%rsp)
leaq (%r15,%rax,8), %r12
movslq 0x10(%r12), %rdi
movl $0x8, %esi
callq 0x36dd
movq %rax, %rbx
movslq (%r12), %rdi
shlq $0x3, %rdi
callq 0x36cb
movq %rax, %r15
movslq 0x8(%r12), %rdi
shlq $0x2, %rdi
callq 0x36cb
movq %rax, 0x88(%rsp)
movslq 0x8(%r12), %rdi
shlq $0x2, %rdi
callq 0x36cb
movq %rax, 0x40(%rsp)
movslq 0x8(%r12), %rdi
shlq $0x3, %rdi
callq 0x36cb
movq %rax, 0x70(%rsp)
testl %r14d, %r14d
jne 0x37f8
movslq (%r12), %rdi
shlq $0x3, %rdi
callq 0x36cb
movq %rax, 0xa0(%rsp)
movl %ebp, %eax
movq %rax, 0x18(%rsp)
testl %r14d, %r14d
movl %r14d, %r13d
jne 0x389a
movq 0x8(%rsp), %rax
leaq (,%rax,4), %r14
movq %r14, %rdi
callq 0x36cb
movq %rax, 0x58(%rsp)
movq %r14, %rdi
callq 0x36cb
movq %rax, 0x50(%rsp)
movq %r14, %rdi
callq 0x36cb
movq %rax, 0x60(%rsp)
movq %r14, %rdi
callq 0x36cb
testl %ebp, %ebp
movq %rax, 0x80(%rsp)
jle 0x389a
movq 0x10(%rsp), %rcx
leaq 0x14(%rcx), %r9
xorl %ecx, %ecx
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdi
movq 0x60(%rsp), %r8
movq 0x18(%rsp), %r10
movl -0x4(%r9), %edx
movl %edx, (%rsi,%rcx,4)
movl (%r9), %edx
movl %edx, (%rdi,%rcx,4)
movl -0xc(%r9), %edx
movl %edx, (%r8,%rcx,4)
movl -0x8(%r9), %edx
movl %edx, (%rax,%rcx,4)
incq %rcx
addq $0x18, %r9
cmpq %rcx, %r10
jne 0x3872
movq %rbx, 0xc0(%rsp)
movq 0x120(%rsp), %r14
movq 0x8(%rsp), %rax
leaq (,%rax,8), %rdi
movq %rdi, 0x98(%rsp)
callq 0x36cb
movq %rax, 0x48(%rsp)
movl %r13d, 0x78(%rsp)
movl %r13d, %ecx
movl %ebp, 0x4(%rsp)
testl %ebp, %ebp
movq 0x18(%rsp), %r13
movq %rcx, 0x68(%rsp)
jle 0x391f
movq 0x10(%rsp), %rax
leaq 0x10(%rax), %rbp
xorl %ebx, %ebx
cmpq %rbx, %rcx
je 0x3913
movslq (%rbp), %rdi
testq %rdi, %rdi
jle 0x3913
shlq $0x2, %rdi
callq 0x36cb
movq 0x48(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
movq 0x68(%rsp), %rcx
incq %rbx
addq $0x18, %rbp
cmpq %rbx, %r13
jne 0x38ee
movslq 0x14(%r12), %rax
leaq (%r15,%rax,8), %r8
movl 0x10(%r12), %r9d
subq $0x8, %rsp
xorl %ebp, %ebp
movq 0x4696(%rip), %rcx      # 0x7fd0
movq %r14, %rdi
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x468a(%rip), %r14      # 0x7fd8
pushq %r14
pushq %rbp
pushq %rcx
callq 0x2120
addq $0x20, %rsp
movl 0x8(%r12), %r9d
subq $0x8, %rsp
movq 0x463d(%rip), %rcx      # 0x7fa8
movq 0x28(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq 0x48(%rsp), %rbx
movq %rbx, %r8
pushq %r14
pushq %rbp
pushq %rcx
callq 0x2120
addq $0x20, %rsp
movl $0x4, %esi
movq 0x8(%rsp), %rdi
callq 0x36dd
movq %rax, 0x20(%rsp)
movslq (%r12), %rdi
callq 0x36cb
movq %rax, 0x38(%rsp)
cmpl %ebp, 0x8(%r12)
movl 0x4(%rsp), %ebp
jle 0x3a9c
addq $0x14, 0x10(%rsp)
xorl %r14d, %r14d
movl (%rbx,%r14,4), %ebx
movl 0x10(%r12), %edx
movl 0x14(%r12), %esi
movl %ebx, %edi
callq 0x36ef
testb %al, %al
jne 0x3a86
movslq %ebx, %r8
movq 0x38(%rsp), %rax
cmpb $0x0, (%rax,%r8)
jg 0x3a86
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testl %ebp, %ebp
jle 0x3a57
movq %r8, 0x30(%rsp)
movq 0x10(%rsp), %r13
xorl %ebp, %ebp
movl -0x4(%r13), %edx
movl (%r13), %esi
movl %ebx, %edi
callq 0x36ef
testb %al, %al
jne 0x3a47
incq %rbp
addq $0x18, %r13
cmpq %rbp, 0x18(%rsp)
jne 0x3a11
movl 0x4(%rsp), %ebp
movq 0x18(%rsp), %r13
movq 0x30(%rsp), %r8
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x3a57
movl %ebp, %eax
movl 0x4(%rsp), %ebp
movq 0x18(%rsp), %r13
movq 0x30(%rsp), %r8
testl %eax, %eax
js 0x3feb
movl %eax, %eax
movq 0x48(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq 0x20(%rsp), %rdi
movslq (%rdi,%rax,4), %rdx
leal 0x1(%rdx), %esi
movl %esi, (%rdi,%rax,4)
movl %ebx, (%rcx,%rdx,4)
movq 0x38(%rsp), %rax
movb $0x1, (%rax,%r8)
incq %r14
movslq 0x8(%r12), %rax
cmpq %rax, %r14
movq 0x40(%rsp), %rbx
jl 0x39cc
movq 0x98(%rsp), %rbx
movq %rbx, %rdi
callq 0x36cb
movq %rax, 0x38(%rsp)
movq %rbx, %rdi
callq 0x36cb
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
callq 0x36cb
movq %rax, 0x30(%rsp)
testl %ebp, %ebp
jle 0x3af9
xorl %ebx, %ebx
movq 0x20(%rsp), %rax
movslq (%rax,%rbx,4), %rdi
testq %rdi, %rdi
jle 0x3af1
shlq $0x3, %rdi
callq 0x36cb
movq 0x30(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
cmpq %rbx, %r13
jne 0x3ad1
movl $0x4, %esi
movq 0x8(%rsp), %rdi
callq 0x36dd
movq %rax, %rdx
testl %ebp, %ebp
movq %r12, 0x90(%rsp)
jle 0x3c09
xorl %ebx, %ebx
movq 0x447c(%rip), %r12      # 0x7fa0
movq 0x38(%rsp), %rbp
movq 0x10(%rsp), %r14
movl $0x0, 0x8(%rsp)
movq 0x68(%rsp), %rcx
movq %rdx, 0xc8(%rsp)
cmpq %rbx, %rcx
je 0x3be1
movq 0x20(%rsp), %rax
cmpl $0x0, (%rax,%rbx,4)
je 0x3be1
movl $0x1, (%rdx,%rbx,4)
incl 0x8(%rsp)
movq 0x48(%rsp), %rax
movq (%rax,%rbx,8), %rdi
movq 0x20(%rsp), %r13
movl (%r13,%rbx,4), %esi
subq $0x8, %rsp
movq 0x4424(%rip), %rdx      # 0x7fa8
movl %ebx, %ecx
xorl %r8d, %r8d
movq 0x4448(%rip), %r9       # 0x7fd8
pushq %rbp
callq 0x20d0
addq $0x10, %rsp
movq 0x30(%rsp), %rax
movq (%rax,%rbx,8), %rdi
movl (%r13,%rbx,4), %esi
movq 0x18(%rsp), %r13
subq $0x8, %rsp
movq 0x4418(%rip), %rdx      # 0x7fd0
movl %ebx, %ecx
movl $0x1, %r8d
movq 0x4411(%rip), %r9       # 0x7fd8
pushq %r14
callq 0x20b0
movq 0xd8(%rsp), %rdx
movq 0x78(%rsp), %rcx
addq $0x10, %rsp
jmp 0x3bf3
movq 0x10(%rsp), %rax
movq %r12, (%rax,%rbx,8)
movq 0x38(%rsp), %rax
movq %r12, (%rax,%rbx,8)
incq %rbx
addq $0x8, %r14
addq $0x8, %rbp
cmpq %rbx, %r13
jne 0x3b43
jmp 0x3c11
movl $0x0, 0x8(%rsp)
cmpl $0x0, 0x78(%rsp)
je 0x3c2f
subq $0x8, %rsp
movq 0x4385(%rip), %rcx      # 0x7fa8
movq 0x43b6(%rip), %r8       # 0x7fe0
movq %rdx, %rdi
jmp 0x3c46
subq $0x8, %rsp
movq 0x436e(%rip), %rcx      # 0x7fa8
movq 0x439f(%rip), %r8       # 0x7fe0
movl $0x1, %edi
movq %rdx, %rbx
movq %rdx, %rsi
movl 0xc(%rsp), %edx
xorl %r9d, %r9d
movq 0x437e(%rip), %r14      # 0x7fd8
pushq %r14
callq 0x21d0
addq $0x10, %rsp
movq 0xa8(%rsp), %r12
leaq (%rbx,%r12,4), %rcx
movq %rcx, 0x18(%rsp)
movq 0x432b(%rip), %rdx      # 0x7fa8
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %r8d
movq %rdx, %r9
pushq %r14
pushq $0x0
callq 0x2200
addq $0x10, %rsp
movq 0x90(%rsp), %rax
movslq 0x10(%rax), %rdi
shlq $0x2, %rdi
callq 0x36cb
movq %rax, %rbp
movq 0x98(%rsp), %rdi
callq 0x36cb
cmpl $0x0, (%rbx,%r12,4)
jle 0x3dab
movq %rax, %r13
xorl %ebx, %ebx
movq 0x4301(%rip), %r14      # 0x7fd8
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %esi, %esi
movq %r14, %rdx
leaq 0xd0(%rsp), %r12
movq %r12, %rcx
callq 0x2190
movq %r12, %rdi
movq 0x42ad(%rip), %r12      # 0x7fa8
movq %r12, %rsi
leaq 0x2c(%rsp), %rdx
callq 0x2050
movslq 0x2c(%rsp), %rdi
shlq $0x3, %rdi
callq 0x36cb
movq %rax, (%r13,%rbx,8)
movl 0x2c(%rsp), %esi
movl 0xd0(%rsp), %ecx
subq $0x8, %rsp
movq %rbp, %rdi
movq %r12, %rdx
xorl %r8d, %r8d
movq %r14, %r9
pushq $0x0
callq 0x21a0
addq $0x10, %rsp
movslq 0x2c(%rsp), %rsi
testq %rsi, %rsi
jle 0x3d6a
movq (%r13,%rbx,8), %rax
xorl %ecx, %ecx
movslq (%rbp,%rcx,4), %rdx
movsd (%r15,%rdx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %rsi
jne 0x3d52
movq (%r13,%rbx,8), %rdi
movl 0xd0(%rsp), %ecx
subq $0x8, %rsp
movq 0x424f(%rip), %rdx      # 0x7fd0
movl $0x1, %r8d
movq %r14, %r9
pushq 0x40(%rsp)
callq 0x20d0
addq $0x10, %rsp
incq %rbx
movq 0x18(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %rbx
jl 0x3cd7
movq 0x90(%rsp), %r12
movl 0x8(%r12), %r9d
subq $0x8, %rsp
xorl %eax, %eax
movq 0xb8(%rsp), %rdi
movq 0x68(%rsp), %rbp
movq %rbp, %rsi
movq 0x88(%rsp), %rbx
movq %rbx, %rdx
movq 0x41c8(%rip), %rcx      # 0x7fa8
movq 0x90(%rsp), %r14
movq %r14, %r8
movq 0x41e6(%rip), %r13      # 0x7fd8
pushq %r13
pushq %rax
pushq %rcx
callq 0x2120
addq $0x20, %rsp
movl 0x8(%r12), %r9d
subq $0x8, %rsp
movq 0xc0(%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq 0x41b3(%rip), %rcx      # 0x7fd0
movq 0x78(%rsp), %r8
pushq %r13
xorl %ebx, %ebx
pushq %rbx
pushq %rcx
callq 0x2120
addq $0x20, %rsp
cmpl %ebx, 0x8(%r12)
movq 0xc0(%rsp), %rbp
movq 0x40(%rsp), %rsi
jle 0x3e9b
xorl %ebx, %ebx
movl (%rsi,%rbx,4), %edi
movl 0x10(%r12), %edx
movl 0x14(%r12), %esi
callq 0x36ef
movq 0x40(%rsp), %rsi
testb %al, %al
je 0x3e8e
movq 0x70(%rsp), %rax
movsd (%rax,%rbx,8), %xmm0
movslq (%rsi,%rbx,4), %rax
movslq (%r14,%rbx,4), %rcx
movslq 0x14(%r12), %rdx
mulsd (%r15,%rax,8), %xmm0
subq %rdx, %rcx
addsd (%rbp,%rcx,8), %xmm0
movsd %xmm0, (%rbp,%rcx,8)
incq %rbx
movslq 0x8(%r12), %rax
cmpq %rax, %rbx
jl 0x3e47
cmpl $0x0, 0x8(%rsp)
jle 0x3f12
xorl %r14d, %r14d
leaq 0x7c(%rsp), %rbx
movl 0x4(%rsp), %edi
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x2080
movslq 0x7c(%rsp), %rdx
cmpq $-0x7ffe, %rdx          # imm = 0x8002
je 0x3fcc
movq 0x20(%rsp), %rax
movslq (%rax,%rdx,4), %rax
testq %rax, %rax
jle 0x3f08
movq 0x30(%rsp), %rcx
movq (%rcx,%rdx,8), %rcx
movq 0x48(%rsp), %rsi
movq (%rsi,%rdx,8), %rdx
xorl %esi, %esi
movsd (%rcx,%rsi,8), %xmm0
movslq (%rdx,%rsi,4), %rdi
movsd %xmm0, (%r15,%rdi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x3ef1
incl %r14d
cmpl 0x8(%rsp), %r14d
jne 0x3eaa
cmpl $0x0, 0x8(%r12)
movq 0x88(%rsp), %r14
movq 0x40(%rsp), %rsi
jle 0x3f7d
xorl %ebx, %ebx
movl (%rsi,%rbx,4), %edi
movl 0x10(%r12), %edx
movl 0x14(%r12), %esi
callq 0x36ef
movq 0x40(%rsp), %rsi
testb %al, %al
jne 0x3f70
movq 0x70(%rsp), %rax
movsd (%rax,%rbx,8), %xmm0
movslq (%rsi,%rbx,4), %rax
movslq (%r14,%rbx,4), %rcx
movslq 0x14(%r12), %rdx
mulsd (%r15,%rax,8), %xmm0
subq %rdx, %rcx
addsd (%rbp,%rcx,8), %xmm0
movsd %xmm0, (%rbp,%rcx,8)
incq %rbx
movslq 0x8(%r12), %rax
cmpq %rax, %rbx
jl 0x3f29
movl 0x10(%r12), %esi
subq $0x8, %rsp
movq %rbp, %rdi
movq 0x4040(%rip), %rdx      # 0x7fd0
movq 0xa8(%rsp), %rbx
movq %rbx, %rcx
movq 0x60(%rsp), %r8
movq 0x58(%rsp), %r9
pushq 0x402d(%rip)            # 0x7fd8
pushq $0x0
pushq %rdx
callq 0x2290
addq $0x20, %rsp
movq %rbx, %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x13e1(%rip), %rdi      # 0x53b4
leaq 0x1370(%rip), %rsi      # 0x534a
leaq 0x137a(%rip), %rcx      # 0x535b
movl $0xc5, %edx
callq 0x20c0
leaq 0x134e(%rip), %rdi      # 0x5340
leaq 0x1351(%rip), %rsi      # 0x534a
leaq 0x135b(%rip), %rcx      # 0x535b
movl $0x6a, %edx
callq 0x20c0