// File: /workspace/github_c_makefile_star2_O2/pyk[P]simple-nn/deps/pcg/sample/pcg32-demo.c
// Function: main
int main(int argc, char** argv)
{
    // Read command-line options

    int rounds = 5;
    bool nondeterministic_seed = false;

    ++argv;
    --argc;
    if (argc > 0 && strcmp(argv[0], "-r") == 0) {
        nondeterministic_seed = true;
        ++argv;
        --argc;
    }
    if (argc > 0) {
        rounds = atoi(argv[0]);
    }

    // In this version of the code, we'll use a local rng, rather than the
    // global one.

    pcg32_random_t rng;

    // You should *always* seed the RNG.  The usual time to do it is the
    // point in time when you create RNG (typically at the beginning of the
    // program).
    //
    // pcg32_srandom_r takes two 64-bit constants (the initial state, and the
    // rng sequence selector; rngs with different sequence selectors will
    // *never* have random sequences that coincide, at all) - the code below
    // shows three possible ways to do so.

    if (nondeterministic_seed) {
        // Seed with external entropy

        uint64_t seeds[2];
        entropy_getbytes((void*)seeds, sizeof(seeds));
        pcg32_srandom_r(&rng, seeds[0], seeds[1]);
    } else {
        // Seed with a fixed constant

        pcg32_srandom_r(&rng, 42u, 54u);
    }

    printf("pcg32_random_r:\n"
           "      -  result:      32-bit unsigned int (uint32_t)\n"
           "      -  period:      2^64   (* 2^63 streams)\n"
           "      -  state type:  pcg32_random_t (%zu bytes)\n"
           "      -  output func: XSH-RR\n"
           "\n",
           sizeof(pcg32_random_t));

    for (int round = 1; round <= rounds; ++round) {
        printf("Round %d:\n", round);

        /* Make some 32-bit numbers */
        printf("  32bit:");
        for (int i = 0; i < 6; ++i)
            printf(" 0x%08x", pcg32_random_r(&rng));
        printf("\n");

        printf("  Again:");
        pcg32_advance_r(&rng, -6);
        for (int i = 0; i < 6; ++i)
            printf(" 0x%08x", pcg32_random_r(&rng));
        printf("\n");

        /* Toss some coins */
        printf("  Coins: ");
        for (int i = 0; i < 65; ++i)
            printf("%c", pcg32_boundedrand_r(&rng, 2) ? 'H' : 'T');
        printf("\n");

        /* Roll some dice */
        printf("  Rolls:");
        for (int i = 0; i < 33; ++i)
            printf(" %d", (int)pcg32_boundedrand_r(&rng, 6) + 1);
        printf("\n");

        /* Deal some cards */
        enum { SUITS = 4, NUMBERS = 13, CARDS = 52 };
        char cards[CARDS];

        for (int i = 0; i < CARDS; ++i)
            cards[i] = i;

        for (int i = CARDS; i > 1; --i) {
            int chosen = pcg32_boundedrand_r(&rng, i);
            char card = cards[chosen];
            cards[chosen] = cards[i - 1];
            cards[i - 1] = card;
        }

        printf("  Cards:");
        static const char number[] = {'A', '2', '3', '4', '5', '6', '7',
                                      '8', '9', 'T', 'J', 'Q', 'K'};
        static const char suit[] = {'h', 'c', 'd', 's'};
        for (int i = 0; i < CARDS; ++i) {
            printf(" %c%c", number[cards[i] / SUITS], suit[cards[i] % SUITS]);
            if ((i + 1) % 22 == 0)
                printf("\n\t");
        }
        printf("\n");

        printf("\n");
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movabsq $0x5851f42d4c957f2d, %rbx # imm = 0x5851F42D4C957F2D
cmpl $0x1, %edi
jle 0x1214
movl %edi, %eax
movq 0x8(%rsi), %rdi
cmpb $0x2d, (%rdi)
jne 0x11d4
cmpb $0x72, 0x1(%rdi)
jne 0x11d4
cmpb $0x0, 0x2(%rdi)
je 0x1495
xorl %ebp, %ebp
callq 0x1090
movl %eax, %r15d
testb %bpl, %bpl
je 0x1218
leaq 0x20(%rsp), %r14
pushq $0x10
popq %rsi
movq %r14, %rdi
callq 0x14b0
movq 0x8(%r14), %rax
leaq 0x1(,%rax,2), %rcx
movq %rcx, 0x10(%rsp)
addq (%r14), %rcx
imulq %rbx, %rcx
leaq (%rcx,%rax,2), %rax
incq %rax
jmp 0x122b
pushq $0x5
popq %r15
movq $0x6d, 0x10(%rsp)
movabsq $0x185706b82c2e03f8, %rax # imm = 0x185706B82C2E03F8
movq %rax, 0x8(%rsp)
leaq 0xdcd(%rip), %rdi       # 0x2004
xorl %r14d, %r14d
pushq $0x10
popq %rsi
xorl %eax, %eax
callq 0x1040
testl %r15d, %r15d
cmovlel %r14d, %r15d
incl %r15d
movl %r15d, 0x18(%rsp)
pushq $0x1
popq %rsi
leaq 0x8(%rsp), %r15
pushq $0x2
popq %r13
pushq $0x48
popq %r12
leaq 0xe71(%rip), %rbp       # 0x20db
cmpl 0x18(%rsp), %esi
je 0x1484
leaq 0xe4c(%rip), %rdi       # 0x20c7
movl %esi, 0x1c(%rsp)
xorl %eax, %eax
callq 0x1040
leaq 0xe45(%rip), %rdi       # 0x20d2
xorl %eax, %eax
callq 0x1040
pushq $0x6
popq %r14
subl $0x1, %r14d
jb 0x12d6
movq 0x8(%rsp), %rcx
movq %rcx, %rax
imulq %rbx, %rax
addq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rcx, %rsi
shrq $0x2d, %rsi
movq %rcx, %rax
shrq $0x1b, %rax
xorl %eax, %esi
shrq $0x3b, %rcx
rorl %cl, %esi
movq %rbp, %rdi
xorl %eax, %eax
callq 0x1040
jmp 0x1298
pushq $0xa
popq %rdi
callq 0x1030
leaq 0xdfe(%rip), %rdi       # 0x20e3
xorl %eax, %eax
callq 0x1040
movq %r15, %rdi
pushq $-0x6
popq %rsi
callq 0x1677
pushq $0x6
popq %r14
subl $0x1, %r14d
jb 0x1339
movq 0x8(%rsp), %rcx
movq %rcx, %rax
imulq %rbx, %rax
addq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rcx, %rsi
shrq $0x2d, %rsi
movq %rcx, %rax
shrq $0x1b, %rax
xorl %eax, %esi
shrq $0x3b, %rcx
rorl %cl, %esi
movq %rbp, %rdi
xorl %eax, %eax
callq 0x1040
jmp 0x12fb
pushq $0xa
popq %rdi
callq 0x1030
leaq 0xda4(%rip), %rdi       # 0x20ec
xorl %eax, %eax
callq 0x1040
pushq $0x41
popq %r14
subl $0x1, %r14d
jb 0x1376
movq %r15, %rdi
movl %r13d, %esi
callq 0x195f
testl %eax, %eax
movl %r12d, %edi
pushq $0x54
popq %rax
cmovel %eax, %edi
callq 0x1030
jmp 0x1353
pushq $0xa
popq %rdi
callq 0x1030
leaq 0xd71(%rip), %rdi       # 0x20f6
xorl %eax, %eax
callq 0x1040
pushq $0x21
popq %r14
subl $0x1, %r14d
jb 0x13b4
movq %r15, %rdi
pushq $0x6
popq %rsi
callq 0x195f
leal 0x1(%rax), %esi
leaq 0xd54(%rip), %rdi       # 0x20ff
xorl %eax, %eax
callq 0x1040
jmp 0x1390
pushq $0xa
popq %rdi
callq 0x1030
xorl %eax, %eax
cmpq $0x34, %rax
je 0x13cd
movb %al, 0x20(%rsp,%rax)
incq %rax
jmp 0x13be
pushq $0x34
popq %r14
cmpq $0x1, %r14
jbe 0x13fb
movq %r15, %rdi
movl %r14d, %esi
callq 0x195f
cltq
movb 0x20(%rsp,%rax), %cl
movb 0x1f(%rsp,%r14), %dl
movb %dl, 0x20(%rsp,%rax)
movb %cl, 0x1f(%rsp,%r14)
decq %r14
jmp 0x13d1
leaq 0xd01(%rip), %rdi       # 0x2103
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x1040
cmpq $0x34, %r14
je 0x1465
movsbl 0x20(%rsp,%r14), %eax
movb $0x4, %cl
idivb %cl
movsbl %ah, %ecx
movsbq %al, %rax
leaq 0xceb(%rip), %rdx       # 0x2115
movsbl (%rax,%rdx), %esi
movslq %ecx, %rax
leaq 0xcea(%rip), %rcx       # 0x2122
movsbl (%rax,%rcx), %edx
leaq 0xcc9(%rip), %rdi       # 0x210c
xorl %eax, %eax
callq 0x1040
incq %r14
movzbl %r14b, %eax
movb $0x16, %cl
divb %cl
movzbl %ah, %eax
testb %al, %al
jne 0x140c
leaq 0xcaf(%rip), %rdi       # 0x2112
jmp 0x1405
pushq $0xa
popq %r14
movl %r14d, %edi
callq 0x1030
movl %r14d, %edi
callq 0x1030
movl 0x1c(%rsp), %esi
incl %esi
jmp 0x126a
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %eax
jne 0x14a3
pushq $0x5
popq %r15
jmp 0x11e3
movq 0x10(%rsi), %rdi
movb $0x1, %bpl
jmp 0x11d6
nop