// File: /workspace/github_c_makefile_star2_O1/openshmem-org[P]openshmem-examples/c/dtrand.c
// Function: main
int
main(void)
{
    int table_bytes;
    int lock_bytes;
    int i;

    srand(getpid() + getuid());

    shmem_init();
    me = shmem_my_pe();
    npes = shmem_n_pes();

    /*
     * size of the per-PE partition
     */
    ip_pe = table_size / npes;

    /*
     * each PE only stores what it owns
     */
    table_bytes = sizeof(*table) * ip_pe;
    table = shmem_malloc(table_bytes);  /* !!! unchecked !!! */
    /*
     * initialize table
     */
    for (i = 0; i < ip_pe; i += 1) {
        table[i] = 0;
    }

    /*
     * each PE needs to be able to lock everywhere
     */
    lock_bytes = sizeof(*lock) * table_size;
    lock = shmem_malloc(lock_bytes);    /* !!! unchecked !!! */
    /*
     * initialize locks
     */
    for (i = 0; i < table_size; i += 1) {
        lock[i] = 0L;
    }

    /*
     * make sure all PEs have initialized symmetric data
     */
    shmem_barrier_all();

    for (i = 0; i < 4; i += 1) {
        const int updater = rand() % npes;

        if (me == updater) {
            const int i2u = rand() % table_size;
            const int nv = rand() % 100;

            printf("PE %d: About to update index %d with %d...\n", me, i2u,
                   nv);

            table_update(nv, i2u);
        }
    }

    shmem_barrier_all();

    /*
     * everyone shows their part of the table
     */
    table_dump();

    /*
     * clean up allocated memory
     */
    shmem_barrier_all();
    shmem_free(lock);
    shmem_free(table);

    shmem_finalize();

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
callq 0x1080
movl %eax, %ebx
callq 0x10f0
addl %eax, %ebx
movl %ebx, %edi
callq 0x10e0
callq 0x10d0
callq 0x10a0
movl %eax, 0x2dc8(%rip)      # 0x40c0
callq 0x1070
movl %eax, %ecx
movl %eax, 0x2dbf(%rip)      # 0x40c4
movl $0x10, %eax
xorl %edx, %edx
idivl %ecx
movl %eax, 0x2d94(%rip)      # 0x40a8
shll $0x2, %eax
movslq %eax, %rdi
callq 0x10b0
movq %rax, 0x2d92(%rip)      # 0x40b8
cmpl $0x0, 0x2d7b(%rip)      # 0x40a8
jle 0x1347
xorl %ecx, %ecx
movl $0x0, (%rax,%rcx,4)
incq %rcx
movslq 0x2d66(%rip), %rdx      # 0x40a8
cmpq %rdx, %rcx
jl 0x1331
movl $0x80, %edi
callq 0x10b0
movq %rax, 0x2d58(%rip)      # 0x40b0
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
movups %xmm0, 0x50(%rax)
movups %xmm0, 0x60(%rax)
movups %xmm0, 0x70(%rax)
callq 0x10c0
movl $0x4, %ebp
leaq 0xca8(%rip), %rbx       # 0x2033
callq 0x1110
cltd
idivl 0x2d2d(%rip)            # 0x40c4
cmpl %edx, 0x2d23(%rip)      # 0x40c0
jne 0x13fb
callq 0x1110
movl %eax, %r14d
leal 0xf(%r14), %eax
testl %r14d, %r14d
cmovnsl %r14d, %eax
andl $-0x10, %eax
subl %eax, %r14d
callq 0x1110
movslq %eax, %r15
imulq $0x51eb851f, %r15, %rax # imm = 0x51EB851F
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x25, %rax
addl %ecx, %eax
imull $0x64, %eax, %eax
subl %eax, %r15d
movl 0x2ce0(%rip), %esi      # 0x40c0
movq %rbx, %rdi
movl %r14d, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x1030
movl %r15d, %edi
movl %r14d, %esi
callq 0x121c
decl %ebp
jne 0x138b
callq 0x10c0
callq 0x1279
callq 0x10c0
movq 0x2c9b(%rip), %rdi      # 0x40b0
callq 0x1100
movq 0x2c97(%rip), %rdi      # 0x40b8
callq 0x1100
callq 0x1090
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq