// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3ConnectionUnlocked
SQLITE_PRIVATE void sqlite3ConnectionUnlocked(sqlite3 *db){
  void (*xUnlockNotify)(void **, int) = 0; /* Unlock-notify cb to invoke */
  int nArg = 0;                            /* Number of entries in aArg[] */
  sqlite3 **pp;                            /* Iterator variable */
  void **aArg;               /* Arguments to the unlock callback */
  void **aDyn = 0;           /* Dynamically allocated space for aArg[] */
  void *aStatic[16];         /* Starter space for aArg[].  No malloc required */

  aArg = aStatic;
  enterMutex();         /* Enter STATIC_MAIN mutex */

  /* This loop runs once for each entry in the blocked-connections list. */
  for(pp=&sqlite3BlockedList; *pp; /* no-op */ ){
    sqlite3 *p = *pp;

    /* Step 1. */
    if( p->pBlockingConnection==db ){
      p->pBlockingConnection = 0;
    }

    /* Step 2. */
    if( p->pUnlockConnection==db ){
      assert( p->xUnlockNotify );
      if( p->xUnlockNotify!=xUnlockNotify && nArg!=0 ){
        xUnlockNotify(aArg, nArg);
        nArg = 0;
      }

      sqlite3BeginBenignMalloc();
      assert( aArg==aDyn || (aDyn==0 && aArg==aStatic) );
      assert( nArg<=(int)ArraySize(aStatic) || aArg==aDyn );
      if( (!aDyn && nArg==(int)ArraySize(aStatic))
       || (aDyn && nArg==(int)(sqlite3MallocSize(aDyn)/sizeof(void*)))
      ){
        /* The aArg[] array needs to grow. */
        void **pNew = (void **)sqlite3Malloc(nArg*sizeof(void *)*2);
        if( pNew ){
          memcpy(pNew, aArg, nArg*sizeof(void *));
          sqlite3_free(aDyn);
          aDyn = aArg = pNew;
        }else{
          /* This occurs when the array of context pointers that need to
          ** be passed to the unlock-notify callback is larger than the
          ** aStatic[] array allocated on the stack and the attempt to
          ** allocate a larger array from the heap has failed.
          **
          ** This is a difficult situation to handle. Returning an error
          ** code to the caller is insufficient, as even if an error code
          ** is returned the transaction on connection db will still be
          ** closed and the unlock-notify callbacks on blocked connections
          ** will go unissued. This might cause the application to wait
          ** indefinitely for an unlock-notify callback that will never
          ** arrive.
          **
          ** Instead, invoke the unlock-notify callback with the context
          ** array already accumulated. We can then clear the array and
          ** begin accumulating any further context pointers without
          ** requiring any dynamic allocation. This is sub-optimal because
          ** it means that instead of one callback with a large array of
          ** context pointers the application will receive two or more
          ** callbacks with smaller arrays of context pointers, which will
          ** reduce the applications ability to prioritize multiple
          ** connections. But it is the best that can be done under the
          ** circumstances.
          */
          xUnlockNotify(aArg, nArg);
          nArg = 0;
        }
      }
      sqlite3EndBenignMalloc();

      aArg[nArg++] = p->pUnlockArg;
      xUnlockNotify = p->xUnlockNotify;
      p->pUnlockConnection = 0;
      p->xUnlockNotify = 0;
      p->pUnlockArg = 0;
    }

    /* Step 3. */
    if( p->pBlockingConnection==0 && p->pUnlockConnection==0 ){
      /* Remove connection p from the blocked connections list. */
      *pp = p->pNextBlocked;
      p->pNextBlocked = 0;
    }else{
      pp = &p->pNextBlocked;
    }
  }

  if( nArg!=0 ){
    xUnlockNotify(aArg, nArg);
  }
  sqlite3_free(aDyn);
  leaveMutex();         /* Leave STATIC_MAIN mutex */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %rbx
xorl %r12d, %r12d
leaq 0x20(%rsp), %r13
leaq 0x204944(%rip), %r14    # 0x43de08
xorl %ebp, %ebp
xorl %edx, %edx
movq %rdi, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movq (%r14), %r15
testq %r15, %r15
je 0x23962f
movq 0x2d8(%r15), %rcx
cmpq %rbx, %rcx
je 0x239500
movq 0x2e0(%r15), %rax
cmpq %rbx, %rax
je 0x239522
testq %rcx, %rcx
je 0x239514
jmp 0x239620
andq $0x0, 0x2d8(%r15)
movq 0x2e0(%r15), %rax
cmpq %rbx, %rax
je 0x239522
testq %rax, %rax
je 0x239609
jmp 0x239620
cmpq %rdx, 0x2f0(%r15)
movq %rdx, 0x18(%rsp)
je 0x23953d
testl %ebp, %ebp
je 0x23953d
movq %r13, %rdi
movl %ebp, %esi
callq *%rdx
xorl %ebp, %ebp
movq 0x2048b4(%rip), %rax    # 0x43ddf8
testq %rax, %rax
je 0x23954b
callq *%rax
testq %r12, %r12
jne 0x239555
cmpl $0x10, %ebp
je 0x23956a
testq %r12, %r12
je 0x2395c3
movq %r12, %rdi
callq *0x2010e5(%rip)         # 0x43a648
sarl $0x3, %eax
cmpl %eax, %ebp
jne 0x2395c6
movq %r13, %r14
movq %r12, %rbx
movslq %ebp, %r13
movq %r13, %rdi
shlq $0x4, %rdi
callq 0x21f6df
testq %rax, %rax
je 0x2395a6
movq %rax, %r12
shlq $0x3, %r13
movq %rax, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x17630
movq %rbx, %rdi
callq 0x21f7f9
movq %r12, %r13
jmp 0x2395b7
movq %r14, %r13
movq %r14, %rdi
movl %ebp, %esi
callq *0x18(%rsp)
xorl %ebp, %ebp
movq %rbx, %r12
movq 0x8(%rsp), %rbx
movq 0x10(%rsp), %r14
jmp 0x2395c6
xorl %r12d, %r12d
movq 0x204833(%rip), %rax    # 0x43de00
testq %rax, %rax
je 0x2395d4
callq *%rax
movq 0x2e8(%r15), %rax
movslq %ebp, %rcx
movq %rax, (%r13,%rcx,8)
movq 0x2f0(%r15), %rdx
andq $0x0, 0x2e0(%r15)
incl %ebp
xorps %xmm0, %xmm0
movups %xmm0, 0x2e8(%r15)
cmpq $0x0, 0x2d8(%r15)
jne 0x239620
movq 0x2f8(%r15), %rax
movq %rax, (%r14)
andq $0x0, 0x2f8(%r15)
jmp 0x2394d2
addq $0x2f8, %r15            # imm = 0x2F8
movq %r15, %r14
jmp 0x2394cd
testl %ebp, %ebp
je 0x23963a
movq %r13, %rdi
movl %ebp, %esi
callq *%rdx
movq %r12, %rdi
callq 0x21f7f9
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq