// File: /workspace/github_c_makefile_star2_O2/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, 0xc8(%rsp)
movq %r8, 0x18(%rsp)
movq %rcx, 0xc0(%rsp)
movq %rdx, %r14
movl %esi, %ebp
movl %edi, %r12d
movslq %esi, %rbx
testl %edi, %edi
je 0x3601
imulq $0x18, %rbx, %rdi
callq 0x20e0
movq %rax, %r14
movq %rbx, 0x28(%rsp)
movq 0x3b7b(%rip), %rdx      # 0x7188
movq 0x39c4(%rip), %r8       # 0x6fd8
xorl %ebx, %ebx
movq %r14, %rdi
movl %ebp, %esi
xorl %ecx, %ecx
callq 0x21d0
movslq %r12d, %rcx
movq %rcx, 0xb8(%rsp)
imulq $0x18, %rcx, %r15
leaq (%r14,%r15), %r13
movslq 0x10(%r14,%r15), %rdi
pushq $0x8
popq %rsi
callq 0x357d
movq %rax, 0xa8(%rsp)
movslq (%r14,%r15), %rdi
shlq $0x3, %rdi
callq 0x354c
movl %ebp, 0xc(%rsp)
movq %r14, %rbp
movq %rax, %r14
movslq 0x8(%rbp,%r15), %rdi
shlq $0x2, %rdi
callq 0x354c
movq %rax, 0x80(%rsp)
movslq 0x8(%rbp,%r15), %rdi
shlq $0x2, %rdi
callq 0x354c
movq %rax, 0x58(%rsp)
movslq 0x8(%rbp,%r15), %rdi
shlq $0x3, %rdi
callq 0x354c
movq %rax, 0x78(%rsp)
testl %r12d, %r12d
movq %r13, 0x40(%rsp)
movl %r12d, 0x54(%rsp)
movq %rbp, 0x30(%rsp)
je 0x36c4
movl 0xc(%rsp), %eax
testl %eax, %eax
cmovgl %eax, %ebx
movq %rbx, 0x10(%rsp)
jmp 0x3779
movslq (%r13), %rdi
shlq $0x3, %rdi
callq 0x354c
movq %rax, 0xb0(%rsp)
movl 0xc(%rsp), %r12d
movslq %r12d, %rax
movq %rax, 0x28(%rsp)
leaq (,%rax,4), %r15
movq %r15, %rdi
callq 0x354c
movq %rax, 0x68(%rsp)
movq %r15, %rdi
callq 0x354c
movq %rax, 0x60(%rsp)
movq %r15, %rdi
callq 0x354c
movq %rax, %r13
movq %r15, %rdi
callq 0x354c
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %r8
testl %r12d, %r12d
movl $0x0, %ecx
cmovgl %r12d, %ecx
movq %rcx, 0x10(%rsp)
leaq 0x14(%rbp), %rdi
cmpq %rbx, 0x10(%rsp)
je 0x3764
movl -0x4(%rdi), %ecx
movl %ecx, (%r8,%rbx,4)
movl (%rdi), %ecx
movl %ecx, (%rdx,%rbx,4)
movl -0xc(%rdi), %ecx
movl %ecx, (%r13,%rbx,4)
movl -0x8(%rdi), %ecx
movl %ecx, (%rax,%rbx,4)
incq %rbx
addq $0x18, %rdi
jmp 0x373a
movq %rax, 0x90(%rsp)
movq %r13, 0x98(%rsp)
movl 0x54(%rsp), %r12d
movq 0x120(%rsp), %rbx
movq 0x28(%rsp), %rax
leaq (,%rax,8), %rdi
movq %rdi, 0xa0(%rsp)
callq 0x354c
movq %rax, %r15
movl %r12d, %ecx
movq 0x30(%rsp), %rax
leaq 0x10(%rax), %r13
xorl %ebp, %ebp
movq 0x40(%rsp), %r12
movq %rcx, 0x70(%rsp)
cmpq %rbp, 0x10(%rsp)
je 0x37e6
cmpq %rbp, %rcx
je 0x37dd
movslq (%r13), %rdi
testq %rdi, %rdi
jle 0x37dd
shlq $0x2, %rdi
callq 0x354c
movq 0x70(%rsp), %rcx
movq %rax, (%r15,%rbp,8)
incq %rbp
addq $0x18, %r13
jmp 0x37b6
movslq 0x14(%r12), %rax
leaq (%r14,%rax,8), %r8
movl 0x10(%r12), %r9d
subq $0x8, %rsp
movq 0x37d1(%rip), %rcx      # 0x6fd0
movq %rbx, %rdi
movq 0x70(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x37c5(%rip), %r13      # 0x6fd8
pushq %r13
pushq $0x0
pushq %rcx
callq 0x2120
addq $0x20, %rsp
movl 0x8(%r12), %r9d
subq $0x8, %rsp
movq 0x3777(%rip), %rcx      # 0x6fa8
movq 0x20(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movq 0x98(%rsp), %rdx
movq 0x60(%rsp), %rbx
movq %rbx, %r8
pushq %r13
pushq $0x0
pushq %rcx
callq 0x2120
addq $0x20, %rsp
pushq $0x4
popq %rsi
movq 0x28(%rsp), %rdi
callq 0x357d
movq %rax, 0x18(%rsp)
movslq (%r12), %rdi
callq 0x354c
movq %rax, 0x38(%rsp)
addq $0x14, 0x30(%rsp)
xorl %r13d, %r13d
movslq 0x8(%r12), %rax
cmpq %rax, %r13
jge 0x3924
movl (%rbx,%r13,4), %ebp
movl 0x10(%r12), %edx
movl 0x14(%r12), %esi
movl %ebp, %edi
callq 0x35ae
testb %al, %al
jne 0x3917
movslq %ebp, %rcx
movq 0x38(%rsp), %rax
cmpb $0x0, (%rax,%rcx)
jg 0x3917
movq %rcx, 0x48(%rsp)
movq 0x30(%rsp), %r12
xorl %ebx, %ebx
cmpq %rbx, 0x10(%rsp)
je 0x3e27
movl -0x4(%r12), %edx
movl (%r12), %esi
movl %ebp, %edi
callq 0x35ae
testb %al, %al
jne 0x38ee
incq %rbx
addq $0x18, %r12
jmp 0x38c6
movq (%r15,%rbx,8), %rax
movq 0x18(%rsp), %rsi
movslq (%rsi,%rbx,4), %rcx
leal 0x1(%rcx), %edx
movl %edx, (%rsi,%rbx,4)
movl %ebp, (%rax,%rcx,4)
movq 0x38(%rsp), %rax
movq 0x48(%rsp), %rcx
movb $0x1, (%rax,%rcx)
movq 0x40(%rsp), %r12
incq %r13
movq 0x58(%rsp), %rbx
jmp 0x3885
movq 0xa0(%rsp), %rbx
movq %rbx, %rdi
callq 0x354c
movq %rax, 0x38(%rsp)
movq %rbx, %rdi
callq 0x354c
movq %rax, 0x48(%rsp)
movq %rbx, %rdi
callq 0x354c
movq %rax, %rbp
xorl %ebx, %ebx
cmpq %rbx, 0x10(%rsp)
je 0x397b
movq 0x18(%rsp), %rax
movslq (%rax,%rbx,4), %rdi
testq %rdi, %rdi
jle 0x3976
shlq $0x3, %rdi
callq 0x354c
movq %rax, (%rbp,%rbx,8)
incq %rbx
jmp 0x3953
pushq $0x4
popq %rsi
movq 0x28(%rsp), %rdi
callq 0x357d
movq %rax, %rdx
xorl %r13d, %r13d
movq 0x360b(%rip), %rsi      # 0x6fa0
xorl %ebx, %ebx
movl $0x0, 0x30(%rsp)
movq 0x70(%rsp), %rcx
movq %rax, 0x28(%rsp)
cmpq %rbx, 0x10(%rsp)
je 0x3a77
cmpq %rbx, %rcx
je 0x3a59
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax,%rbx,4)
je 0x3a59
movl $0x1, (%rdx,%rbx,4)
incl 0x30(%rsp)
movq (%r15,%rbx,8), %rdi
movq 0x18(%rsp), %r12
movl (%r12,%rbx,4), %esi
movq 0x38(%rsp), %rax
addq %r13, %rax
subq $0x8, %rsp
movq 0x35b1(%rip), %rdx      # 0x6fa8
movl %ebx, %ecx
xorl %r8d, %r8d
movq 0x35d5(%rip), %r9       # 0x6fd8
pushq %rax
callq 0x20d0
popq %rcx
popq %rdx
movq (%rbp,%rbx,8), %rdi
movl (%r12,%rbx,4), %esi
movq 0x40(%rsp), %r12
movq 0x48(%rsp), %rax
addq %r13, %rax
subq $0x8, %rsp
movq 0x35a4(%rip), %rdx      # 0x6fd0
movl %ebx, %ecx
pushq $0x1
popq %r8
movq 0x359f(%rip), %r9       # 0x6fd8
pushq %rax
callq 0x20b0
movq 0x355a(%rip), %rsi      # 0x6fa0
movq 0x38(%rsp), %rdx
movq 0x80(%rsp), %rcx
addq $0x10, %rsp
jmp 0x3a6b
movq 0x48(%rsp), %rax
movq %rsi, (%rax,%rbx,8)
movq 0x38(%rsp), %rax
movq %rsi, (%rax,%rbx,8)
incq %rbx
addq $0x8, %r13
jmp 0x39a9
cmpl $0x0, 0x54(%rsp)
je 0x3a95
subq $0x8, %rsp
movq 0x351f(%rip), %rcx      # 0x6fa8
movq 0x3550(%rip), %r8       # 0x6fe0
movq %rdx, %rdi
jmp 0x3aaa
subq $0x8, %rsp
movq 0x3508(%rip), %rcx      # 0x6fa8
movq 0x3539(%rip), %r8       # 0x6fe0
pushq $0x1
popq %rdi
movq %rdx, %r13
movq %rdx, %rsi
movl 0x14(%rsp), %edx
xorl %r9d, %r9d
movq 0x351a(%rip), %rbx      # 0x6fd8
pushq %rbx
callq 0x21e0
popq %rcx
popq %rdx
movq 0xb8(%rsp), %rax
leaq (%r13,%rax,4), %rcx
movq 0x34ce(%rip), %rdx      # 0x6fa8
pushq $0x1
popq %rsi
movq %r13, %rdi
movq %rcx, 0x10(%rsp)
movl %esi, %r8d
movq %rdx, %r9
pushq %rbx
pushq $0x0
callq 0x2210
popq %rcx
popq %rdx
movslq 0x10(%r12), %rdi
shlq $0x2, %rdi
callq 0x354c
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
callq 0x354c
movq %rax, %r12
xorl %r13d, %r13d
movq 0x10(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %r13
jge 0x3bfd
pushq $-0x1
popq %rdi
xorl %esi, %esi
movq 0x34a2(%rip), %rdx      # 0x6fd8
leaq 0xd0(%rsp), %rcx
callq 0x2190
leaq 0xd0(%rsp), %rdi
movq 0x3456(%rip), %rsi      # 0x6fa8
leaq 0x24(%rsp), %rdx
callq 0x2050
movslq 0x24(%rsp), %rdi
shlq $0x3, %rdi
callq 0x354c
movq %rax, (%r12,%r13,8)
movl 0x24(%rsp), %esi
movl 0xd0(%rsp), %ecx
subq $0x8, %rsp
movq %rbx, %rdi
movq 0x3421(%rip), %rdx      # 0x6fa8
xorl %r8d, %r8d
movq 0x3447(%rip), %r9       # 0x6fd8
pushq $0x0
callq 0x21b0
addq $0x10, %rsp
movl 0x24(%rsp), %esi
testl %esi, %esi
movl $0x0, %eax
cmovgl %esi, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x3bc9
movslq (%rbx,%rcx,4), %rdx
movsd (%r14,%rdx,8), %xmm0
movq (%r12,%r13,8), %rdx
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
jmp 0x3bac
movq (%r12,%r13,8), %rdi
movl 0xd0(%rsp), %ecx
subq $0x8, %rsp
movq 0x33f1(%rip), %rdx      # 0x6fd0
pushq $0x1
popq %r8
movq 0x33ee(%rip), %r9       # 0x6fd8
pushq 0x40(%rsp)
callq 0x20d0
popq %rcx
popq %rdx
incq %r13
jmp 0x3b19
movq 0x40(%rsp), %r12
movl 0x8(%r12), %r9d
subq $0x8, %rsp
movq 0xc8(%rsp), %rdi
movq 0xa0(%rsp), %rbx
movq %rbx, %rsi
movq 0x98(%rsp), %r13
movq %r13, %rdx
movq 0x3378(%rip), %rcx      # 0x6fa8
movq 0x88(%rsp), %r8
movq 0x3399(%rip), %rax      # 0x6fd8
pushq %rax
pushq $0x0
pushq %rcx
callq 0x2120
addq $0x20, %rsp
movl 0x8(%r12), %r9d
subq $0x8, %rsp
movq 0xd0(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq 0x3366(%rip), %rcx      # 0x6fd0
movq 0x80(%rsp), %r8
pushq 0x3360(%rip)            # 0x6fd8
pushq $0x0
pushq %rcx
callq 0x2120
addq $0x20, %rsp
xorl %ebx, %ebx
movq 0x58(%rsp), %r13
movslq 0x8(%r12), %rax
cmpq %rax, %rbx
jge 0x3ced
movl (%r13,%rbx,4), %edi
movl 0x10(%r12), %edx
movl 0x14(%r12), %esi
callq 0x35ae
testb %al, %al
je 0x3ce8
movq 0x78(%rsp), %rax
movsd (%rax,%rbx,8), %xmm0
movslq (%r13,%rbx,4), %rax
movq 0x80(%rsp), %rcx
movslq (%rcx,%rbx,4), %rcx
movslq 0x14(%r12), %rdx
mulsd (%r14,%rax,8), %xmm0
subq %rdx, %rcx
movq 0xa8(%rsp), %rax
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rbx
jmp 0x3c8b
xorl %eax, %eax
movl 0x30(%rsp), %r12d
testl %r12d, %r12d
cmovlel %eax, %r12d
leaq 0x8c(%rsp), %rbx
xorl %r13d, %r13d
cmpl %r12d, %r13d
je 0x3d6d
movl 0xc(%rsp), %edi
movq 0x48(%rsp), %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x2080
movslq 0x8c(%rsp), %rax
cmpq $-0x7ffe, %rax          # imm = 0x8002
je 0x3e44
movq 0x18(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
testl %ecx, %ecx
movl $0x0, %edx
cmovlel %edx, %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x3d68
movq (%rbp,%rax,8), %rsi
movsd (%rsi,%rdx,8), %xmm0
movq (%r15,%rax,8), %rsi
movslq (%rsi,%rdx,4), %rsi
movsd %xmm0, (%r14,%rsi,8)
incq %rdx
jmp 0x3d46
incl %r13d
jmp 0x3d06
xorl %ebx, %ebx
movq 0x40(%rsp), %r15
movq 0xa8(%rsp), %r12
movq 0x58(%rsp), %r13
movslq 0x8(%r15), %rax
cmpq %rax, %rbx
jge 0x3dd9
movl (%r13,%rbx,4), %edi
movl 0x10(%r15), %edx
movl 0x14(%r15), %esi
callq 0x35ae
testb %al, %al
jne 0x3dd4
movq 0x78(%rsp), %rax
movsd (%rax,%rbx,8), %xmm0
movslq (%r13,%rbx,4), %rax
movq 0x80(%rsp), %rcx
movslq (%rcx,%rbx,4), %rcx
movslq 0x14(%r15), %rdx
mulsd (%r14,%rax,8), %xmm0
subq %rdx, %rcx
addsd (%r12,%rcx,8), %xmm0
movsd %xmm0, (%r12,%rcx,8)
incq %rbx
jmp 0x3d81
movl 0x10(%r15), %esi
subq $0x8, %rsp
movq %r12, %rdi
movq 0x31e5(%rip), %rdx      # 0x6fd0
movq 0xb8(%rsp), %rbx
movq %rbx, %rcx
movq 0x70(%rsp), %r8
movq 0x68(%rsp), %r9
pushq 0x31d2(%rip)            # 0x6fd8
pushq $0x0
pushq %rdx
callq 0x22a0
addq $0x20, %rsp
movq %rbx, %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14fa(%rip), %rdi      # 0x5328
leaq 0x14fd(%rip), %rsi      # 0x5332
leaq 0x1507(%rip), %rcx      # 0x5343
pushq $0x6a
popq %rdx
callq 0x20c0
leaq 0x1551(%rip), %rdi      # 0x539c
leaq 0x14e0(%rip), %rsi      # 0x5332
leaq 0x14ea(%rip), %rcx      # 0x5343
movl $0xc5, %edx
callq 0x20c0