// File: /workspace/github_c_makefile_star2_O2/pyk[P]simple-nn/deps/pcg/sample/pcg32x2-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.

    pcg32x2_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).
    //
    // pcg32x2_srandom_r takes four 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[4];
        entropy_getbytes((void*)seeds, sizeof(seeds));
        pcg32x2_srandom_r(&rng, seeds[0], seeds[1], seeds[2], seeds[3]);
    } else {
        // Seed with a fixed constant

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

    printf("pcg32x2_random_r:\n"
           "      -  result:      64-bit unsigned int (uint64_t)\n"
           "      -  period:      2^64   (* ~2^126 streams)\n"
           "      -  state space: 2^128  (* ~2^126 streams)\n"
           "      -  state type:  pcg32x2_random_t (%zu bytes)\n"
           "      -  output func: XSH-RR (x 2)\n"
           "\n",
           sizeof(pcg32x2_random_t));

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

        /* Make some RngTypebit numbers */
        printf("  64bit:");
        for (int i = 0; i < 6; ++i) {
            if (i > 0 && i % 3 == 0)
                printf("\n\t");
            printf(" 0x%016llx", pcg32x2_random_r(&rng));
        }
        printf("\n");

        printf("  Again:");
        pcg32x2_advance_r(&rng, -6);
        for (int i = 0; i < 6; ++i) {
            if (i > 0 && i % 3 == 0)
                printf("\n\t");
            printf(" 0x%016llx", pcg32x2_random_r(&rng));
        }
        printf("\n");

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

        /* Roll some dice */
        printf("  Rolls:");
        for (int i = 0; i < 33; ++i)
            printf(" %d", (int)pcg32x2_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 = pcg32x2_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 $0x68, %rsp
cmpl $0x1, %edi
jle 0x12ed
movl %edi, %eax
movq 0x8(%rsi), %rdi
cmpb $0x2d, (%rdi)
jne 0x12b5
cmpb $0x72, 0x1(%rdi)
jne 0x12b5
cmpb $0x0, 0x2(%rdi)
je 0x1566
xorl %ebx, %ebx
callq 0x1090
movl %eax, %ebp
testb %bl, %bl
je 0x12f0
leaq 0x30(%rsp), %rbx
pushq $0x20
popq %rsi
movq %rbx, %rdi
callq 0x1580
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x10(%rbx), %rcx
movq 0x18(%rbx), %r8
leaq 0x10(%rsp), %rdi
callq 0x119c
jmp 0x1320
pushq $0x5
popq %rbp
movq $0x6d, 0x18(%rsp)
movabsq $0x185706b82c2e03f8, %rax # imm = 0x185706B82C2E03F8
movq %rax, 0x10(%rsp)
movq $-0x6d, 0x28(%rsp)
movabsq $-0x1d72e7db0b204934, %rax # imm = 0xE28D1824F4DFB6CC
movq %rax, 0x20(%rsp)
leaq 0xcdd(%rip), %rdi       # 0x2004
xorl %ebx, %ebx
pushq $0x20
popq %rsi
xorl %eax, %eax
callq 0x1040
testl %ebp, %ebp
cmovlel %ebx, %ebp
incl %ebp
movl %ebp, 0x8(%rsp)
pushq $0x1
popq %rsi
leaq 0x10(%rsp), %r14
leaq 0xdca(%rip), %r15       # 0x2117
pushq $0x48
popq %r12
leaq 0xdc2(%rip), %r13       # 0x211a
cmpl 0x8(%rsp), %esi
je 0x1555
xorl %ebx, %ebx
leaq 0xd98(%rip), %rdi       # 0x2103
movl %esi, 0xc(%rsp)
xorl %eax, %eax
callq 0x1040
leaq 0xd91(%rip), %rdi       # 0x210e
xorl %eax, %eax
callq 0x1040
pushq $0x6
popq %rbp
subl $0x1, %ebp
jb 0x13bf
movl %ebx, %eax
subl $0x3, %eax
cmovbl %ebx, %eax
testl %ebx, %ebx
je 0x13a6
testl %eax, %eax
jne 0x13a6
movq %r15, %rdi
xorl %eax, %eax
callq 0x1040
movq %r14, %rdi
callq 0x1202
movq %r13, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x1040
incl %ebx
jmp 0x1387
pushq $0xa
popq %rdi
callq 0x1030
xorl %ebx, %ebx
leaq 0xd55(%rip), %rdi       # 0x2125
xorl %eax, %eax
callq 0x1040
movq %r14, %rdi
pushq $-0x6
popq %rsi
callq 0x122e
pushq $0x6
popq %rbp
subl $0x1, %ebp
jb 0x141d
movl %ebx, %eax
subl $0x3, %eax
cmovbl %ebx, %eax
testl %ebx, %ebx
je 0x1404
testl %eax, %eax
jne 0x1404
movq %r15, %rdi
xorl %eax, %eax
callq 0x1040
movq %r14, %rdi
callq 0x1202
movq %r13, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x1040
incl %ebx
jmp 0x13e5
pushq $0xa
popq %rbp
movl %ebp, %edi
callq 0x1030
leaq 0xd00(%rip), %rdi       # 0x212e
xorl %eax, %eax
callq 0x1040
pushq $0x41
popq %rbx
subl $0x1, %ebx
jb 0x145b
movq %r14, %rdi
pushq $0x2
popq %rsi
callq 0x1253
testq %rax, %rax
movl %r12d, %edi
pushq $0x54
popq %rax
cmovel %eax, %edi
callq 0x1030
jmp 0x1438
movl %ebp, %edi
callq 0x1030
leaq 0xccf(%rip), %rdi       # 0x2138
xorl %eax, %eax
callq 0x1040
pushq $0x21
popq %rbx
subl $0x1, %ebx
jb 0x1496
movq %r14, %rdi
pushq $0x6
popq %rsi
callq 0x1253
leal 0x1(%rax), %esi
leaq 0xcb4(%rip), %rdi       # 0x2141
xorl %eax, %eax
callq 0x1040
jmp 0x1473
movl %ebp, %edi
callq 0x1030
xorl %eax, %eax
cmpq $0x34, %rax
je 0x14ae
movb %al, 0x30(%rsp,%rax)
incq %rax
jmp 0x149f
pushq $0x34
popq %rbx
cmpq $0x1, %rbx
jbe 0x14d9
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1253
cltq
movb 0x30(%rsp,%rax), %cl
movb 0x2f(%rsp,%rbx), %dl
movb %dl, 0x30(%rsp,%rax)
movb %cl, 0x2f(%rsp,%rbx)
decq %rbx
jmp 0x14b1
leaq 0xc65(%rip), %rdi       # 0x2145
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x1040
cmpq $0x34, %rbx
je 0x153c
movsbl 0x30(%rsp,%rbx), %eax
movb $0x4, %cl
idivb %cl
movsbl %ah, %ecx
movsbq %al, %rax
leaq 0xc4e(%rip), %rdx       # 0x2154
movsbl (%rax,%rdx), %esi
movslq %ecx, %rax
leaq 0xc4d(%rip), %rcx       # 0x2161
movsbl (%rax,%rcx), %edx
leaq 0xc2f(%rip), %rdi       # 0x214e
xorl %eax, %eax
callq 0x1040
incq %rbx
movzbl %bl, %eax
movb $0x16, %cl
divb %cl
movzbl %ah, %eax
testb %al, %al
jne 0x14e9
movq %r15, %rdi
jmp 0x14e2
movl %ebp, %edi
callq 0x1030
movl %ebp, %edi
callq 0x1030
movl 0xc(%rsp), %esi
incl %esi
jmp 0x1358
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %eax
jne 0x1573
pushq $0x5
popq %rbp
jmp 0x12c2
movq 0x10(%rsi), %rdi
movb $0x1, %bl
jmp 0x12b7
nop