// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq $0x0, -0x30(%rbp)
leaq -0xb0(%rbp), %rax
movq %rax, -0x28(%rbp)
callq 0x3d5cb0
leaq 0x2569c3(%rip), %rax    # 0x6434c0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0x3ecd06
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movq 0x2d8(%rax), %rax
cmpq -0x8(%rbp), %rax
jne 0x3ecb43
movq -0xb8(%rbp), %rax
movq $0x0, 0x2d8(%rax)
movq -0xb8(%rbp), %rax
movq 0x2e0(%rax), %rax
cmpq -0x8(%rbp), %rax
jne 0x3ecca5
movq -0xb8(%rbp), %rax
movq 0x2f0(%rax), %rax
cmpq -0x10(%rbp), %rax
je 0x3ecb89
cmpl $0x0, -0x14(%rbp)
je 0x3ecb89
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %esi
callq *%rax
movl $0x0, -0x14(%rbp)
callq 0x3e01d0
cmpq $0x0, -0x30(%rbp)
jne 0x3ecb9b
cmpl $0x10, -0x14(%rbp)
je 0x3ecbcb
cmpq $0x0, -0x30(%rbp)
je 0x3ecc34
movl -0x14(%rbp), %eax
movl %eax, -0xc4(%rbp)
movq -0x30(%rbp), %rdi
callq 0x3c08a0
movl %eax, %ecx
movl -0xc4(%rbp), %eax
movslq %ecx, %rcx
shrq $0x3, %rcx
cmpl %ecx, %eax
jne 0x3ecc34
movslq -0x14(%rbp), %rdi
shlq $0x3, %rdi
shlq %rdi
callq 0x3c0760
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0xc0(%rbp)
je 0x3ecc1e
movq -0xc0(%rbp), %rdi
movq -0x28(%rbp), %rsi
movslq -0x14(%rbp), %rdx
shlq $0x3, %rdx
callq 0x19610
movq -0x30(%rbp), %rdi
callq 0x3c0800
movq -0xc0(%rbp), %rax
movq %rax, -0x28(%rbp)
movq %rax, -0x30(%rbp)
jmp 0x3ecc32
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %esi
callq *%rax
movl $0x0, -0x14(%rbp)
jmp 0x3ecc34
callq 0x3e0220
movq -0xb8(%rbp), %rax
movq 0x2e8(%rax), %rdx
movq -0x28(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x14(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0xb8(%rbp), %rax
movq 0x2f0(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0xb8(%rbp), %rax
movq $0x0, 0x2e0(%rax)
movq -0xb8(%rbp), %rax
movq $0x0, 0x2f0(%rax)
movq -0xb8(%rbp), %rax
movq $0x0, 0x2e8(%rax)
movq -0xb8(%rbp), %rax
cmpq $0x0, 0x2d8(%rax)
jne 0x3eccf0
movq -0xb8(%rbp), %rax
cmpq $0x0, 0x2e0(%rax)
jne 0x3eccf0
movq -0xb8(%rbp), %rax
movq 0x2f8(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0xb8(%rbp), %rax
movq $0x0, 0x2f8(%rax)
jmp 0x3ecd01
movq -0xb8(%rbp), %rax
addq $0x2f8, %rax            # imm = 0x2F8
movq %rax, -0x20(%rbp)
jmp 0x3ecb01
cmpl $0x0, -0x14(%rbp)
je 0x3ecd19
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %esi
callq *%rax
movq -0x30(%rbp), %rdi
callq 0x3c0800
callq 0x3d5da0
addq $0xd0, %rsp
popq %rbp
retq