// File: /workspace/github_cpp_makefile_star2_O1/sisong[P]ApkDiffPatch/lzma/C/LzFindMt.c
// Function: BtThreadFunc
Z7_NO_INLINE
static void BtThreadFunc(CMatchFinderMt *mt)
{
  CMtSync *p = &mt->btSync;
  for (;;)
  {
    UInt32 blockIndex = 0;
    Event_Wait(&p->canStart);

    for (;;)
    {
        PRF(printf("  BT thread block = %d  pos = %d\n", (unsigned)blockIndex, mt->pos));
      /* (p->exit == true) is possible after (p->canStart) at first loop iteration
         and is unexpected after more Wait(freeSemaphore) iterations */
      if (p->exit)
        return;

      Semaphore_Wait(&p->freeSemaphore);
      
      // for faster stop : we check (p->stopWriting) after Wait(freeSemaphore)
      if (p->stopWriting)
        break;

      BtFillBlock(mt, blockIndex++);
      
      Semaphore_Release1(&p->filledSemaphore);
    }

    // we stop HASH_THREAD here
    MtSync_StopWriting(&mt->hashSync);

    // p->numBlocks_Sent = blockIndex;
    Event_Set(&p->wasStopped);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
addq $0x88, %rdi
movq %rdi, 0x60(%rsp)
callq 0x3dc62
cmpl $0x0, 0x80(%rbx)
je 0x3af3a
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x158(%rbx), %r14
leaq 0x4f0(%rbx), %rax
movq %rax, 0x28(%rsp)
leaq 0x318(%rbx), %rax
movq %rax, 0x30(%rsp)
leaq 0x1c0(%rbx), %rax
movq %rax, 0x48(%rsp)
leaq 0xf0(%rbx), %rax
movq %rax, 0x58(%rsp)
xorl %ebp, %ebp
movq %r14, 0x50(%rsp)
movq %r14, %rdi
callq 0x3dde1
cmpl $0x0, 0x84(%rbx)
je 0x3afba
movq 0x30(%rsp), %rdi
callq 0x3a64a
movq 0x58(%rsp), %rdi
callq 0x3dbe9
movq 0x60(%rsp), %rdi
callq 0x3dc62
cmpl $0x0, 0x80(%rbx)
movl $0x0, %ebp
je 0x3af78
jmp 0x3af2b
cmpl $0x0, 0x33c(%rbx)
jne 0x3afd7
movq 0x28(%rsp), %rdi
callq 0x3de7a
movl $0x1, 0x344(%rbx)
movq 0x8(%rbx), %rcx
movl %ebp, 0x24(%rsp)
movl %ebp, %edx
andl $0xf, %edx
shll $0x12, %edx
leaq (%rcx,%rdx), %r14
movl 0x2f0(%rbx), %eax
movl 0x2e0(%rbx), %esi
movl %esi, 0x4(%rcx,%rdx)
cmpl $0x0, 0x2e4(%rbx)
je 0x3b04b
movl $0x0, (%r14)
movl 0x24(%rsp), %ebp
incl %ebp
movq 0x28(%rsp), %rdi
callq 0x3de84
movl $0x0, 0x344(%rbx)
movq 0x48(%rsp), %rdi
movl $0x1, %esi
callq 0x3dd7c
cmpl $0x0, 0x80(%rbx)
movq 0x50(%rsp), %r14
je 0x3af78
jmp 0x3af2b
addl %eax, %eax
movl $0x10000, %ecx          # imm = 0x10000
subl %eax, %ecx
movl %ecx, 0x20(%rsp)
movl %ecx, %eax
movq %rax, 0x40(%rsp)
xorl %r15d, %r15d
movl $0x2, %eax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
cmpl 0x20(%rsp), %eax
jae 0x3b2bc
movl %eax, %r12d
leaq (,%r12,4), %rax
movq %rax, 0x8(%rsp)
movl 0x2dc(%rbx), %eax
subl 0x2d8(%rbx), %eax
jne 0x3b13e
movq 0x30(%rsp), %rdi
callq 0x3b2c4
andl $0x1, %eax
shll $0x11, %eax
movq 0x2d0(%rbx), %rcx
movl 0x4(%rcx,%rax,4), %ebp
movl (%rcx,%rax,4), %ecx
addl %eax, %ecx
movl %ecx, 0x2dc(%rbx)
movl %ebp, 0x2e0(%rbx)
orl $0x2, %eax
movl %r15d, %ecx
addl %ebp, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmovbl %edx, %ecx
movl %eax, 0x2d8(%rbx)
movl %ecx, 0x4(%r14)
movl 0x2f4(%rbx), %r13d
cmpl %r13d, %ebp
jae 0x3b130
movl $0x0, 0x2e0(%rbx)
movq 0x18(%rsp), %rax
addl %ebp, %eax
movl %eax, (%r14)
leaq (%r14,%r12,4), %rdi
testq %rbp, %rbp
je 0x3b12d
addq $0x4, %r14
addq 0x8(%rsp), %r14
leaq (,%rbp,4), %rdx
xorl %esi, %esi
callq 0x41c0
leal -0x1(%rbp), %eax
leaq (%r14,%rax,4), %r14
jmp 0x3b130
movq %rdi, %r14
cmpl %r13d, %ebp
jae 0x3b08b
jmp 0x3b00b
movl 0x2f8(%rbx), %edi
movl 0x308(%rbx), %edx
movl 0x2e0(%rbx), %ecx
movl 0x2f0(%rbx), %r13d
cmpl %ecx, %r13d
cmovael %ecx, %r13d
subl %r13d, %ecx
incl %ecx
cmpl %eax, %ecx
cmovael %eax, %ecx
movl 0x30c(%rbx), %r8d
movl %r8d, %ebp
movq %rdx, 0x38(%rsp)
subl %edx, %ebp
cmpl %ecx, %ebp
cmovael %ecx, %ebp
movl %ebp, %eax
addl %edi, %eax
jae 0x3b1aa
subl %r8d, %edi
movl %r8d, 0x2f8(%rbx)
movq 0x2e8(%rbx), %rsi
leaq (%r8,%r8), %rdx
movq %r8, 0x8(%rsp)
callq 0x37f0f
movq 0x8(%rsp), %rcx
jmp 0x3b1ac
movl %edi, %ecx
movq %rcx, 0x8(%rsp)
movl %ecx, 0x14(%rsp)
movq 0x300(%rbx), %rdx
movl %r13d, %eax
leaq (%rdx,%rax), %rdi
decq %rdi
movl %ecx, %esi
movq 0x2e8(%rbx), %rcx
movl 0x310(%rbx), %r8d
leaq (%r14,%r12,4), %r9
movl 0x2f4(%rbx), %eax
decl %eax
movl 0x2d8(%rbx), %r10d
shlq $0x2, %r10
addq 0x2d0(%rbx), %r10
movq 0x40(%rsp), %r11
leaq (%r14,%r11,4), %r11
movl %ebp, %r12d
leaq (%r10,%r12,4), %r12
movl 0x30c(%rbx), %r13d
subq $0x8, %rsp
leaq 0x1c(%rsp), %rbp
pushq %rbp
pushq %r13
movq 0x50(%rsp), %r13
pushq %r13
pushq %r12
pushq %r11
pushq %r10
pushq %rax
callq 0x3b3f4
addq $0x40, %rsp
testq %rax, %rax
je 0x3b25b
movq %rax, %rsi
subq %r14, %rsi
shrq $0x2, %rsi
movl 0x14(%rsp), %ecx
movl %ecx, %edx
subl 0x8(%rsp), %edx
addl %edx, 0x2d8(%rbx)
addl %edx, %r13d
addq %rdx, 0x300(%rbx)
movl %ecx, %edx
jmp 0x3b276
movl $0x1, 0x2e4(%rbx)
movl $0x0, (%r14)
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rdx
testq %rax, %rax
movq %rsi, 0x18(%rsp)
je 0x3b2ae
movl %edx, %ecx
subl 0x2f8(%rbx), %ecx
subl %ecx, 0x2e0(%rbx)
addl %ecx, %r15d
movl %edx, 0x2f8(%rbx)
cmpl 0x30c(%rbx), %r13d
movl $0x0, %ecx
cmovel %ecx, %r13d
movl %r13d, 0x308(%rbx)
testq %rax, %rax
jne 0x3b06c
jmp 0x3b00b
movl %eax, (%r14)
jmp 0x3b00b