// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movb %dil, %al
movb %al, -0x1(%rbp)
movq $0x0, -0x10(%rbp)
leaq 0xe0c(%rip), %rdi       # 0x1c8e9
leaq 0xe0e(%rip), %rsi       # 0x1c8f2
callq 0x1ba70
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x20a0
movl %eax, -0x20(%rbp)
cmpl $0x0, %eax
jle 0x1bb89
movl -0x20(%rbp), %edi
callq 0x2210
cmpl $0x0, %eax
je 0x1bb26
movl $0xa, -0x24(%rbp)
movl $0x30, -0x28(%rbp)
jmp 0x1bb72
movl -0x20(%rbp), %edi
callq 0x22d0
cmpl $0x0, %eax
je 0x1bb43
movl $0x1a, -0x24(%rbp)
movl $0x61, -0x28(%rbp)
jmp 0x1bb70
movl -0x20(%rbp), %edi
callq 0x21b0
cmpl $0x0, %eax
je 0x1bb60
movl $0x1a, -0x24(%rbp)
movl $0x41, -0x28(%rbp)
jmp 0x1bb6e
movl $0x7f, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
jmp 0x1bb70
jmp 0x1bb72
movl -0x24(%rbp), %eax
imull -0x1c(%rbp), %eax
movl -0x20(%rbp), %ecx
subl -0x28(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1baf4
movq -0x18(%rbp), %rdi
callq 0x1baa0
movq $0x0, -0x30(%rbp)
cmpb $0x0, -0x1(%rbp)
je 0x1bd39
leaq 0xd49(%rip), %rdi       # 0x1c8f4
leaq 0xd40(%rip), %rsi       # 0x1c8f2
callq 0x22a0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x1bbd9
leaq 0xd38(%rip), %rdi       # 0x1c901
leaq 0xd22(%rip), %rsi       # 0x1c8f2
callq 0x22a0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1bc33
movq -0x18(%rbp), %rcx
leaq -0x30(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x2380
movq %rax, %rcx
movl $0x1, %eax
cmpq %rcx, %rax
jne 0x1bc06
jmp 0x1bc25
leaq 0xd00(%rip), %rdi       # 0x1c90d
leaq 0xc98(%rip), %rsi       # 0x1c8ac
movl $0x89, %edx
leaq 0xd1f(%rip), %rcx       # 0x1c93f
callq 0x2180
movq -0x18(%rbp), %rdi
callq 0x2240
jmp 0x1bd37
leaq 0xd29(%rip), %rdi       # 0x1c963
leaq 0xcb1(%rip), %rsi       # 0x1c8f2
callq 0x1ba70
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x23b0
movb %al, -0x31(%rbp)
movzbl %al, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x39(%rbp)
jle 0x1bc7e
movzbl -0x31(%rbp), %ecx
xorl %eax, %eax
cmpl $0x20, %ecx
movb %al, -0x39(%rbp)
je 0x1bc7e
movzbl -0x31(%rbp), %eax
cmpl $0x9, %eax
setne %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x1bc8a
jmp 0x1bd2e
movzbl -0x31(%rbp), %edi
callq 0x2210
cmpl $0x0, %eax
je 0x1bca4
movzbl -0x31(%rbp), %eax
subl $0x30, %eax
movl %eax, -0x38(%rbp)
jmp 0x1bd17
movzbl -0x31(%rbp), %edi
callq 0x2350
movb %al, -0x31(%rbp)
movzbl -0x31(%rbp), %edi
callq 0x22d0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x3a(%rbp)
je 0x1bce0
movzbl -0x31(%rbp), %ecx
xorl %eax, %eax
cmpl $0x61, %ecx
movb %al, -0x3a(%rbp)
jl 0x1bce0
movzbl -0x31(%rbp), %eax
cmpl $0x66, %eax
setle %al
movb %al, -0x3a(%rbp)
movb -0x3a(%rbp), %al
testb $0x1, %al
jne 0x1bce9
jmp 0x1bceb
jmp 0x1bd0a
leaq 0xcb3(%rip), %rdi       # 0x1c9a5
leaq 0xbb3(%rip), %rsi       # 0x1c8ac
movl $0x96, %edx
leaq 0xc3a(%rip), %rcx       # 0x1c93f
callq 0x2180
movzbl -0x31(%rbp), %eax
subl $0x60, %eax
addl $0xa, %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rax
shlq $0x4, %rax
movl -0x38(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0x1bc4a
movq -0x18(%rbp), %rdi
callq 0x1baa0
jmp 0x1bd39
movslq -0x1c(%rbp), %rax
movq %rax, -0x58(%rbp)
xorl %eax, %eax
movl %eax, %edi
callq 0x2220
movq %rax, %rcx
movq -0x58(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x50(%rbp)
callq 0x2310
movl %eax, %ecx
movq -0x50(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
callq 0x2370
movl %eax, %ecx
movq -0x48(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
addq -0x30(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq