// File: /workspace/github_c_makefile_star2_O0/Ziddykins[P]Dawn/src/namegen.c
// Function: gen_name
void gen_name(char * name, NameGen ng, size_t avg, double var) {
    if(!ng)
        return;
    struct namegen * cng = ng;
    assert(name && avg > 0 && var >= 0);
    assert(cng->markov_tier <= avg);
    //assert((malloc_usable_size(name)/sizeof *name) >= avg + cng->markov_tier + avg*var);
    assert(cng->success);
    double gauss = gaussrand();
    gauss = gauss > 1 || gauss < -1 ? 0 : gauss;
    size_t min = avg + (size_t)(gauss * avg * var);
    /*do {
        name[0] = (char)(genNum() * 26 + 'A') //(char)(rand()%256-128);
    } while(!isProducible(ng, name[0], cng->markov_tier));*/

    size_t tier = (size_t)((1-absd(gauss)) * (cng->markov_tier-1));
    char * start_str = gen_start(cng->tiers[tier]);
    size_t len = 0;
    int ret = snprintf(name, avg*2+1, "%s", start_str);
    CALLEXIT(ret < 0 || ret == (int)(avg*2+1))
    len += (size_t)ret;


    char last = name[tier+1];
    while(len < min) {
        while((tier = ((size_t)(rand()) % cng->markov_tier))+len+1 > min); //probability skew is okay
        char * res;
        while(!is_producible(ng, last, min-len)) {
            last = (char)(rand() % 256 - 128);
        }
        if(!(res = gen_token(cng->tiers[tier], last, 0))) {
            continue;
        }
        snprintf(name+len, (size_t)(avg*2+1-len), "%s", res);
        len += tier+1;
        assert(len < avg*2+1);
        last = name[len-1];
    }

    size_t distrib_len = (size_t)((absd(gaussrand())+(1-var))*cng->markov_tier);
    for(size_t i = distrib_len < cng->markov_tier-1 ? distrib_len : cng->markov_tier-1; i < cng->markov_tier; i--) {
        char * res;
        if((res = gen_token(cng->tiers[i], last, 1)) != 0) {
            snprintf(name+len, (size_t)(avg*2+cng->markov_tier+1), "%s", res);
            len += i+1;
            assert(len <= avg*2+cng->markov_tier+1);
            break;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x11e18
jmp 0x122e8
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x11e3e
cmpq $0x0, -0x18(%rbp)
jbe 0x11e3e
movsd -0x20(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x11e3e
jmp 0x11e5d
leaq 0xdf2f(%rip), %rdi      # 0x1fd74
leaq 0xdf44(%rip), %rsi      # 0x1fd90
movl $0x37, %edx
leaq 0xdf46(%rip), %rcx      # 0x1fd9e
callq 0x2100
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
cmpq -0x18(%rbp), %rax
ja 0x11e6c
jmp 0x11e8b
leaq 0xdf5a(%rip), %rdi      # 0x1fdcd
leaq 0xdf16(%rip), %rsi      # 0x1fd90
movl $0x38, %edx
leaq 0xdf18(%rip), %rcx      # 0x1fd9e
callq 0x2100
movq -0x28(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x11e97
jmp 0x11eb6
leaq 0xdf47(%rip), %rdi      # 0x1fde5
leaq 0xdeeb(%rip), %rsi      # 0x1fd90
movl $0x3a, %edx
leaq 0xdeed(%rip), %rcx      # 0x1fd9e
callq 0x2100
callq 0x181e0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd 0xddfb(%rip), %xmm1     # 0x1fcc8
ucomisd %xmm1, %xmm0
ja 0x11ee2
movsd 0xddf5(%rip), %xmm0     # 0x1fcd0
ucomisd -0x30(%rbp), %xmm0
jbe 0x11eec
xorps %xmm0, %xmm0
movsd %xmm0, -0x80(%rbp)
jmp 0x11ef6
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x18(%rbp), %rax
movsd -0x30(%rbp), %xmm0
movq %rax, %xmm1
movaps 0x80fb(%rip), %xmm2     # 0x1a010
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x80ff(%rip), %xmm2     # 0x1a020
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd -0x20(%rbp), %xmm1
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rcx
movq %rcx, %rsi
sarq $0x3f, %rsi
movsd 0x8b84(%rip), %xmm1     # 0x1aad8
movsd %xmm1, -0x88(%rbp)
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rdx
andq %rsi, %rdx
orq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movsd -0x30(%rbp), %xmm0
callq 0x18370
movsd -0x88(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd 0xdd39(%rip), %xmm0     # 0x1fcc8
subsd %xmm2, %xmm0
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
decl %eax
cvtsi2sd %rax, %xmm2
mulsd %xmm2, %xmm0
movaps %xmm0, %xmm2
cvttsd2si %xmm2, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2c60
movq %rax, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
shlq %rsi
addq $0x1, %rsi
movq -0x48(%rbp), %rcx
leaq 0xe539(%rip), %rdx      # 0x2053a
movb $0x0, %al
callq 0x2390
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jl 0x12023
movl -0x54(%rbp), %eax
movq -0x18(%rbp), %rcx
shlq %rcx
addq $0x1, %rcx
cmpl %ecx, %eax
jne 0x12039
leaq 0xddc8(%rip), %rdi      # 0x1fdf2
callq 0x2190
movl $0x1, %edi
callq 0x2260
movslq -0x54(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq -0x40(%rbp), %rcx
movb 0x1(%rax,%rcx), %al
movb %al, -0x55(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x1217d
jmp 0x12064
callq 0x2080
cltq
movq -0x28(%rbp), %rcx
movl 0x8(%rcx), %ecx
xorl %edx, %edx
divq %rcx
movq %rdx, %rax
movq %rax, -0x40(%rbp)
addq -0x50(%rbp), %rax
addq $0x1, %rax
cmpq -0x38(%rbp), %rax
jbe 0x1208e
jmp 0x12064
jmp 0x12090
movq -0x10(%rbp), %rdi
movb -0x55(%rbp), %al
movq -0x38(%rbp), %rdx
subq -0x50(%rbp), %rdx
movsbl %al, %esi
callq 0x12300
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x120b5
jmp 0x120cf
callq 0x2080
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
subl $0x80, %edx
movb %dl, %al
movb %al, -0x55(%rbp)
jmp 0x12090
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
xorl %edx, %edx
movsbl -0x55(%rbp), %esi
callq 0x2a60
movq %rax, -0x60(%rbp)
cmpq $0x0, %rax
jne 0x120f8
jmp 0x12054
movq -0x8(%rbp), %rdi
addq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
shlq %rsi
addq $0x1, %rsi
subq -0x50(%rbp), %rsi
movq -0x60(%rbp), %rcx
leaq 0xe420(%rip), %rdx      # 0x2053a
movb $0x0, %al
callq 0x2390
movq -0x40(%rbp), %rax
addq $0x1, %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x12147
jmp 0x12166
leaq 0xdcea(%rip), %rdi      # 0x1fe38
leaq 0xdc3b(%rip), %rsi      # 0x1fd90
movl $0x56, %edx
leaq 0xdc3d(%rip), %rcx      # 0x1fd9e
callq 0x2100
movq -0x8(%rbp), %rax
movq -0x50(%rbp), %rcx
subq $0x1, %rcx
movb (%rax,%rcx), %al
movb %al, -0x55(%rbp)
jmp 0x12054
callq 0x181e0
callq 0x18370
movsd -0x20(%rbp), %xmm2
movsd 0xdb34(%rip), %xmm1     # 0x1fcc8
subsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
cvtsi2sd %rax, %xmm1
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x8915(%rip), %xmm1     # 0x1aad8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x28(%rbp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x121f8
movq -0x68(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x1220b
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, %eax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq -0x28(%rbp), %rcx
movl 0x8(%rcx), %ecx
cmpq %rcx, %rax
jae 0x122e8
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl $0x1, %edx
movsbl -0x55(%rbp), %esi
callq 0x2a60
movq %rax, -0x78(%rbp)
cmpq $0x0, %rax
je 0x122d5
movq -0x8(%rbp), %rdi
addq -0x50(%rbp), %rdi
movq -0x18(%rbp), %rsi
shlq %rsi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
addq %rax, %rsi
addq $0x1, %rsi
movq -0x78(%rbp), %rcx
leaq 0xe2bd(%rip), %rdx      # 0x2053a
movb $0x0, %al
callq 0x2390
movq -0x70(%rbp), %rax
addq $0x1, %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x18(%rbp), %rcx
shlq %rcx
movq -0x28(%rbp), %rdx
movl 0x8(%rdx), %edx
addq %rdx, %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
ja 0x122b4
jmp 0x122d3
leaq 0xdb8b(%rip), %rdi      # 0x1fe46
leaq 0xdace(%rip), %rsi      # 0x1fd90
movl $0x60, %edx
leaq 0xdad0(%rip), %rcx      # 0x1fd9e
callq 0x2100
jmp 0x122e8
jmp 0x122d7
movq -0x70(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x12216
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)