// File: /workspace/github_cpp_makefile_star2_O1/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
subq $0x18, %rsp
movl %esi, %ebp
movq %rdi, %rbx
cmpl $0x1, 0x2c(%rdi)
jne 0x40acf
movl %ebp, %ecx
shrl $0x10, %ecx
movl $0x10000, %eax          # imm = 0x10000
xorl %edi, %edi
cmpl %eax, %ebp
setae %dil
cmovbl %ebp, %ecx
shll $0x4, %edi
leal 0x8(%rdi), %r8d
movl %ecx, %r9d
shrl $0x8, %r9d
movl $0x100, %esi            # imm = 0x100
cmpl %esi, %ecx
cmovbl %ecx, %r9d
cmovbl %edi, %r8d
leal 0x4(%r8), %r12d
movl %r9d, %r10d
shrl $0x4, %r10d
cmpl $0x10, %r9d
cmovbl %r9d, %r10d
cmovbl %r8d, %r12d
movl 0x68(%rbx), %ecx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
shll %cl, %r14d
leaq 0xdbb0(%rip), %rdi      # 0x4e53b
movsbl (%r10,%rdi), %r10d
notl %r14d
addl %edx, %r14d
movl %r14d, %edx
shrl $0x10, %edx
xorl %r8d, %r8d
cmpl %eax, %r14d
setae %r8b
cmovbl %r14d, %edx
shll $0x4, %r8d
leal 0x8(%r8), %eax
movl %edx, %r9d
shrl $0x8, %r9d
cmpl %esi, %edx
cmovbl %edx, %r9d
cmovbl %r8d, %eax
leal 0x4(%rax), %edx
movl %r9d, %esi
shrl $0x4, %esi
cmpl $0x10, %r9d
cmovbl %r9d, %esi
cmovbl %eax, %edx
movq %r10, 0x8(%rsp)
leal (%r12,%r10), %r13d
decl %r13d
movsbl (%rsi,%rdi), %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 0x4a6ba
movl %r15d, %esi
andl $0x7, %esi
movq %rbx, %rdi
movl $0x3, %edx
callq 0x4a6ba
cmpl $0x3, %r13d
jl 0x40a5e
addl 0x8(%rsp), %r12d
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x4a6ba
leal -0x2(%r12), %eax
movzbl %al, %eax
xorl %esi, %esi
btl %eax, %ebp
setb %sil
movq %rbx, %rdi
movl $0x1, %edx
callq 0x4a6ba
decl %r12d
cmpl $0x3, %r12d
jg 0x40a25
movl 0x70(%rbx), %eax
incl %eax
cmpl $0x8, %eax
jb 0x40a8a
movl 0x6c(%rbx), %ecx
movl 0x78(%rbx), %edx
movl %edx, %esi
incl %edx
movb %cl, 0x90(%rbx,%rsi)
shrl $0x8, %ecx
addl $-0x8, %eax
cmpl $0x7, %eax
ja 0x40a6e
movl %edx, 0x78(%rbx)
movl %ecx, 0x6c(%rbx)
movl %eax, 0x70(%rbx)
andl $0x3, %ebp
movq %rbx, %rdi
movl %ebp, %esi
movl $0x2, %edx
callq 0x4a6ba
movl 0x68(%rbx), %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x4a6ba
movb 0x68(%rbx), %cl
shrl %cl, %r14d
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4a6ba
testl %ebp, %ebp
je 0x40c24
decl %edx
movl 0x3c(%rbx), %eax
movl 0x78(%rbx), %r10d
leal 0x3f(,%rax,2), %ecx
leal 0x3f(%rax), %esi
movl %edx, %edi
shrl $0x18, %edi
movl %edi, 0x8(%rsp)
movl %edx, %r8d
shrl $0x10, %r8d
movl %edx, %r9d
shrl $0x8, %r9d
movl %edx, 0x14(%rsp)
movl %eax, %edi
cmpl %esi, %ebp
ja 0x40b0d
xorl %edi, %edi
movl %ebp, %r11d
subl %edi, %r11d
cmpl %ecx, %ebp
cmoval %esi, %r11d
movl %r10d, %r15d
cmpl $0xffff, %edx           # imm = 0xFFFF
ja 0x40b59
movl %r11d, %edi
subl %eax, %edi
addb $0x40, %dil
leal 0x1(%r10), %r14d
movl %r14d, 0x78(%rbx)
movb %dil, 0x90(%rbx,%r15)
leal 0x2(%r10), %edi
movl %edi, 0x78(%rbx)
movb %r9b, 0x90(%rbx,%r14)
addl $0x3, %r10d
movl %r10d, 0x78(%rbx)
jmp 0x40c0e
leal 0x1(%r10), %edi
leal 0x2(%r10), %r13d
leal 0x3(%r10), %r12d
leal 0x4(%r10), %r14d
cmpl $0xffffff, %edx         # imm = 0xFFFFFF
ja 0x40baf
movl %r11d, %r10d
xorl $0x80, %r10d
subl %eax, %r10d
movl %edi, 0x78(%rbx)
movb %r10b, 0x90(%rbx,%r15)
movl %r13d, 0x78(%rbx)
movb %r8b, 0x90(%rbx,%rdi)
movl %r12d, 0x78(%rbx)
movb %r9b, 0x90(%rbx,%r13)
movl %r14d, 0x78(%rbx)
movb %dl, 0x90(%rbx,%r12)
jmp 0x40c18
movl %r9d, %edx
movl %ecx, %r9d
movl %r8d, %ecx
movl %r11d, %r8d
subl %eax, %r8d
addb $-0x40, %r8b
movl %edi, 0x78(%rbx)
movb %r8b, 0x90(%rbx,%r15)
movl %r13d, 0x78(%rbx)
movl 0x8(%rsp), %r8d
movb %r8b, 0x90(%rbx,%rdi)
movl %ecx, %r8d
movl %r9d, %ecx
movl %edx, %r9d
movl 0x14(%rsp), %edx
movl %r12d, 0x78(%rbx)
movb %r8b, 0x90(%rbx,%r13)
movl %r14d, 0x78(%rbx)
movb %r9b, 0x90(%rbx,%r12)
addl $0x5, %r10d
movl %r10d, 0x78(%rbx)
movl %r14d, %edi
movb %dl, 0x90(%rbx,%rdi)
movl %r10d, %r14d
movl %r14d, %r10d
subl %r11d, %ebp
jne 0x40b05
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq