// File: /workspace/github_cpp_makefile_star2_O3/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
leaq 0x88(%rdi), %r12
movq %r12, %rdi
callq 0x3d81e
cmpl $0x0, 0x80(%rbx)
je 0x3ab00
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x158(%rbx), %rbp
leaq 0x4f0(%rbx), %rax
movq %rax, 0x40(%rsp)
leaq 0x318(%rbx), %r13
leaq 0x1c0(%rbx), %rax
movq %rax, 0x58(%rsp)
leaq 0xf0(%rbx), %rax
movq %rax, 0x60(%rsp)
xorl %r15d, %r15d
movq %r13, 0x28(%rsp)
movq %r12, 0x18(%rsp)
movq %rbp, 0x10(%rsp)
movq %rbp, %rdi
callq 0x3d99b
cmpl $0x0, 0x84(%rbx)
je 0x3ab83
movq %r13, %rdi
callq 0x3a18a
movq 0x60(%rsp), %rdi
callq 0x3d7a5
movq %r12, %rdi
callq 0x3d81e
cmpl $0x0, 0x80(%rbx)
movl $0x0, %r15d
je 0x3ab44
jmp 0x3aaf1
cmpl $0x0, 0x33c(%rbx)
jne 0x3aba0
movq 0x40(%rsp), %rdi
callq 0x3da34
movl $0x1, 0x344(%rbx)
movq 0x8(%rbx), %rcx
movl %r15d, %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 0x3abd6
movl $0x0, (%r14)
jmp 0x3ae1e
addl %eax, %eax
movl $0x10000, %ecx          # imm = 0x10000
subl %eax, %ecx
movl $0x2, %ebp
cmpl $0x3, %ecx
jb 0x3addd
movl %ecx, %eax
leaq (%r14,%rax,4), %rax
movq %rax, 0x50(%rsp)
movl $0x2, %ebp
xorl %r12d, %r12d
movl $0x2, %eax
movl %ecx, 0x24(%rsp)
movq %rax, 0x38(%rsp)
movl 0x2d8(%rbx), %eax
movl 0x2dc(%rbx), %ecx
subl %eax, %ecx
jne 0x3ac6f
movq %r13, %rdi
callq 0x3ae78
andl $0x1, %eax
shll $0x11, %eax
movq 0x2d0(%rbx), %rcx
movl 0x4(%rcx,%rax,4), %edx
movl (%rcx,%rax,4), %ecx
addl %eax, %ecx
movl %ecx, 0x2dc(%rbx)
movl %edx, 0x2e0(%rbx)
orl $0x2, %eax
movl %r12d, %ecx
addl %edx, %ecx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmovbl %esi, %ecx
movl %eax, 0x2d8(%rbx)
movl %ecx, 0x4(%r14)
cmpl 0x2f4(%rbx), %edx
jae 0x3ac0e
jmp 0x3adec
movl 0x2f8(%rbx), %edi
movl 0x308(%rbx), %esi
movl 0x2e0(%rbx), %edx
movl 0x2f0(%rbx), %r13d
cmpl %edx, %r13d
cmovael %edx, %r13d
subl %r13d, %edx
incl %edx
cmpl %ecx, %edx
cmovael %ecx, %edx
movl 0x30c(%rbx), %r8d
movl %r8d, %ebp
movq %rsi, 0x48(%rsp)
subl %esi, %ebp
cmpl %edx, %ebp
cmovael %edx, %ebp
movl %ebp, %ecx
addl %edi, %ecx
jae 0x3acef
subl %r8d, %edi
movl %r8d, 0x2f8(%rbx)
movq 0x2e8(%rbx), %rsi
leaq (%r8,%r8), %rdx
movq %r8, 0x8(%rsp)
callq 0x37bc5
movl 0x2d8(%rbx), %eax
movl 0x30c(%rbx), %ecx
movq %rcx, 0x30(%rsp)
movq 0x8(%rsp), %rdi
movq %rdi, %rsi
jmp 0x3acfa
movq %rdi, %rsi
movl %r8d, %ecx
movq %rcx, 0x30(%rsp)
movq %rdi, 0x8(%rsp)
movl %edi, 0x4(%rsp)
movq 0x300(%rbx), %rdx
movl %r13d, %ecx
leaq (%rdx,%rcx), %rdi
decq %rdi
movq 0x2e8(%rbx), %rcx
movl 0x310(%rbx), %r8d
movq 0x38(%rsp), %r9
leaq (%r14,%r9,4), %r9
movl 0x2f4(%rbx), %r11d
decl %r11d
movl %eax, %eax
shlq $0x2, %rax
addq 0x2d0(%rbx), %rax
movl %ebp, %ebp
leaq (%rax,%rbp,4), %rbp
subq $0x8, %rsp
leaq 0xc(%rsp), %r10
pushq %r10
pushq 0x40(%rsp)
movq 0x60(%rsp), %r13
pushq %r13
pushq %rbp
pushq 0x78(%rsp)
pushq %rax
pushq %r11
callq 0x3afa8
addq $0x40, %rsp
testq %rax, %rax
je 0x3ae56
movq %rax, %rbp
subq %r14, %rbp
shrq $0x2, %rbp
movl 0x4(%rsp), %eax
movl %eax, %ecx
subl 0x8(%rsp), %ecx
addl %ecx, 0x2d8(%rbx)
addl %ecx, %r13d
addq %rcx, 0x300(%rbx)
movl %eax, %ecx
subl 0x2f8(%rbx), %ecx
addl %ecx, %r12d
subl %ecx, 0x2e0(%rbx)
movl %eax, 0x2f8(%rbx)
cmpl 0x30c(%rbx), %r13d
movl $0x0, %eax
cmovel %eax, %r13d
movl %r13d, 0x308(%rbx)
movl %ebp, %eax
movl 0x24(%rsp), %ecx
cmpl %ebp, %ecx
movq 0x28(%rsp), %r13
ja 0x3ac09
movl %ebp, (%r14)
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %rbp
jmp 0x3ae1e
movl $0x0, 0x2e0(%rbx)
addl %edx, %ebp
movl %ebp, (%r14)
testq %rdx, %rdx
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %rbp
je 0x3ae1e
movq 0x38(%rsp), %rax
leaq (%r14,%rax,4), %rdi
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x41c0
incl %r15d
movq 0x40(%rsp), %rdi
callq 0x3da3e
movl $0x0, 0x344(%rbx)
movq 0x58(%rsp), %rdi
movl $0x1, %esi
callq 0x3d936
cmpl $0x0, 0x80(%rbx)
je 0x3ab44
jmp 0x3aaf1
movl $0x1, 0x2e4(%rbx)
movl $0x0, (%r14)
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %rbp
movq 0x28(%rsp), %r13
jmp 0x3ae1e