// File: /workspace/github_c_makefile_star2_O2/pyk[P]simple-nn/deps/pcg/sample/pcg32-global-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 the global rng, rather than a
    // local one.

    // 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(seeds[0], seeds[1]);
    } else {
        // Seed with a fixed constant

        pcg32_srandom(42u, 54u);
    }

    printf("pcg32_random:\n"
           "      -  result:      32-bit unsigned int (uint32_t)\n"
           "      -  period:      2^64   (* 2^63 streams)\n"
           "      -  state type:  N/A (private global)\n"
           "      -  output func: XSH-RR\n"
           "\n");

    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());
        printf("\n");

        printf("  Again:");
        pcg32_advance(-6);
        for (int i = 0; i < 6; ++i)
            printf(" 0x%08x", pcg32_random());
        printf("\n");

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

        /* Roll some dice */
        printf("  Rolls:");
        for (int i = 0; i < 33; ++i)
            printf(" %d", (int)pcg32_boundedrand(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(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 $0x48, %rsp
cmpl $0x2, %edi
jl 0x1200
movl %edi, %eax
movq 0x8(%rsi), %rdi
cmpb $0x2d, (%rdi)
jne 0x11da
cmpb $0x72, 0x1(%rdi)
jne 0x11da
cmpb $0x0, 0x2(%rdi)
je 0x1406
xorl %ebx, %ebx
callq 0x10a0
movl %eax, %ebp
testb %bl, %bl
je 0x1203
leaq 0x10(%rsp), %rbx
pushq $0x10
popq %rsi
movq %rbx, %rdi
callq 0x1420
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
jmp 0x1209
pushq $0x5
popq %rbp
pushq $0x2a
popq %rdi
pushq $0x36
popq %rsi
callq 0x1d8e
leaq 0xe3d(%rip), %rdi       # 0x2052
callq 0x1040
xorl %eax, %eax
testl %ebp, %ebp
cmovlel %eax, %ebp
incl %ebp
movl %ebp, 0x8(%rsp)
pushq $0x1
popq %rsi
pushq $0x6
popq %r12
leaq 0xe07(%rip), %r15       # 0x203c
pushq $0x2
popq %rbx
pushq $0x48
popq %r14
leaq 0xdd5(%rip), %r13       # 0x2018
cmpl 0x8(%rsp), %esi
je 0x13f5
leaq 0xdb0(%rip), %rdi       # 0x2004
movl %esi, 0xc(%rsp)
xorl %eax, %eax
callq 0x1050
leaq 0xda9(%rip), %rdi       # 0x200f
xorl %eax, %eax
callq 0x1050
movl %r12d, %ebp
subl $0x1, %ebp
jb 0x128a
xorl %eax, %eax
callq 0x1d74
movq %r13, %rdi
movl %eax, %esi
xorl %eax, %eax
callq 0x1050
jmp 0x1270
pushq $0xa
popq %rdi
callq 0x1030
leaq 0xd87(%rip), %rdi       # 0x2020
xorl %eax, %eax
callq 0x1050
pushq $-0x6
popq %rdi
callq 0x1dc1
movl %r12d, %ebp
subl $0x1, %ebp
jb 0x12c5
xorl %eax, %eax
callq 0x1d74
movq %r13, %rdi
movl %eax, %esi
xorl %eax, %eax
callq 0x1050
jmp 0x12ab
pushq $0xa
popq %rdi
callq 0x1030
leaq 0xd55(%rip), %rdi       # 0x2029
xorl %eax, %eax
callq 0x1050
pushq $0x41
popq %rbp
subl $0x1, %ebp
jb 0x12fc
movl %ebx, %edi
callq 0x1d80
testl %eax, %eax
movl %r14d, %edi
pushq $0x54
popq %rax
cmovel %eax, %edi
callq 0x1030
jmp 0x12de
pushq $0xa
popq %rdi
callq 0x1030
leaq 0xd28(%rip), %rdi       # 0x2033
xorl %eax, %eax
callq 0x1050
pushq $0x21
popq %rbp
subl $0x1, %ebp
jb 0x1331
movl %r12d, %edi
callq 0x1d80
leal 0x1(%rax), %esi
movq %r15, %rdi
xorl %eax, %eax
callq 0x1050
jmp 0x1315
pushq $0xa
popq %rdi
callq 0x1030
xorl %eax, %eax
cmpq $0x34, %rax
je 0x134a
movb %al, 0x10(%rsp,%rax)
incq %rax
jmp 0x133b
pushq $0x34
popq %rbp
cmpq $0x1, %rbp
jbe 0x1371
movl %ebp, %edi
callq 0x1d80
cltq
movb 0x10(%rsp,%rax), %cl
movb 0xf(%rsp,%rbp), %dl
movb %dl, 0x10(%rsp,%rax)
movb %cl, 0xf(%rsp,%rbp)
decq %rbp
jmp 0x134d
leaq 0xcc8(%rip), %rdi       # 0x2040
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x1050
cmpq $0x34, %rbp
je 0x13d9
movsbl 0x10(%rsp,%rbp), %eax
movb $0x4, %cl
idivb %cl
movsbl %ah, %ecx
movsbq %al, %rax
leaq 0xd6e(%rip), %rdx       # 0x210c
movsbl (%rax,%rdx), %esi
movslq %ecx, %rax
leaq 0xd6d(%rip), %rcx       # 0x2119
movsbl (%rax,%rcx), %edx
leaq 0xc92(%rip), %rdi       # 0x2049
xorl %eax, %eax
callq 0x1050
incq %rbp
movzbl %bpl, %eax
movb $0x16, %cl
divb %cl
movzbl %ah, %eax
testb %al, %al
jne 0x1381
leaq 0xc78(%rip), %rdi       # 0x204f
jmp 0x137a
pushq $0xa
popq %rbp
movl %ebp, %edi
callq 0x1030
movl %ebp, %edi
callq 0x1030
movl 0xc(%rsp), %esi
incl %esi
jmp 0x1243
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %eax
jne 0x1413
pushq $0x5
popq %rbp
jmp 0x11e7
movq 0x10(%rsi), %rdi
movb $0x1, %bl
jmp 0x11dc
nop