// File: /workspace/github_c_makefile_star2_O3/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, 0x28(%rsp)
movq %rcx, 0xb0(%rsp)
movq %rdx, %r15
movl %esi, %ebx
movslq %esi, %r14
movl %edi, 0x18(%rsp)
testl %edi, %edi
je 0x3762
leaq (,%r14,8), %rax
leaq (%rax,%rax,2), %rdi
callq 0x20e0
movq %rax, %r15
movq %r14, 0x8(%rsp)
movq 0x4a12(%rip), %rdx      # 0x8180
movq 0x4863(%rip), %r8       # 0x7fd8
movq %r15, %rdi
movl %ebx, %esi
xorl %ecx, %ecx
callq 0x21c0
movl 0x18(%rsp), %r12d
movslq %r12d, %rax
movq %rax, 0xa8(%rsp)
leaq (%rax,%rax,2), %rax
movq %r15, 0x20(%rsp)
leaq (%r15,%rax,8), %rbp
movslq 0x10(%rbp), %rdi
movl $0x8, %esi
callq 0x36f4
movq %rax, 0xc0(%rsp)
movslq (%rbp), %rdi
shlq $0x3, %rdi
callq 0x36e2
movq %rax, %r15
movslq 0x8(%rbp), %rdi
shlq $0x2, %rdi
callq 0x36e2
movq %rax, 0x98(%rsp)
movslq 0x8(%rbp), %rdi
shlq $0x2, %rdi
callq 0x36e2
movq %rax, 0x40(%rsp)
movslq 0x8(%rbp), %rdi
shlq $0x3, %rdi
callq 0x36e2
movq %rax, 0x80(%rsp)
movl %ebx, %r14d
testl %r12d, %r12d
movq %rbp, 0x38(%rsp)
movl %ebx, 0x1c(%rsp)
je 0x381b
movq 0x8(%rsp), %r12
jmp 0x38c1
movslq (%rbp), %rdi
shlq $0x3, %rdi
callq 0x36e2
movq %rax, 0xa0(%rsp)
movslq %ebx, %r12
leaq (,%r12,4), %rbp
movq %rbp, %rdi
callq 0x36e2
movq %rax, 0x70(%rsp)
movq %rbp, %rdi
callq 0x36e2
movq %rax, 0x68(%rsp)
movq %rbp, %rdi
callq 0x36e2
movq %rax, 0x78(%rsp)
movq %rbp, %rdi
callq 0x36e2
testl %ebx, %ebx
movq %rax, 0x90(%rsp)
jle 0x3930
movq 0x20(%rsp), %rcx
leaq 0x14(%rcx), %r9
xorl %ecx, %ecx
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdi
movq 0x78(%rsp), %r8
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, %r14
jne 0x3894
movq 0x38(%rsp), %rbp
movq %r12, 0x8(%rsp)
leaq (,%r12,8), %rdi
movq %rdi, 0x60(%rsp)
callq 0x36e2
movq %rax, 0x48(%rsp)
testl %ebx, %ebx
setg %al
movl %eax, 0x10(%rsp)
jle 0x3926
movl 0x18(%rsp), %r12d
movq 0x20(%rsp), %rax
leaq 0x10(%rax), %rbp
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0x3918
movslq (%rbp), %rdi
testq %rdi, %rdi
jle 0x3918
shlq $0x2, %rdi
callq 0x36e2
movq 0x48(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
addq $0x18, %rbp
cmpq %rbx, %r14
jne 0x38f8
jmp 0x3954
movl $0x0, 0x10(%rsp)
jmp 0x3959
movq %r12, 0x8(%rsp)
leaq (,%r12,8), %rdi
movq %rdi, 0x60(%rsp)
callq 0x36e2
movq %rax, 0x48(%rsp)
movl $0x0, 0x10(%rsp)
movq 0x38(%rsp), %rbp
movslq 0x14(%rbp), %rax
leaq (%r15,%rax,8), %r8
movl 0x10(%rbp), %r9d
subq $0x8, %rsp
xorl %r12d, %r12d
movq 0x465d(%rip), %rcx      # 0x7fd0
movq 0x128(%rsp), %rdi
movq 0x78(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x464c(%rip), %r13      # 0x7fd8
pushq %r13
pushq %r12
pushq %rcx
callq 0x2120
addq $0x20, %rsp
movl 0x8(%rbp), %r9d
subq $0x8, %rsp
movq 0x45ff(%rip), %rcx      # 0x7fa8
movq 0x30(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x98(%rsp), %rdx
movq 0x48(%rsp), %rbx
movq %rbx, %r8
pushq %r13
pushq %r12
pushq %rcx
callq 0x2120
addq $0x20, %rsp
movl $0x4, %esi
movq 0x8(%rsp), %rdi
callq 0x36f4
movq %rax, 0x28(%rsp)
movslq (%rbp), %rdi
callq 0x36e2
cmpl %r12d, 0x8(%rbp)
jle 0x3ab0
movq %rax, %r13
addq $0x14, 0x20(%rsp)
xorl %r12d, %r12d
movq %rax, 0x50(%rsp)
movq %rbp, %rax
movl (%rbx,%r12,4), %ebp
movl 0x10(%rax), %edx
movl 0x14(%rax), %esi
movl %ebp, %edi
callq 0x3706
testb %al, %al
jne 0x3a96
movslq %ebp, %rax
cmpb $0x0, (%r13,%rax)
jg 0x3a96
movq %rax, 0x58(%rsp)
cmpb $0x0, 0x10(%rsp)
je 0x4014
movq 0x20(%rsp), %rbx
xorl %r13d, %r13d
movl -0x4(%rbx), %edx
movl (%rbx), %esi
movl %ebp, %edi
callq 0x3706
testb %al, %al
jne 0x3a68
incq %r13
addq $0x18, %rbx
cmpq %r13, %r14
jne 0x3a47
jmp 0x4014
movl %r13d, %eax
movq 0x48(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
movq 0x28(%rsp), %rdi
movslq (%rdi,%rax,4), %rdx
leal 0x1(%rdx), %esi
movl %esi, (%rdi,%rax,4)
movl %ebp, (%rcx,%rdx,4)
movq 0x50(%rsp), %r13
movq 0x58(%rsp), %rax
movb $0x1, (%r13,%rax)
incq %r12
movq 0x38(%rsp), %rbp
movslq 0x8(%rbp), %rax
cmpq %rax, %r12
movq 0x40(%rsp), %rbx
jl 0x3a0c
movq 0x60(%rsp), %r12
movq %r12, %rdi
callq 0x36e2
movq %rax, 0x58(%rsp)
movq %r12, %rdi
callq 0x36e2
movq %rax, 0x20(%rsp)
movq %r12, %rdi
callq 0x36e2
movq %rax, 0x50(%rsp)
cmpb $0x0, 0x10(%rsp)
je 0x3c3d
xorl %ebx, %ebx
movq 0x28(%rsp), %rax
movslq (%rax,%rbx,4), %rdi
testq %rdi, %rdi
jle 0x3b09
shlq $0x3, %rdi
callq 0x36e2
movq 0x50(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
cmpq %rbx, %r14
jne 0x3ae9
movl $0x4, %esi
movq 0x8(%rsp), %rdi
callq 0x36f4
movq %rax, %rbx
movl $0x0, 0x8(%rsp)
cmpb $0x0, 0x10(%rsp)
je 0x3c57
movq %rbx, 0x10(%rsp)
movl 0x18(%rsp), %ecx
xorl %ebx, %ebx
movq 0x4458(%rip), %rdx      # 0x7fa0
movq 0x58(%rsp), %r12
movq 0x20(%rsp), %rbp
movl $0x0, 0x8(%rsp)
movq %rcx, 0xc8(%rsp)
movq 0x28(%rsp), %r13
cmpq %rbx, %rcx
je 0x3c02
movq 0x28(%rsp), %rax
cmpl $0x0, (%rax,%rbx,4)
je 0x3c02
movq 0x10(%rsp), %rax
movl $0x1, (%rax,%rbx,4)
incl 0x8(%rsp)
movq 0x48(%rsp), %rax
movq (%rax,%rbx,8), %rdi
movl (%r13,%rbx,4), %esi
subq $0x8, %rsp
movq 0x4400(%rip), %rdx      # 0x7fa8
movl %ebx, %ecx
xorl %r8d, %r8d
movq 0x4424(%rip), %r9       # 0x7fd8
pushq %r12
callq 0x20d0
addq $0x10, %rsp
movq 0x50(%rsp), %rax
movq (%rax,%rbx,8), %rdi
movl (%r13,%rbx,4), %esi
subq $0x8, %rsp
movq 0x43f8(%rip), %rdx      # 0x7fd0
movl %ebx, %ecx
movl $0x1, %r8d
movq 0x43f1(%rip), %r9       # 0x7fd8
pushq %rbp
callq 0x20b0
movq 0x43ac(%rip), %rdx      # 0x7fa0
movq 0xd8(%rsp), %rcx
addq $0x10, %rsp
jmp 0x3c14
movq 0x20(%rsp), %rax
movq %rdx, (%rax,%rbx,8)
movq 0x58(%rsp), %rax
movq %rdx, (%rax,%rbx,8)
incq %rbx
addq $0x8, %rbp
addq $0x8, %r12
cmpq %rbx, %r14
jne 0x3b67
movq 0x38(%rsp), %rbp
movl 0x1c(%rsp), %edx
movq 0x60(%rsp), %r12
movq 0x10(%rsp), %rbx
jmp 0x3c5b
movl $0x4, %esi
movq 0x8(%rsp), %rdi
callq 0x36f4
movq %rax, %rbx
movl $0x0, 0x8(%rsp)
movl 0x1c(%rsp), %edx
cmpl $0x0, 0x18(%rsp)
je 0x3c79
subq $0x8, %rsp
movq 0x433b(%rip), %rcx      # 0x7fa8
movq 0x436c(%rip), %r8       # 0x7fe0
movq %rbx, %rdi
jmp 0x3c90
subq $0x8, %rsp
movq 0x4324(%rip), %rcx      # 0x7fa8
movq 0x4355(%rip), %r8       # 0x7fe0
movl $0x1, %edi
movq %rbx, %rsi
xorl %r9d, %r9d
pushq 0x433c(%rip)            # 0x7fd8
callq 0x21d0
addq $0x10, %rsp
movq 0xa8(%rsp), %rax
leaq (%rbx,%rax,4), %r13
movq 0x42f0(%rip), %rdx      # 0x7fa8
movq %rbx, %rdi
movl $0x1, %esi
movq %r13, %rcx
movl $0x1, %r8d
movq %rdx, %r9
pushq 0x4306(%rip)            # 0x7fd8
pushq $0x0
callq 0x2200
addq $0x10, %rsp
movslq 0x10(%rbp), %rdi
shlq $0x2, %rdi
callq 0x36e2
movq %rax, %rbp
movq %r12, %rdi
callq 0x36e2
movq %r13, 0x10(%rsp)
cmpl $0x0, (%r13)
jle 0x3ddf
movq %rax, %r14
xorl %r12d, %r12d
movq 0x42c6(%rip), %rbx      # 0x7fd8
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %esi, %esi
movq %rbx, %rdx
leaq 0xd0(%rsp), %r13
movq %r13, %rcx
callq 0x2190
movq %r13, %rdi
movq 0x4272(%rip), %r13      # 0x7fa8
movq %r13, %rsi
leaq 0x34(%rsp), %rdx
callq 0x2050
movslq 0x34(%rsp), %rdi
shlq $0x3, %rdi
callq 0x36e2
movq %rax, (%r14,%r12,8)
movl 0x34(%rsp), %esi
movl 0xd0(%rsp), %ecx
subq $0x8, %rsp
movq %rbp, %rdi
movq %r13, %rdx
xorl %r8d, %r8d
movq %rbx, %r9
pushq $0x0
callq 0x21a0
addq $0x10, %rsp
movslq 0x34(%rsp), %rsi
movq (%r14,%r12,8), %rdi
testq %rsi, %rsi
jle 0x3da3
xorl %eax, %eax
movslq (%rbp,%rax,4), %rcx
movsd (%r15,%rcx,8), %xmm0
movsd %xmm0, (%rdi,%rax,8)
incq %rax
cmpq %rax, %rsi
jne 0x3d8b
movl 0xd0(%rsp), %ecx
subq $0x8, %rsp
movq 0x421b(%rip), %rdx      # 0x7fd0
movl $0x1, %r8d
movq %rbx, %r9
pushq 0x60(%rsp)
callq 0x20d0
addq $0x10, %rsp
incq %r12
movq 0x10(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %r12
jl 0x3d12
movq 0x38(%rsp), %r12
movl 0x8(%r12), %r9d
subq $0x8, %rsp
xorl %r10d, %r10d
movq 0xb8(%rsp), %rdi
movq 0x80(%rsp), %rbp
movq %rbp, %rsi
movq 0x98(%rsp), %rbx
movq %rbx, %rdx
movq 0x4193(%rip), %rcx      # 0x7fa8
movq 0xa0(%rsp), %r14
movq %r14, %r8
movq 0x41b1(%rip), %r13      # 0x7fd8
pushq %r13
pushq %r10
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 0x417d(%rip), %rcx      # 0x7fd0
movq 0x88(%rsp), %r8
pushq %r13
xorl %eax, %eax
pushq %rax
pushq %rcx
callq 0x2120
addq $0x20, %rsp
movl 0x8(%r12), %eax
testl %eax, %eax
movq 0xc0(%rsp), %rbp
movq 0x40(%rsp), %rsi
jle 0x3ed9
xorl %ebx, %ebx
movl (%rsi,%rbx,4), %edi
movl 0x10(%r12), %edx
movl 0x14(%r12), %esi
callq 0x3706
movq 0x40(%rsp), %rsi
testb %al, %al
je 0x3ecc
movq 0x80(%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 0x3e82
cmpl $0x0, 0x8(%rsp)
jle 0x3f6c
xorl %r14d, %r14d
leaq 0x8c(%rsp), %rbx
movl 0x1c(%rsp), %edi
movq 0x20(%rsp), %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x2080
movslq 0x8c(%rsp), %rdx
cmpq $-0x7ffe, %rdx          # imm = 0x8002
je 0x4033
movq 0x28(%rsp), %rax
movslq (%rax,%rdx,4), %rax
testq %rax, %rax
jle 0x3f50
movq 0x50(%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 0x3f39
incl %r14d
cmpl 0x8(%rsp), %r14d
jne 0x3eef
movl 0x8(%r12), %eax
movq 0x98(%rsp), %r14
movq 0x40(%rsp), %rsi
testl %eax, %eax
jle 0x3fc9
xorl %ebx, %ebx
movl (%rsi,%rbx,4), %edi
movl 0x10(%r12), %edx
movl 0x14(%r12), %esi
callq 0x3706
movq 0x40(%rsp), %rsi
testb %al, %al
jne 0x3fbc
movq 0x80(%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 0x3f72
movl 0x10(%r12), %esi
subq $0x8, %rsp
movq %rbp, %rdi
movq 0x3ff4(%rip), %rdx      # 0x7fd0
movq 0xa8(%rsp), %rbx
movq %rbx, %rcx
movq 0x78(%rsp), %r8
movq 0x70(%rsp), %r9
pushq %r13
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 0x1345(%rip), %rdi      # 0x5360
leaq 0x1348(%rip), %rsi      # 0x536a
leaq 0x1352(%rip), %rcx      # 0x537b
movl $0x6a, %edx
callq 0x20c0
leaq 0x139a(%rip), %rdi      # 0x53d4
leaq 0x1329(%rip), %rsi      # 0x536a
leaq 0x1333(%rip), %rcx      # 0x537b
movl $0xc5, %edx
callq 0x20c0