// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movq %rdi, %rbx
addq $0x88, %rdi
leaq 0x158(%rbx), %r13
leaq 0x4f0(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0x318(%rbx), %rax
movq %rax, 0x28(%rsp)
leaq 0x1c0(%rbx), %rax
movq %rax, 0x50(%rsp)
leaq 0xf0(%rbx), %rax
movq %rax, 0x30(%rsp)
movq %rdi, 0x38(%rsp)
movq %r13, 0x18(%rsp)
callq 0x35001
xorl %ebp, %ebp
cmpl $0x0, 0x80(%rbx)
jne 0x32a93
movq %r13, %rdi
callq 0x35170
cmpl $0x0, 0x84(%rbx)
jne 0x32a75
cmpl $0x0, 0x33c(%rbx)
jne 0x327d7
movq 0x20(%rsp), %rdi
callq 0x351fe
movl $0x1, 0x344(%rbx)
movq 0x8(%rbx), %rcx
movl %ebp, 0x14(%rsp)
movl %ebp, %edx
andl $0xf, %edx
shll $0x12, %edx
leaq (%rcx,%rdx), %r12
movl 0x2f0(%rbx), %eax
movl 0x2e0(%rbx), %esi
movl %esi, 0x4(%rcx,%rdx)
cmpl $0x0, 0x2e4(%rbx)
je 0x32832
andl $0x0, (%r12)
movl 0x14(%rsp), %ebp
incl %ebp
movq 0x20(%rsp), %rdi
callq 0x35208
andl $0x0, 0x344(%rbx)
movq 0x50(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x3510d
jmp 0x32798
addl %eax, %eax
movl $0x10000, %ecx          # imm = 0x10000
subl %eax, %ecx
movl %ecx, %eax
movq %rax, 0x48(%rsp)
xorl %r15d, %r15d
pushq $0x2
popq %rax
movl %eax, %r14d
movl %ecx, 0x10(%rsp)
cmpl %ecx, %r14d
jae 0x32a53
movl %r14d, %ebp
movl 0x2d8(%rbx), %eax
movl 0x2dc(%rbx), %ecx
subl %eax, %ecx
jne 0x328f0
movq 0x28(%rsp), %rdi
callq 0x32aa2
andl $0x1, %eax
shll $0x11, %eax
movq 0x2d0(%rbx), %rdx
movl 0x4(%rdx,%rax,4), %ecx
movl (%rdx,%rax,4), %edx
addl %eax, %edx
movl %edx, 0x2dc(%rbx)
movl %ecx, 0x2e0(%rbx)
orl $0x2, %eax
movl %r15d, %edx
addl %ecx, %edx
pushq $-0x1
popq %rsi
cmovbl %esi, %edx
movl %eax, 0x2d8(%rbx)
movl %edx, 0x4(%r12)
movl 0x2f4(%rbx), %eax
cmpl %eax, %ecx
jae 0x328e3
andl $0x0, 0x2e0(%rbx)
leal (%rcx,%r14), %edx
movl %edx, (%r12)
leaq (%r12,%rbp,4), %r12
movl %ecx, %edx
subl $0x1, %edx
jb 0x328e3
andl $0x0, (%r12)
addq $0x4, %r12
jmp 0x328d3
cmpl %eax, %ecx
jae 0x3285b
jmp 0x32809
movl 0x2f8(%rbx), %edi
movl 0x308(%rbx), %esi
movl 0x2e0(%rbx), %edx
movl 0x2f0(%rbx), %r8d
cmpl %edx, %r8d
cmovael %edx, %r8d
subl %r8d, %edx
incl %edx
cmpl %ecx, %edx
cmovael %ecx, %edx
movl 0x30c(%rbx), %r13d
movl %r13d, %r14d
movq %rsi, 0x40(%rsp)
subl %esi, %r14d
cmpl %edx, %r14d
cmovael %edx, %r14d
movl %r14d, %ecx
addl %edi, %ecx
jae 0x32977
subl %r13d, %edi
movl %r13d, 0x2f8(%rbx)
movq 0x2e8(%rbx), %rsi
leaq (,%r13,2), %rdx
movl %r8d, 0x8(%rsp)
callq 0x2f8e9
movl 0x8(%rsp), %r8d
movl 0x2d8(%rbx), %eax
movl 0x30c(%rbx), %r10d
movq %r13, %rsi
movl %r13d, %edi
jmp 0x3297d
movq %rdi, %rsi
movl %r13d, %r10d
movq %rdi, 0x8(%rsp)
movl %edi, 0x4(%rsp)
movq 0x300(%rbx), %rdx
movl %r8d, %ecx
leaq (%rdx,%rcx), %rdi
decq %rdi
movq 0x2e8(%rbx), %rcx
movl 0x310(%rbx), %r8d
leaq (%r12,%rbp,4), %r9
movl 0x2f4(%rbx), %r11d
movl %eax, %eax
shlq $0x2, %rax
addq 0x2d0(%rbx), %rax
decl %r11d
movq 0x48(%rsp), %r13
leaq (%r12,%r13,4), %r13
movl %r14d, %r14d
leaq (%rax,%r14,4), %r14
subq $0x8, %rsp
leaq 0xc(%rsp), %rbp
pushq %rbp
pushq %r10
movq 0x58(%rsp), %rbp
pushq %rbp
pushq %r14
pushq %r13
pushq %rax
pushq %r11
callq 0x32bc8
addq $0x40, %rsp
testq %rax, %rax
je 0x32a5c
movq %rax, %r14
movl 0x4(%rsp), %eax
movl %eax, %ecx
subl 0x8(%rsp), %ecx
addl %ecx, 0x2d8(%rbx)
subq %r12, %r14
addq %rcx, 0x300(%rbx)
shrq $0x2, %r14
movl %eax, %edx
subl 0x2f8(%rbx), %edx
addl %ecx, %ebp
subl %edx, 0x2e0(%rbx)
addl %edx, %r15d
movl %eax, 0x2f8(%rbx)
cmpl 0x30c(%rbx), %ebp
movl $0x0, %eax
cmovel %eax, %ebp
movl %ebp, 0x308(%rbx)
movq 0x18(%rsp), %r13
movl 0x10(%rsp), %ecx
jmp 0x3284f
movl %r14d, (%r12)
jmp 0x32809
movl $0x1, 0x2e4(%rbx)
andl $0x0, (%r12)
movq 0x18(%rsp), %r13
jmp 0x32809
movq 0x28(%rsp), %rdi
callq 0x31e50
movq 0x30(%rsp), %rdi
callq 0x34f8b
movq 0x38(%rsp), %rdi
jmp 0x32791
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq