// File: /workspace/github_cpp_makefile_star2_O2/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
movl %esi, %r14d
movq %rdi, %rbx
cmpl $0x1, 0x2c(%rdi)
jne 0x179b3
movl %r14d, %edi
movl %edx, %ebp
callq 0x16ae3
movl 0x68(%rbx), %r13d
pushq $-0x1
popq %r15
movl %r13d, %ecx
shll %cl, %r15d
movl %eax, %r12d
decl %r12d
notl %r15d
addl %ebp, %r15d
movl %r15d, %edi
callq 0x16ae3
notl %r13d
leal (%rax,%r13), %ebp
leal (%rax,%r13), %esi
addl $0x8, %esi
sarl $0x3, %esi
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0x1cab0
movl %ebp, %esi
andl $0x7, %esi
pushq $0x3
popq %rdx
movq %rbx, %rdi
callq 0x1cab0
pushq $0x1
popq %r13
cmpl $0x3, %r12d
jl 0x17965
decl %r12d
movq %rbx, %rdi
movl %r13d, %esi
movl %r13d, %edx
callq 0x1cab0
xorl %esi, %esi
btl %r12d, %r14d
setb %sil
movq %rbx, %rdi
movl %r13d, %edx
callq 0x1cab0
jmp 0x17937
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1cab0
andl $0x3, %r14d
pushq $0x2
popq %rdx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x1cab0
movl 0x68(%rbx), %edx
movq %rbx, %rdi
movl %r15d, %esi
callq 0x1cab0
movb 0x68(%rbx), %cl
shrl %cl, %r15d
movq %rbx, %rdi
movl %r15d, %esi
movl %ebp, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1cab0
decl %edx
movl 0x3c(%rbx), %eax
movl 0x78(%rbx), %r8d
leal 0x3f(,%rax,2), %ecx
leal 0x3f(%rax), %edi
movl %edx, %esi
shrl $0x18, %esi
movl %esi, 0x4(%rsp)
movl %edx, %r10d
shrl $0x10, %r10d
movl %edx, %r9d
shrl $0x8, %r9d
movl %edi, (%rsp)
testl %r14d, %r14d
je 0x17ad7
movl %eax, %esi
cmpl %edi, %r14d
ja 0x179f2
xorl %esi, %esi
movl %r14d, %ebp
subl %esi, %ebp
cmpl %ecx, %r14d
cmoval %edi, %ebp
movl %r8d, %r15d
cmpl $0xffff, %edx           # imm = 0xFFFF
ja 0x17a31
movl %ebp, %esi
subl %eax, %esi
addb $0x40, %sil
leal 0x1(%r8), %r12d
movb %sil, 0x90(%rbx,%r15)
leal 0x2(%r8), %r11d
movb %r9b, 0x90(%rbx,%r12)
addl $0x3, %r8d
jmp 0x17ac1
leal 0x1(%r8), %r13d
leal 0x2(%r8), %esi
leal 0x3(%r8), %r11d
leal 0x4(%r8), %r12d
cmpl $0xffffff, %edx         # imm = 0xFFFFFF
ja 0x17a73
movl %ebp, %r8d
xorl $0x80, %r8d
subl %eax, %r8d
movb %r8b, 0x90(%rbx,%r15)
movb %r10b, 0x90(%rbx,%r13)
movb %r9b, 0x90(%rbx,%rsi)
movl %r12d, %r8d
jmp 0x17ac1
movl %r9d, %edi
movl %ecx, %r9d
movl %r10d, %ecx
movl %ebp, %r10d
subl %eax, %r10d
addb $-0x40, %r10b
movb %r10b, 0x90(%rbx,%r15)
movl 0x4(%rsp), %r10d
movb %r10b, 0x90(%rbx,%r13)
movl %ecx, %r10d
movl %r9d, %ecx
movl %edi, %r9d
movl (%rsp), %edi
movb %r10b, 0x90(%rbx,%rsi)
movl %r11d, %esi
movb %r9b, 0x90(%rbx,%rsi)
addl $0x5, %r8d
movl %r12d, %r11d
movl %r8d, 0x78(%rbx)
movl %r11d, %esi
movb %dl, 0x90(%rbx,%rsi)
subl %ebp, %r14d
jmp 0x179e0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq