// File: /workspace/github_cpp_makefile_star2_O2/twekkel[P]mzpq/libzpaq.cpp
// Function: libzpaq::LZBuffer::LZBuffer(libzpaq::StringBuffer&, int*, unsigned int const*)
LZBuffer::LZBuffer(StringBuffer& inbuf, int args[], const unsigned* sap):
    ht((args[1]&3)==3 ? (inbuf.size()+1)*!sap      // for BWT suffix array
        : args[5]-args[0]<21 ? 1u<<args[5]         // for LZ77 hash table
        : (inbuf.size()*!sap)+(1u<<17<<args[0])),  // for LZ77 SA and ISA
    in(inbuf.data()),
    checkbits(args[5]-args[0]<21 ? 12-args[0] : 17+args[0]),
    level(args[1]&3),
    htsize(ht.size()),
    n(inbuf.size()),
    i(0),
    minMatch(args[2]),
    minMatch2(args[3]),
    maxMatch(BUFSIZE*3),
    maxLiteral(BUFSIZE/4),
    lookahead(args[6]),
    h1(0), h2(0),
    bucket((1<<args[4])-1), 
    shift1(minMatch>0 ? (args[5]-1)/minMatch+1 : 1),
    shift2(minMatch2>0 ? (args[5]-1)/minMatch2+1 : 0),
    minMatchBoth(MAX(minMatch, minMatch2+lookahead)+4),
    rb(args[0]>4 ? args[0]-4 : 0),
    bits(0), nbits(0), rpos(0), wpos(0),
    idx(0), sa(0), isa(0) {
  assert(args[0]>=0);
  assert(n<=(1u<<20<<args[0]));
  assert(args[1]>=1 && args[1]<=7 && args[1]!=4);
  assert(level>=1 && level<=3);
  if ((minMatch<4 && level==1) || (minMatch<1 && level==2))
    error("match length $3 too small");

  // e8e9 transform
  if (args[1]>4 && !sap) e8e9(inbuf.data(), n);

  // build suffix array if not supplied
  if (args[5]-args[0]>=21 || level==3) {  // LZ77-SA or BWT
    if (sap)
      sa=sap;
    else {
      assert(ht.size()>=n);
      assert(ht.size()>0);
      sa=&ht[0];
      if (n>0) divsufsort((const unsigned char*)in, (int*)sa, n);
    }
    if (level<3) {
      assert(ht.size()>=(n*(sap==0))+(1u<<17<<args[0]));
      isa=&ht[n*(sap==0)];
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x1363e(%rip), %rax     # 0x2abd8
movq %rax, (%rdi)
leaq 0x8(%rdi), %r13
movl 0x4(%rdx), %eax
notl %eax
testb $0x3, %al
jne 0x175bd
movq 0x20(%r12), %rax
incq %rax
xorl %esi, %esi
testq %r14, %r14
cmoveq %rax, %rsi
jmp 0x175ef
movl (%r15), %ecx
movl 0x14(%r15), %eax
movl %eax, %edx
subl %ecx, %edx
cmpl $0x14, %edx
jg 0x175d7
pushq $0x1
popq %rsi
movl %eax, %ecx
shlq %cl, %rsi
jmp 0x175ef
testq %r14, %r14
jne 0x175e3
movq 0x20(%r12), %rax
jmp 0x175e5
xorl %eax, %eax
movl $0x20000, %esi          # imm = 0x20000
shll %cl, %esi
addq %rax, %rsi
xorl %ebp, %ebp
movq %r13, %rdi
xorl %edx, %edx
callq 0x1c600
movq 0x10(%r12), %rax
movq %rax, 0x20(%rbx)
movl (%r15), %eax
movl 0x14(%r15), %ecx
subl %eax, %ecx
pushq $0xc
popq %rdx
subl %eax, %edx
addl $0x11, %eax
cmpl $0x15, %ecx
cmovll %edx, %eax
movl %eax, 0x28(%rbx)
movl 0x4(%r15), %esi
andl $0x3, %esi
movl %esi, 0x2c(%rbx)
movl 0x10(%rbx), %eax
movl %eax, 0x30(%rbx)
movl 0x20(%r12), %eax
movl %eax, 0x34(%rbx)
andl $0x0, 0x38(%rbx)
movl 0x8(%r15), %edi
movl %edi, 0x3c(%rbx)
movl 0xc(%r15), %r9d
movl %r9d, 0x40(%rbx)
movabsq $0x10000000c000, %rax   # imm = 0x10000000C000
movq %rax, 0x44(%rbx)
movl 0x18(%r15), %r8d
movl %r8d, 0x4c(%rbx)
andq $0x0, 0x50(%rbx)
movb 0x10(%r15), %cl
pushq $-0x1
popq %rax
shll %cl, %eax
notl %eax
movl %eax, 0x58(%rbx)
testl %edi, %edi
je 0x17684
movl 0x14(%r15), %eax
decl %eax
xorl %edx, %edx
divl %edi
incl %eax
jmp 0x17687
pushq $0x1
popq %rax
movl %eax, 0x5c(%rbx)
testl %r9d, %r9d
je 0x1769e
movl 0x14(%r15), %eax
decl %eax
xorl %edx, %edx
divl %r9d
movl %eax, %ebp
incl %ebp
movl %ebp, 0x60(%rbx)
addl %r9d, %r8d
cmpl %r8d, %edi
cmoval %edi, %r8d
addl $0x4, %r8d
movl %r8d, 0x64(%rbx)
movl (%r15), %eax
leal -0x4(%rax), %ecx
xorl %edx, %edx
cmpl $0x5, %eax
cmovgel %ecx, %edx
movl %edx, 0x68(%rbx)
cmpl $0x4, %edi
setb %cl
cmpl $0x1, %esi
sete %dl
xorl $0x2, %esi
orl %edi, %esi
sete %al
xorps %xmm0, %xmm0
movups %xmm0, 0x6c(%rbx)
movups %xmm0, 0x7c(%rbx)
andl $0x0, 0x8c(%rbx)
testb %dl, %cl
jne 0x176f2
testb %al, %al
je 0x176fe
leaq 0xaffe(%rip), %rdi      # 0x226f7
callq 0x44dc
testq %r14, %r14
jne 0x17717
cmpl $0x5, 0x4(%r15)
jl 0x17717
movq 0x10(%r12), %rdi
movl 0x34(%rbx), %esi
callq 0x16a9f
movl 0x14(%r15), %eax
subl (%r15), %eax
cmpl $0x15, %eax
setge %cl
movl 0x2c(%rbx), %eax
cmpl $0x3, %eax
sete %dl
orb %cl, %dl
cmpb $0x1, %dl
jne 0x17780
testq %r14, %r14
je 0x17742
movq %r14, 0x80(%rbx)
jmp 0x17760
movq 0x8(%rbx), %rsi
movq %rsi, 0x80(%rbx)
movl 0x34(%rbx), %edx
testl %edx, %edx
je 0x17760
movq 0x20(%rbx), %rdi
callq 0x14608
movl 0x2c(%rbx), %eax
cmpl $0x2, %eax
jg 0x17780
movl 0x34(%rbx), %eax
xorl %ecx, %ecx
testq %r14, %r14
cmoveq %rax, %rcx
shlq $0x2, %rcx
addq 0x8(%rbx), %rcx
movq %rcx, 0x88(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r13, %rdi
callq 0x1c6ca
movq %rbx, %rdi
callq 0x4320