// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x28, %rsp
movl $0x0, 0x24(%rsp)
callq 0x1080
movl %eax, 0x8(%rsp)
callq 0x10f0
movl 0x8(%rsp), %edi
addl %eax, %edi
callq 0x10e0
callq 0x10d0
callq 0x10a0
movl %eax, 0x2d8b(%rip)      # 0x40c0
callq 0x1070
movl %eax, 0x2d84(%rip)      # 0x40c4
movl $0x10, %eax
cltd
idivl 0x2d78(%rip)            # 0x40c4
movl %eax, 0x2d56(%rip)      # 0x40a8
movslq 0x2d4f(%rip), %rax      # 0x40a8
shlq $0x2, %rax
movl %eax, 0x20(%rsp)
movslq 0x20(%rsp), %rdi
callq 0x10b0
movq %rax, 0x2d46(%rip)      # 0x40b8
movl $0x0, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x2d24(%rip), %eax      # 0x40a8
jge 0x13a6
movq 0x2d2b(%rip), %rax      # 0x40b8
movslq 0x18(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x137a
movl $0x80, 0x1c(%rsp)
movslq 0x1c(%rsp), %rdi
callq 0x10b0
movq %rax, 0x2cf1(%rip)      # 0x40b0
movl $0x0, 0x18(%rsp)
cmpl $0x10, 0x18(%rsp)
jge 0x13ef
movq 0x2cdb(%rip), %rax      # 0x40b0
movslq 0x18(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x13c7
callq 0x10c0
movl $0x0, 0x18(%rsp)
cmpl $0x4, 0x18(%rsp)
jge 0x1479
callq 0x1110
cltd
idivl 0x2cb5(%rip)            # 0x40c4
movl %edx, 0x14(%rsp)
movl 0x2ca7(%rip), %eax      # 0x40c0
cmpl 0x14(%rsp), %eax
jne 0x146a
callq 0x1110
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, 0x10(%rsp)
callq 0x1110
movl $0x64, %ecx
cltd
idivl %ecx
movl %edx, 0xc(%rsp)
movl 0x2c79(%rip), %esi      # 0x40c0
movl 0x10(%rsp), %edx
movl 0xc(%rsp), %ecx
leaq 0xbdd(%rip), %rdi       # 0x2033
movb $0x0, %al
callq 0x1030
movl 0xc(%rsp), %edi
movl 0x10(%rsp), %esi
callq 0x1220
jmp 0x146c
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x13fc
callq 0x10c0
callq 0x12a0
callq 0x10c0
movq 0x2c21(%rip), %rdi      # 0x40b0
callq 0x1100
movq 0x2c1d(%rip), %rdi      # 0x40b8
callq 0x1100
callq 0x1090
xorl %eax, %eax
addq $0x28, %rsp
retq