// File: /workspace/github_c_makefile_star2_O0/00pauln00[P]yapio/yapio.c
// Function: yapio_gather_barrier_stats
static void
yapio_gather_barrier_stats(yapio_test_ctx_t *ytc, bool leader_rank)
{
    const int nranks = ytc->ytc_group->ytg_num_ranks;

    float *barrier_global_results =
        leader_rank ? ytc->ytc_barrier_results : NULL;

    int *barrier_max_rank = leader_rank ? &ytc->ytc_barrier_max_rank : NULL;

    yapio_per_rank_result_t *all_results = NULL;

    yapio_per_rank_result_t yprr =
        {.yprr_stonewalled = ytc->ytc_stonewalled,
         .yprr_num_ops_completed = ytc->ytc_num_ops_completed_before_stonewall,
         .yprr_barrier_wait = ytc->ytc_barrier_wait[0]};

    if (barrier_global_results)
    {
        *barrier_max_rank = -1;
        barrier_global_results[YAPIO_BARRIER_STATS_MAX] = 0.0;
        barrier_global_results[YAPIO_BARRIER_STATS_AVG] = 0.0;

        /* This node is rank0 and will gather the timers for reporting.
         */
        all_results =
            YAPIO_CALLOC(nranks, sizeof(yapio_per_rank_result_t));

        if (!all_results)
            log_msg(YAPIO_LL_FATAL, "calloc: %s", strerror(ENOMEM));
    }

    MPI_OP_START;
    int rc = MPI_Gather(&yprr, sizeof(yapio_per_rank_result_t),
                        MPI_BYTE, all_results, sizeof(yapio_per_rank_result_t),
                        MPI_BYTE, 0, ytc->ytc_group->ytg_comm);
    MPI_OP_END;

    if (rc != MPI_SUCCESS)
        log_msg(YAPIO_LL_FATAL, "MPI_Gather: error=%d", rc);

    if (barrier_global_results)
    {
        ssize_t nblks_written_before_stonewalling = 0;
        int i;
        for (i = 0; i < nranks; i++)
        {
            float bwait =
                yapio_timer_to_float(&all_results[i].yprr_barrier_wait);

            barrier_global_results[YAPIO_BARRIER_STATS_AVG] += bwait;

            if (bwait > barrier_global_results[YAPIO_BARRIER_STATS_MAX])
            {
                barrier_global_results[YAPIO_BARRIER_STATS_MAX] = bwait;
                *barrier_max_rank = i;
            }

            /* Check if any ranks have been stonewalled.  If so, then adjust
             * the leaders ytc stats to reflect this.
             */
            if (all_results[i].yprr_stonewalled)
            {
                ytc->ytc_stonewalled = 1;
                nblks_written_before_stonewalling +=
                    all_results[i].yprr_num_ops_completed;
            }
        }

        /* Calculate the average number of blocks processed by each rank.
         */
        if (ytc->ytc_stonewalled)
            ytc->ytc_num_ops_completed_before_stonewall =
                nblks_written_before_stonewalling / nranks;

        log_msg(YAPIO_LL_DEBUG, "%d = ytc_num_ops_completed_before_stonewall",
                ytc->ytc_num_ops_completed_before_stonewall);

        /* Calculate average
         */
        barrier_global_results[YAPIO_BARRIER_STATS_AVG] /= nranks;

        /* Determine the median by sorting the result array.
         */
        qsort((void *)all_results, (size_t)nranks,
              sizeof(yapio_per_rank_result_t),
              yapio_gather_barrier_stats_median_cmp);

        barrier_global_results[YAPIO_BARRIER_STATS_MED] =
            yapio_timer_to_float(&all_results[nranks / 2].yprr_barrier_wait);

        YAPIO_FREE(all_results);
    }
}

// Assembly:
subq $0xc8, %rsp
movb %sil, %al
movq %rdi, 0xc0(%rsp)
andb $0x1, %al
movb %al, 0xbf(%rsp)
movq 0xc0(%rsp), %rax
movq 0xa0(%rax), %rax
movl 0xb01c(%rax), %eax
movl %eax, 0xb8(%rsp)
testb $0x1, 0xbf(%rsp)
je 0xa706
movq 0xc0(%rsp), %rax
addq $0x88, %rax
movq %rax, 0x58(%rsp)
jmp 0xa70f
xorl %eax, %eax
movq %rax, 0x58(%rsp)
jmp 0xa70f
movq 0x58(%rsp), %rax
movq %rax, 0xb0(%rsp)
testb $0x1, 0xbf(%rsp)
je 0xa73b
movq 0xc0(%rsp), %rax
addq $0x94, %rax
movq %rax, 0x50(%rsp)
jmp 0xa744
xorl %eax, %eax
movq %rax, 0x50(%rsp)
jmp 0xa744
movq 0x50(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq $0x0, 0xa0(%rsp)
movq 0xc0(%rsp), %rax
movb 0x1(%rax), %al
andb $0x1, %al
movb %al, 0x88(%rsp)
movq 0xc0(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x8c(%rsp)
movq 0xc0(%rsp), %rax
movq 0x48(%rax), %rcx
movq %rcx, 0x90(%rsp)
movq 0x50(%rax), %rax
movq %rax, 0x98(%rsp)
cmpq $0x0, 0xb0(%rsp)
je 0xa900
movq 0xa8(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0xb0(%rsp), %rax
xorps %xmm0, %xmm0
movss %xmm0, 0x4(%rax)
movq 0xb0(%rsp), %rax
xorps %xmm0, %xmm0
movss %xmm0, (%rax)
movslq 0xb8(%rsp), %rdi
movl $0x18, %esi
callq 0x22c0
movq %rax, 0x80(%rsp)
movl $0x3, %eax
cmpl 0x4a0c(%rip), %eax      # 0xf210
jg 0xa866
movq 0x47d3(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x48(%rsp)
movl $0x3, %edi
callq 0x4890
movq 0x48(%rsp), %rdi
movq %rax, %rdx
movl 0x4a62(%rip), %r8d      # 0xf290
movq 0x80(%rsp), %r10
movslq 0xb8(%rsp), %rax
imulq $0x18, %rax, %rax
leaq 0x1606(%rip), %rsi      # 0xbe4f
leaq 0x23f3(%rip), %rcx      # 0xcc43
movl $0x952, %r9d            # imm = 0x952
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x2370
movq 0x80(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0xa0(%rsp)
cmpq $0x0, 0xa0(%rsp)
jne 0xa8fe
xorl %eax, %eax
cmpl 0x497d(%rip), %eax      # 0xf210
jg 0xa8fc
movq 0x4744(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x30(%rsp)
xorl %edi, %edi
callq 0x4890
movq %rax, 0x38(%rsp)
movl 0x49da(%rip), %eax      # 0xf290
movl %eax, 0x44(%rsp)
movl $0xc, %edi
callq 0x21e0
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rdx
movl 0x44(%rsp), %r8d
leaq 0x2384(%rip), %rsi      # 0xcc5e
leaq 0x2362(%rip), %rcx      # 0xcc43
movl $0x955, %r9d            # imm = 0x955
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2370
movl $0x1, %edi
callq 0x40f0
jmp 0xa8fe
jmp 0xa900
leaq 0xe0f1f1(%rip), %rdi    # 0xe19af8
callq 0x2350
movq 0xa0(%rsp), %rcx
movq 0xc0(%rsp), %rax
movq 0xa0(%rax), %rax
movq (%rax), %rax
leaq 0x88(%rsp), %rdi
movl $0x18, %r8d
movq 0x46b5(%rip), %r9       # 0xeff0
xorl %edx, %edx
movl %r8d, %esi
movq %r9, %rdx
movl $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x21f0
movl %eax, 0x74(%rsp)
leaq 0xe0f199(%rip), %rdi    # 0xe19af8
callq 0x2390
cmpl $0x0, 0x74(%rsp)
je 0xa9c8
xorl %eax, %eax
cmpl 0x489d(%rip), %eax      # 0xf210
jg 0xa9c6
movq 0x4664(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x28(%rsp)
xorl %edi, %edi
callq 0x4890
movq 0x28(%rsp), %rdi
movq %rax, %rdx
movl 0x48f6(%rip), %r8d      # 0xf290
movl 0x74(%rsp), %eax
leaq 0x22d3(%rip), %rsi      # 0xcc78
leaq 0x2297(%rip), %rcx      # 0xcc43
movl $0x95f, %r9d            # imm = 0x95F
movl %eax, (%rsp)
movb $0x0, %al
callq 0x2370
movl $0x1, %edi
callq 0x40f0
jmp 0xa9c8
cmpq $0x0, 0xb0(%rsp)
je 0xac2a
movq $0x0, 0x68(%rsp)
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
cmpl 0xb8(%rsp), %eax
jge 0xaac0
movq 0xa0(%rsp), %rdi
movslq 0x64(%rsp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
addq $0x8, %rdi
callq 0x7a80
movss %xmm0, 0x60(%rsp)
movss 0x60(%rsp), %xmm0
movq 0xb0(%rsp), %rax
addss (%rax), %xmm0
movss %xmm0, (%rax)
movss 0x60(%rsp), %xmm0
movq 0xb0(%rsp), %rax
ucomiss 0x4(%rax), %xmm0
jbe 0xaa67
movss 0x60(%rsp), %xmm0
movq 0xb0(%rsp), %rax
movss %xmm0, 0x4(%rax)
movl 0x64(%rsp), %ecx
movq 0xa8(%rsp), %rax
movl %ecx, (%rax)
movq 0xa0(%rsp), %rax
movslq 0x64(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
testb $0x1, (%rax)
je 0xaaae
movq 0xc0(%rsp), %rax
movb $0x1, 0x1(%rax)
movq 0xa0(%rsp), %rax
movslq 0x64(%rsp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rax
addq 0x68(%rsp), %rax
movq %rax, 0x68(%rsp)
jmp 0xaab0
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0xa9e8
movq 0xc0(%rsp), %rax
testb $0x1, 0x1(%rax)
je 0xaaed
movq 0x68(%rsp), %rax
movslq 0xb8(%rsp), %rcx
cqto
idivq %rcx
movl %eax, %ecx
movq 0xc0(%rsp), %rax
movl %ecx, 0x8(%rax)
movl $0x3, %eax
cmpl 0x4718(%rip), %eax      # 0xf210
jg 0xab4b
movq 0x44df(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movl $0x3, %edi
callq 0x4890
movq 0x20(%rsp), %rdi
movq %rax, %rdx
movl 0x476e(%rip), %r8d      # 0xf290
movq 0xc0(%rsp), %rax
movl 0x8(%rax), %eax
leaq 0x2168(%rip), %rsi      # 0xcc9c
leaq 0x2108(%rip), %rcx      # 0xcc43
movl $0x984, %r9d            # imm = 0x984
movl %eax, (%rsp)
movb $0x0, %al
callq 0x2370
cvtsi2ssl 0xb8(%rsp), %xmm1
movq 0xb0(%rsp), %rax
movss (%rax), %xmm0
divss %xmm1, %xmm0
movss %xmm0, (%rax)
movq 0xa0(%rsp), %rdi
movslq 0xb8(%rsp), %rsi
movl $0x18, %edx
leaq 0xbc(%rip), %rcx        # 0xac40
callq 0x2240
movq 0xa0(%rsp), %rdi
movl 0xb8(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cltq
imulq $0x18, %rax, %rax
addq %rax, %rdi
addq $0x8, %rdi
callq 0x7a80
movq 0xb0(%rsp), %rax
movss %xmm0, 0x8(%rax)
movq 0xa0(%rsp), %rdi
callq 0x2150
movl $0x3, %eax
cmpl 0x4639(%rip), %eax      # 0xf210
jg 0xac28
movq 0x4400(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movl $0x3, %edi
callq 0x4890
movq 0x18(%rsp), %rdi
movq %rax, %rdx
movl 0x468f(%rip), %r8d      # 0xf290
movq 0xa0(%rsp), %rax
leaq 0x125c(%rip), %rsi      # 0xbe6c
leaq 0x202c(%rip), %rcx      # 0xcc43
movl $0x993, %r9d            # imm = 0x993
movq %rax, (%rsp)
movb $0x0, %al
callq 0x2370
jmp 0xac2a
addq $0xc8, %rsp
retq
nopw %cs:(%rax,%rax)