// File: /workspace/github_c_makefile_star2_O1/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
movl %edi, %ebx
leaq 0x8(%rsi), %r15
leal -0x1(%rbx), %r12d
cmpl $0x2, %edi
jl 0x11f3
movq %rsi, %r14
movq (%r15), %rdi
leaq 0xe1e(%rip), %rsi       # 0x2004
callq 0x1080
testl %eax, %eax
je 0x1479
xorl %ebp, %ebp
testl %r12d, %r12d
jle 0x1208
movq (%r15), %rdi
callq 0x10b0
movl %eax, 0x4(%rsp)
jmp 0x1210
movl $0x5, 0x4(%rsp)
testb %bpl, %bpl
je 0x1230
leaq 0x10(%rsp), %r14
movl $0x10, %esi
movq %r14, %rdi
callq 0x1490
movq (%r14), %rdi
movq 0x8(%r14), %rsi
jmp 0x123a
movl $0x2a, %edi
movl $0x36, %esi
callq 0x1651
leaq 0xe0f(%rip), %rdi       # 0x2055
callq 0x1040
cmpl $0x0, 0x4(%rsp)
jle 0x1468
movl $0x1, %esi
leaq 0xdb9(%rip), %r13       # 0x201b
movl $0x54, %ebp
leaq 0xdd1(%rip), %r15       # 0x203f
leaq 0xea7(%rip), %r14       # 0x211c
leaq 0xdd0(%rip), %r12       # 0x204c
leaq 0xd84(%rip), %rdi       # 0x2007
movq %rsi, 0x8(%rsp)
xorl %eax, %eax
callq 0x1050
leaq 0xd7c(%rip), %rdi       # 0x2012
xorl %eax, %eax
callq 0x1050
movl $0x6, %ebx
xorl %eax, %eax
callq 0x15b8
movq %r13, %rdi
movl %eax, %esi
xorl %eax, %eax
callq 0x1050
decl %ebx
jne 0x12a2
movl $0xa, %edi
callq 0x1030
leaq 0xd59(%rip), %rdi       # 0x2023
xorl %eax, %eax
callq 0x1050
movq $-0x6, %rdi
callq 0x1684
movl $0x6, %ebx
xorl %eax, %eax
callq 0x15b8
movq %r13, %rdi
movl %eax, %esi
xorl %eax, %eax
callq 0x1050
decl %ebx
jne 0x12e2
movl $0xa, %edi
callq 0x1030
leaq 0xd22(%rip), %rdi       # 0x202c
xorl %eax, %eax
callq 0x1050
movl $0x41, %ebx
movl $0x2, %edi
callq 0x15f2
testl %eax, %eax
movl $0x48, %edi
cmovel %ebp, %edi
callq 0x1030
decl %ebx
jne 0x1316
movl $0xa, %edi
callq 0x1030
leaq 0xcf2(%rip), %rdi       # 0x2036
xorl %eax, %eax
callq 0x1050
movl $0x21, %ebx
movl $0x6, %edi
callq 0x15f2
leal 0x1(%rax), %esi
movq %r15, %rdi
xorl %eax, %eax
callq 0x1050
decl %ebx
jne 0x1350
movl $0xa, %edi
callq 0x1030
xorl %eax, %eax
movb %al, 0x10(%rsp,%rax)
incq %rax
cmpq $0x34, %rax
jne 0x1377
movl $0x35, %ebp
leaq -0x1(%rbp), %rbx
movl %ebx, %edi
callq 0x15f2
cltq
movb 0x10(%rsp,%rax), %cl
movb 0xe(%rsp,%rbp), %dl
movb %dl, 0x10(%rsp,%rax)
movb %cl, 0xe(%rsp,%rbp)
movq %rbx, %rbp
cmpq $0x2, %rbx
ja 0x1389
leaq 0xc8d(%rip), %rdi       # 0x2043
xorl %eax, %eax
callq 0x1050
movl $0x1, %ebx
xorl %ebp, %ebp
movl %ebx, %eax
movl $0xba2e8ba3, %ecx       # imm = 0xBA2E8BA3
imulq %rcx, %rax
shrq $0x24, %rax
leal (%rax,%rax,4), %ecx
leal (%rax,%rcx,4), %ecx
leal (%rax,%rcx), %r15d
decl %r15d
movsbl 0x10(%rsp,%rbp), %eax
leal 0x3(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
movl %ecx, %edx
sarl $0x2, %edx
movslq %edx, %rdx
leaq 0xd13(%rip), %rsi       # 0x210f
movsbl (%rdx,%rsi), %esi
andl $-0x4, %ecx
subl %ecx, %eax
cltq
movsbl (%rax,%r14), %edx
movq %r12, %rdi
xorl %eax, %eax
callq 0x1050
cmpl %ebp, %r15d
jne 0x1429
leaq 0xc30(%rip), %rdi       # 0x2052
xorl %eax, %eax
callq 0x1050
incq %rbp
incl %ebx
cmpq $0x34, %rbp
jne 0x13c4
movl $0xa, %edi
callq 0x1030
movl $0xa, %edi
callq 0x1030
movq 0x8(%rsp), %rcx
leal 0x1(%rcx), %eax
cmpl 0x4(%rsp), %ecx
movl %eax, %esi
movl $0x54, %ebp
leaq 0xbdd(%rip), %r15       # 0x203f
jne 0x127c
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x10, %r14
addl $-0x2, %ebx
movb $0x1, %bpl
movq %r14, %r15
movl %ebx, %r12d
jmp 0x11f5
nop