// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/util.c
// Function: getRandomHexChars
void getRandomHexChars(char *p, unsigned int len) {
    char *charset = "0123456789abcdef";
    unsigned int j;

    /* Global state. */
    static int seed_initialized = 0;
    static unsigned char seed[20]; /* The SHA1 seed, from /dev/urandom. */
    static uint64_t counter = 0; /* The counter we hash with the seed. */

    if (!seed_initialized) {
        /* Initialize a seed and use SHA1 in counter mode, where we hash
         * the same seed with a progressive counter. For the goals of this
         * function we just need non-colliding strings, there are no
         * cryptographic security needs. */
        FILE *fp = fopen("/dev/urandom","r");
        if (fp && fread(seed,sizeof(seed),1,fp) == 1)
            seed_initialized = 1;
        if (fp) fclose(fp);
    }

    if (seed_initialized) {
        while(len) {
            unsigned char digest[20];
            SHA1_CTX ctx;
            unsigned int copylen = len > 20 ? 20 : len;

            SHA1Init(&ctx);
            SHA1Update(&ctx, seed, sizeof(seed));
            SHA1Update(&ctx, (unsigned char*)&counter,sizeof(counter));
            SHA1Final(digest, &ctx);
            counter++;

            memcpy(p,digest,copylen);
            /* Convert to hex digits. */
            for (j = 0; j < copylen; j++) p[j] = charset[p[j] & 0x0F];
            len -= copylen;
            p += copylen;
        }
    } else {
        /* If we can't read from /dev/urandom, do some reasonable effort
         * in order to create some entropy, since this function is used to
         * generate run_id and cluster instance IDs */
        char *x = p;
        unsigned int l = len;
        struct timeval tv;
        pid_t pid = getpid();

        /* Use time and PID to fill the initial array. */
        gettimeofday(&tv,NULL);
        if (l >= sizeof(tv.tv_usec)) {
            memcpy(x,&tv.tv_usec,sizeof(tv.tv_usec));
            l -= sizeof(tv.tv_usec);
            x += sizeof(tv.tv_usec);
        }
        if (l >= sizeof(tv.tv_sec)) {
            memcpy(x,&tv.tv_sec,sizeof(tv.tv_sec));
            l -= sizeof(tv.tv_sec);
            x += sizeof(tv.tv_sec);
        }
        if (l >= sizeof(pid)) {
            memcpy(x,&pid,sizeof(pid));
            l -= sizeof(pid);
            x += sizeof(pid);
        }
        /* Finally xor it with rand() output, that was already seeded with
         * time() at startup, and convert to hex digits. */
        for (j = 0; j < len; j++) {
            p[j] ^= rand();
            p[j] = charset[p[j] & 0x0F];
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
leaq 0xf3797(%rip), %rax     # 0x13b5f0
movq %rax, -0x18(%rbp)
cmpl $0x0, 0x144bfc(%rip)    # 0x18ca60
jne 0x47ec0
leaq 0xf3794(%rip), %rdi     # 0x13b601
leaq 0xf2955(%rip), %rsi     # 0x13a7c9
callq 0x26ae0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x47eae
movq -0x28(%rbp), %rcx
leaq 0x144be1(%rip), %rdi    # 0x18ca70
movl $0x14, %esi
movl $0x1, %edx
callq 0x26820
cmpq $0x1, %rax
jne 0x47eae
movl $0x1, 0x144bb2(%rip)    # 0x18ca60
cmpq $0x0, -0x28(%rbp)
je 0x47ebe
movq -0x28(%rbp), %rdi
callq 0x26a10
jmp 0x47ec0
cmpl $0x0, 0x144b99(%rip)    # 0x18ca60
je 0x47fde
jmp 0x47ecf
cmpl $0x0, -0xc(%rbp)
je 0x47fd9
cmpl $0x14, -0xc(%rbp)
jbe 0x47eec
movl $0x14, %eax
movl %eax, -0xc8(%rbp)
jmp 0x47ef5
movl -0xc(%rbp), %eax
movl %eax, -0xc8(%rbp)
movl -0xc8(%rbp), %eax
movl %eax, -0xa0(%rbp)
leaq -0x9c(%rbp), %rdi
callq 0x3f9d0
leaq -0x9c(%rbp), %rdi
leaq 0x144b55(%rip), %rsi    # 0x18ca70
movl $0x14, %edx
callq 0x3fa30
leaq -0x9c(%rbp), %rdi
leaq 0x144b55(%rip), %rsi    # 0x18ca88
movl $0x8, %edx
callq 0x3fa30
leaq -0x40(%rbp), %rdi
leaq -0x9c(%rbp), %rsi
callq 0x3fb40
movq 0x144b34(%rip), %rax    # 0x18ca88
addq $0x1, %rax
movq %rax, 0x144b29(%rip)    # 0x18ca88
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl -0xa0(%rbp), %eax
movl %eax, %edx
callq 0x26c60
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xa0(%rbp), %eax
jae 0x47fb3
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movl -0x1c(%rbp), %edx
movsbl (%rcx,%rdx), %ecx
andl $0xf, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x47f7b
movl -0xa0(%rbp), %ecx
movl -0xc(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xc(%rbp)
movl -0xa0(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x8(%rbp)
jmp 0x47ecf
jmp 0x4811d
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0xac(%rbp)
callq 0x26420
movl %eax, -0xc4(%rbp)
leaq -0xc0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x26310
movl -0xac(%rbp), %eax
cmpq $0x8, %rax
jb 0x4804c
movq -0xa8(%rbp), %rax
movq -0xb8(%rbp), %rcx
movq %rcx, (%rax)
movl -0xac(%rbp), %eax
subq $0x8, %rax
movl %eax, -0xac(%rbp)
movq -0xa8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xa8(%rbp)
movl -0xac(%rbp), %eax
cmpq $0x8, %rax
jb 0x4808b
movq -0xa8(%rbp), %rax
movq -0xc0(%rbp), %rcx
movq %rcx, (%rax)
movl -0xac(%rbp), %eax
subq $0x8, %rax
movl %eax, -0xac(%rbp)
movq -0xa8(%rbp), %rax
addq $0x8, %rax
movq %rax, -0xa8(%rbp)
movl -0xac(%rbp), %eax
cmpq $0x4, %rax
jb 0x480c8
movq -0xa8(%rbp), %rax
movl -0xc4(%rbp), %ecx
movl %ecx, (%rax)
movl -0xac(%rbp), %eax
subq $0x4, %rax
movl %eax, -0xac(%rbp)
movq -0xa8(%rbp), %rax
addq $0x4, %rax
movq %rax, -0xa8(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x4811b
callq 0x26b80
movl %eax, %esi
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
movsbl (%rax,%rcx), %edx
xorl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movl -0x1c(%rbp), %edx
movsbl (%rcx,%rdx), %ecx
andl $0xf, %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
movb %dl, (%rax,%rcx)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x480cf
jmp 0x4811d
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)