// File: /workspace/github_c_makefile_star2_O2/waynebhayes[P]SAHap/src/utils.cpp
// Function: GetFancySeed
unsigned long GetFancySeed(Boolean trulyRandom)
{
    unsigned long seed = 0;

    FILE *fp=Popen("hostname","r");
    int host_ip=0, c;
    while((c=getc(fp)) > 0) {
	int mul, base;
	if(isdigit(c)) { mul=10; base='0'; }
	else if(islower(c)) {mul=26; base='a';}
	else if(isupper(c)) {mul=26; base='A';}
	else {mul = 127; base=0;}
	host_ip = mul*host_ip + (c-base);
    }
    Pclose(fp);
    unsigned long dev_random=0;
    if(trulyRandom) {
	fp = fopen("/dev/urandom","r");
	if(!fp) fp = fopen("/dev/random","r");
	if(fp){
	    assert(1 == fread(&dev_random, sizeof(dev_random),1, fp));
	    fclose(fp);
	}
	else
	{
	    // Use a bunch of hard-to-predict commands with nondeterministic output, then md5sum it.
	    fp = Popen("(who; w; uptime; ipconfig /all; ifconfig -a) 2>/dev/null | md5sum","r");
	    unsigned char c;
	    while((c=fgetc(fp)) > 0 && c != ' ' && c != '\t') {
		unsigned int hex;
		if(isdigit(c)) hex = (c-'0');
		else {
		    c = tolower(c);
		    assert(islower(c) && c >= 'a' && c <= 'f');
		    hex = 10+(c-('a'-1));
		}
		dev_random = 16*dev_random + hex;
	    }
	    Pclose(fp);
	}
    }
    seed = host_ip + time(0) + getppid() + getpid() + dev_random;
#if 0
    fprintf(stderr,"%s\n",cmd);
    fprintf(stderr,"%d.%d.%d.%d\n",ip[0],ip[1],ip[2],ip[3]);
    fprintf(stderr,"seed is %ud\n",seed);
#endif
    return seed;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, 0xc(%rsp)
leaq 0xe82(%rip), %rdi       # 0xa911
leaq 0xe84(%rip), %rsi       # 0xa91a
callq 0x20a0
movq %rax, %r14
xorl %ebp, %ebp
pushq $-0x30
popq %r12
pushq $0xa
popq %r13
pushq $0x1a
popq %rbx
movq %r14, %rdi
callq 0x2090
testl %eax, %eax
jle 0x9b00
movl %eax, %r15d
leal -0x30(%r15), %ecx
movl %r13d, %edx
movl %r12d, %eax
cmpl $0xa, %ecx
jb 0x9af4
movl %r15d, %edi
callq 0x22b0
movl %eax, %ecx
movl %ebx, %edx
pushq $-0x61
popq %rax
testl %ecx, %ecx
jne 0x9af4
movl %r15d, %edi
callq 0x21b0
testl %eax, %eax
movl %ebx, %edx
pushq $0x7f
popq %rcx
cmovel %ecx, %edx
pushq $-0x41
popq %rcx
cmovnel %ecx, %eax
imull %ebp, %edx
addl %r15d, %eax
addl %edx, %eax
movl %eax, %ebp
jmp 0x9aab
movq %r14, %rdi
callq 0x2310
andq $0x0, 0x10(%rsp)
cmpb $0x0, 0xc(%rsp)
je 0x9b74
leaq 0xe00(%rip), %rdi       # 0xa91c
leaq 0xdf7(%rip), %rsi       # 0xa91a
callq 0x2290
testq %rax, %rax
jne 0x9b45
leaq 0xdf5(%rip), %rdi       # 0xa929
leaq 0xddf(%rip), %rsi       # 0xa91a
callq 0x2290
testq %rax, %rax
je 0x9bae
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
movq %rax, %rcx
callq 0x2360
cmpq $0x1, %rax
jne 0x9c3f
movq %rbx, %rdi
callq 0x2240
movq 0x10(%rsp), %r15
jmp 0x9b77
xorl %r15d, %r15d
movslq %ebp, %r14
xorl %edi, %edi
callq 0x2210
movq %rax, %rbx
addq %r14, %rbx
callq 0x2300
movslq %eax, %r14
callq 0x2350
cltq
addq %r14, %rax
addq %rbx, %rax
addq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xdd6(%rip), %rdi       # 0xa98b
leaq 0xd5e(%rip), %rsi       # 0xa91a
callq 0x20a0
movq %rax, %rbx
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x2390
testb $-0x21, %al
je 0x9c13
movzbl %al, %edi
cmpl $0x9, %edi
je 0x9c13
leal -0x30(%rdi), %r14d
cmpl $0xa, %r14d
jb 0x9c07
callq 0x2330
movzbl %al, %r14d
movl %r14d, %edi
callq 0x22b0
testl %eax, %eax
je 0x9c20
leal -0x61(%r14), %eax
cmpl $0x6, %eax
jae 0x9c20
addl $-0x56, %r14d
shlq $0x4, %r15
movl %r14d, %eax
addq %rax, %r15
jmp 0x9bc7
movq %rbx, %rdi
callq 0x2310
jmp 0x9b77
leaq 0xda6(%rip), %rdi       # 0xa9cd
leaq 0xca6(%rip), %rsi       # 0xa8d4
leaq 0xd32(%rip), %rcx       # 0xa967
movl $0x96, %edx
callq 0x2180
leaq 0xcef(%rip), %rdi       # 0xa935
leaq 0xc87(%rip), %rsi       # 0xa8d4
leaq 0xd13(%rip), %rcx       # 0xa967
movl $0x89, %edx
callq 0x2180