// File: /workspace/github_cpp_makefile_star2_O3/twekkel[P]mzpq/libzpaq.cpp
// Function: libzpaq::LZBuffer::write_match(unsigned int, unsigned int)
void LZBuffer::write_match(unsigned len, unsigned off) {

  // mm,mmm,n,ll,r,q[mmmmm-8] = match n*4+ll, offset ((q-1)<<rb)+r+1
  if (level==1) {
    assert(len>=minMatch && len<=maxMatch);
    assert(off>0);
    assert(len>=4);
    assert(rb>=0 && rb<=8);
    int ll=lg(len)-1;
    assert(ll>=2);
    off+=(1<<rb)-1;
    int lo=lg(off)-1-rb;
    assert(lo>=0 && lo<=23);
    putb((lo+8)>>3, 2);// mm
    putb(lo&7, 3);     // mmm
    while (--ll>=2) {  // n
      putb(1, 1);
      putb((len>>ll)&1, 1);
    }
    putb(0, 1);
    putb(len&3, 2);    // ll
    putb(off, rb);     // r
    putb(off>>rb, lo); // q
  }

  // x[2]:len[6] off[x-1] 
  else {
    assert(level==2);
    assert(minMatch>=1 && minMatch<=64);
    --off;
    while (len>0) {  // Split long matches to len1=minMatch..minMatch+63
      const unsigned len1=len>minMatch*2+63 ? minMatch+63 :
          len>minMatch+63 ? len-minMatch : len;
      assert(wpos<BUFSIZE-5);
      assert(len1>=minMatch && len1<minMatch+64);
      if (off<(1<<16)) {
        put(64+len1-minMatch);
        put(off>>8);
        put(off);
      }
      else if (off<(1<<24)) {
        put(128+len1-minMatch);
        put(off>>16);
        put(off>>8);
        put(off);
      }
      else {
        put(192+len1-minMatch);
        put(off>>24);
        put(off>>16);
        put(off>>8);
        put(off);
      }
      len-=len1;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
cmpl $0x1, 0x2c(%rdi)
jne 0x2a0c2
movl %esi, %eax
shrl $0x10, %eax
movl $0x10000, %r11d         # imm = 0x10000
xorl %ecx, %ecx
cmpl %r11d, %esi
setae %cl
movl %esi, %ebp
cmovbl %esi, %eax
shll $0x4, %ecx
leal 0x8(%rcx), %r8d
movl %eax, %r9d
shrl $0x8, %r9d
movl $0x100, %edi            # imm = 0x100
cmpl %edi, %eax
cmovbl %eax, %r9d
cmovbl %ecx, %r8d
leal 0x4(%r8), %eax
movl %r9d, %r10d
shrl $0x4, %r10d
cmpl $0x10, %r9d
cmovbl %r9d, %r10d
cmovbl %r8d, %eax
movl 0x68(%rbx), %ecx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
shll %cl, %r14d
leaq 0xed6e(%rip), %r8       # 0x38d0b
movsbl (%r10,%r8), %r9d
notl %r14d
addl %edx, %r14d
movl %r14d, %edx
shrl $0x10, %edx
xorl %r10d, %r10d
cmpl %r11d, %r14d
setae %r10b
cmovbl %r14d, %edx
shll $0x4, %r10d
movl %edx, %esi
shrl $0x8, %esi
cmpl %edi, %edx
leal 0x8(%r10), %edi
cmovbl %edx, %esi
cmovbl %r10d, %edi
leal 0x4(%rdi), %edx
movl %esi, %r10d
shrl $0x4, %r10d
cmpl $0x10, %esi
cmovbl %esi, %r10d
cmovbl %edi, %edx
leal (%rax,%r9), %r12d
decl %r12d
movsbl (%r10,%r8), %eax
notl %ecx
addl %eax, %ecx
leal (%rdx,%rcx), %esi
addl $0x8, %esi
movl %ecx, %r15d
addl %edx, %r15d
sarl $0x3, %esi
movq %rbx, %rdi
movl $0x2, %edx
callq 0x33e04
movl %r15d, %esi
andl $0x7, %esi
movq %rbx, %rdi
movl $0x3, %edx
callq 0x33e04
cmpl $0x3, %r12d
jl 0x2a08b
movl 0x6c(%rbx), %ecx
movl 0x70(%rbx), %eax
btsl %eax, %ecx
movl %ecx, 0x6c(%rbx)
incl %eax
cmpl $0x8, %eax
jb 0x2a061
movl 0x78(%rbx), %edx
movl %ebp, %edi
movl %edx, %esi
incl %edx
movb %cl, 0x90(%rbx,%rsi)
shrl $0x8, %ecx
addl $-0x8, %eax
cmpl $0x7, %eax
ja 0x2a043
movl %edx, 0x78(%rbx)
movl %ecx, 0x6c(%rbx)
jmp 0x2a063
movl %ebp, %edi
leal -0x1(%r12), %r13d
movl %eax, 0x70(%rbx)
xorl %esi, %esi
btl %r13d, %edi
setb %sil
movq %rbx, %rdi
movl $0x1, %edx
callq 0x33e04
cmpl $0x3, %r12d
movl %r13d, %r12d
jg 0x2a02b
movl 0x70(%rbx), %eax
incl %eax
cmpl $0x8, %eax
jb 0x2a1f0
movl 0x6c(%rbx), %ecx
movl 0x78(%rbx), %edx
movl %ebp, %esi
movl %edx, %edi
incl %edx
movb %cl, 0x90(%rbx,%rdi)
shrl $0x8, %ecx
addl $-0x8, %eax
cmpl $0x7, %eax
ja 0x2a0a1
movl %edx, 0x78(%rbx)
movl %ecx, 0x6c(%rbx)
jmp 0x2a1f2
testl %esi, %esi
je 0x2a1e1
decl %edx
movl 0x3c(%rbx), %eax
movl 0x78(%rbx), %r9d
leal 0x3f(,%rax,2), %ecx
leal 0x3f(%rax), %r8d
movl %edx, %edi
shrl $0x18, %edi
movl %edi, 0x4(%rsp)
movl %edx, %r11d
shrl $0x10, %r11d
movl %edx, %r10d
shrl $0x8, %r10d
movl %r10d, (%rsp)
movl %eax, %edi
cmpl %r8d, %esi
ja 0x2a102
xorl %edi, %edi
movl %esi, %ebp
subl %edi, %ebp
cmpl %ecx, %esi
cmoval %r8d, %ebp
movl %r9d, %r15d
cmpl $0xffff, %edx           # imm = 0xFFFF
ja 0x2a140
movl %ebp, %edi
subl %eax, %edi
addb $0x40, %dil
leal 0x1(%r9), %r12d
movb %dil, 0x90(%rbx,%r15)
leal 0x2(%r9), %r14d
movb %r10b, 0x90(%rbx,%r12)
addl $0x3, %r9d
jmp 0x2a1cb
leal 0x1(%r9), %r13d
leal 0x2(%r9), %edi
leal 0x3(%r9), %r14d
leal 0x4(%r9), %r12d
cmpl $0xffffff, %edx         # imm = 0xFFFFFF
ja 0x2a182
movl %ebp, %r9d
xorl $0x80, %r9d
subl %eax, %r9d
movb %r9b, 0x90(%rbx,%r15)
movb %r11b, 0x90(%rbx,%r13)
movb %r10b, 0x90(%rbx,%rdi)
movl %r12d, %r9d
jmp 0x2a1cb
movl %ecx, %r10d
movl %r11d, %ecx
movl %ebp, %r11d
subl %eax, %r11d
addb $-0x40, %r11b
movb %r11b, 0x90(%rbx,%r15)
movl 0x4(%rsp), %r11d
movb %r11b, 0x90(%rbx,%r13)
movl %ecx, %r11d
movl %r10d, %ecx
movl (%rsp), %r10d
movb %r11b, 0x90(%rbx,%rdi)
movl %r14d, %edi
movb %r10b, 0x90(%rbx,%rdi)
addl $0x5, %r9d
movl %r12d, %r14d
movl %r14d, %edi
movb %dl, 0x90(%rbx,%rdi)
subl %ebp, %esi
jne 0x2a0f9
movl %r9d, 0x78(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebp, %esi
movl %eax, 0x70(%rbx)
andl $0x3, %esi
movq %rbx, %rdi
movl $0x2, %edx
callq 0x33e04
movl 0x68(%rbx), %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x33e04
movb 0x68(%rbx), %cl
shrl %cl, %r14d
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x33e04