// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3_randomness
SQLITE_API void sqlite3_randomness(int N, void *pBuf){
  unsigned char t;
  unsigned char *zBuf = pBuf;

  /* The "wsdPrng" macro will resolve to the pseudo-random number generator
  ** state vector.  If writable static data is unsupported on the target,
  ** we have to locate the state vector at run-time.  In the more common
  ** case where writable static data is supported, wsdPrng can refer directly
  ** to the "sqlite3Prng" state vector declared above.
  */
#ifdef SQLITE_OMIT_WSD
  struct sqlite3PrngType *p = &GLOBAL(struct sqlite3PrngType, sqlite3Prng);
# define wsdPrng p[0]
#else
# define wsdPrng sqlite3Prng
#endif

#if SQLITE_THREADSAFE
  sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
  sqlite3_mutex_enter(mutex);
#endif

  /* Initialize the state of the random number generator once,
  ** the first time this routine is called.  The seed value does
  ** not need to contain a lot of randomness since we are not
  ** trying to do secure encryption or anything like that...
  **
  ** Nothing in this file or anywhere else in SQLite does any kind of
  ** encryption.  The RC4 algorithm is being used as a PRNG (pseudo-random
  ** number generator) not as an encryption device.
  */
  if( !wsdPrng.isInit ){
    int i;
    char k[256];
    wsdPrng.j = 0;
    wsdPrng.i = 0;
    sqlite3OsRandomness(sqlite3_vfs_find(0), 256, k);
    for(i=0; i<256; i++){
      wsdPrng.s[i] = (u8)i;
    }
    for(i=0; i<256; i++){
      wsdPrng.j += wsdPrng.s[i] + k[i];
      t = wsdPrng.s[wsdPrng.j];
      wsdPrng.s[wsdPrng.j] = wsdPrng.s[i];
      wsdPrng.s[i] = t;
    }
    wsdPrng.isInit = 1;
  }

  while( N-- ){
    wsdPrng.i++;
    t = wsdPrng.s[wsdPrng.i];
    wsdPrng.j += t;
    wsdPrng.s[wsdPrng.i] = wsdPrng.s[wsdPrng.j];
    wsdPrng.s[wsdPrng.j] = t;
    t += wsdPrng.s[wsdPrng.i];
    *(zBuf++) = wsdPrng.s[t];
  }
  sqlite3_mutex_leave(mutex);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, %rbx
movl %edi, %r14d
cmpb $0x0, 0x8a37a(%rip)     # 0x95d70
jne 0xba8a
movw $0x0, 0x8a36c(%rip)     # 0x95d71
callq 0x9d1f
xorl %r15d, %r15d
movl $0x0, %edi
testl %eax, %eax
jne 0xba1d
movq 0x8a313(%rip), %rdi     # 0x95d30
leaq -0x120(%rbp), %rdx
movl $0x100, %esi            # imm = 0x100
callq *0x68(%rdi)
leaq 0x8a33d(%rip), %rax     # 0x95d70
movb %r15b, 0x3(%r15,%rax)
incq %r15
cmpq $0x100, %r15            # imm = 0x100
jne 0xba33
movb 0x8a328(%rip), %cl      # 0x95d72
xorl %edx, %edx
movb 0x3(%rdx,%rax), %sil
movb -0x120(%rbp,%rdx), %dil
addb %sil, %dil
addb %dil, %cl
movzbl %cl, %edi
movb 0x3(%rdi,%rax), %r8b
movb %sil, 0x3(%rdi,%rax)
movb %r8b, 0x3(%rdx,%rax)
incq %rdx
cmpq $0x100, %rdx            # imm = 0x100
jne 0xba4c
movb %cl, 0x8a2ef(%rip)      # 0x95d72
movb $0x1, 0x8a2e6(%rip)     # 0x95d70
testl %r14d, %r14d
je 0xbaf5
movb 0x8a2dd(%rip), %al      # 0x95d72
movb 0x8a2d6(%rip), %cl      # 0x95d71
negl %r14d
movl $0x1, %edx
leaq 0x8a2c6(%rip), %rsi     # 0x95d70
incb %cl
movzbl %cl, %edi
movb 0x3(%rdi,%rsi), %r8b
addb %r8b, %al
movzbl %al, %r9d
movb 0x3(%r9,%rsi), %r10b
movb %r10b, 0x3(%rdi,%rsi)
movb %r8b, 0x3(%r9,%rsi)
addb 0x3(%rdi,%rsi), %r8b
movzbl %r8b, %edi
movb 0x3(%rdi,%rsi), %dil
movb %dil, -0x1(%rbx,%rdx)
incq %rdx
leal (%r14,%rdx), %edi
cmpl $0x1, %edi
jne 0xbaaa
movb %cl, 0x8a282(%rip)      # 0x95d71
movb %al, 0x8a27d(%rip)      # 0x95d72
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r14
popq %r15
popq %rbp
retq