// File: /workspace/github_c_makefile_star2_O0/kkanellis[P]matvec-sparse/partition.c
// Function: partition_equal_rows
void partition_equal_rows(proc_info_t *proc_info, int nprocs, const int *row_idx)
{
    /* rows for each process */
    double row_chunk = ((double)proc_info[0].N) / nprocs; 

    int last_row, i = 0;
    for (int k = 0; k < nprocs; k++) {
        proc_info[k].nz_count = 0;
        proc_info[k].nz_start_idx = i;

        last_row = (int)((k + 1) * row_chunk - 1);

        proc_info[k].row_start_idx = (int)(k * row_chunk);
        proc_info[k].row_count = last_row - proc_info[k].row_start_idx + 1;

        while (i < proc_info[0].NZ && row_idx[i] <= last_row) {
            proc_info[k].nz_count++; 
            i++;
        }

        debug("Processor %d takes rows %3d till %3d [%3d] (entries %6d till %6d) [%6d]\n", 
                        k, 
                        proc_info[k].row_start_idx, 
                        proc_info[k].row_start_idx + proc_info[k].row_count - 1,
                        proc_info[k].row_count,
                        proc_info[k].nz_start_idx, 
                        proc_info[k].nz_start_idx + proc_info[k].nz_count - 1,
                        proc_info[k].nz_count
        );
    }
    /* add remaining elements (if any) to last task */
    proc_info[nprocs - 1].nz_count += proc_info[0].NZ - i;  
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
cvtsi2sdl (%rax), %xmm0
cvtsi2sdl -0xc(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x2b0f
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x8(%rax)
movl -0x28(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0xc(%rax)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm0
movsd -0x20(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0x1853(%rip), %xmm1     # 0x42a8
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x24(%rbp)
cvtsi2sdl -0x2c(%rbp), %xmm0
mulsd -0x20(%rbp), %xmm0
cvttsd2si %xmm0, %ecx
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x14(%rax)
movl -0x24(%rbp), %ecx
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
subl 0x14(%rax), %ecx
addl $0x1, %ecx
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x10(%rax)
movl -0x28(%rbp), %ecx
movq -0x8(%rbp), %rdx
xorl %eax, %eax
cmpl 0x4(%rdx), %ecx
movb %al, -0x2d(%rbp)
jge 0x2acf
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x24(%rbp), %eax
setle %al
movb %al, -0x2d(%rbp)
movb -0x2d(%rbp), %al
testb $0x1, %al
jne 0x2ad8
jmp 0x2afb
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x2aaa
jmp 0x2afd
jmp 0x2aff
jmp 0x2b01
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2a03
movq -0x8(%rbp), %rax
movl 0x4(%rax), %ecx
subl -0x28(%rbp), %ecx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
popq %rbp
retq
nopw %cs:(%rax,%rax)