// File: /workspace/github_cpp_makefile_star2_O3/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 0x170c8(%rip), %rax     # 0x40bd8
movq %rax, (%rdi)
leaq 0x8(%rdi), %r13
movl 0x4(%rdx), %eax
notl %eax
testb $0x3, %al
jne 0x29b33
movq 0x20(%r12), %rax
incq %rax
xorl %esi, %esi
testq %r14, %r14
cmoveq %rax, %rsi
jmp 0x29b67
movl (%r15), %ecx
movl 0x14(%r15), %eax
movl %eax, %edx
subl %ecx, %edx
cmpl $0x14, %edx
jg 0x29b4f
movl $0x1, %esi
movl %eax, %ecx
shlq %cl, %rsi
jmp 0x29b67
testq %r14, %r14
jne 0x29b5b
movq 0x20(%r12), %rax
jmp 0x29b5d
xorl %eax, %eax
movl $0x20000, %esi          # imm = 0x20000
shll %cl, %esi
addq %rax, %rsi
xorl %ebp, %ebp
movl %ebp, 0x10(%r13)
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
movq %r13, %rdi
xorl %edx, %edx
callq 0x3378c
movq 0x10(%r12), %rax
movq %rax, 0x20(%rbx)
movl (%r15), %eax
movl 0x14(%r15), %ecx
subl %eax, %ecx
movl $0xc, %edx
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)
movl %ebp, 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)
movq $0x0, 0x50(%rbx)
movb 0x10(%r15), %cl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
notl %eax
movl %eax, 0x58(%rbx)
testl %edi, %edi
je 0x29c0e
movl 0x14(%r15), %eax
decl %eax
xorl %edx, %edx
divl %edi
incl %eax
jmp 0x29c13
movl $0x1, %eax
movl %eax, 0x5c(%rbx)
testl %r9d, %r9d
je 0x29c2a
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
cmovll %edx, %ecx
movl %ecx, 0x68(%rbx)
cmpl $0x4, %edi
setb %cl
cmpl $0x1, %esi
sete %r8b
xorl $0x2, %esi
orl %edi, %esi
sete %al
xorps %xmm0, %xmm0
movups %xmm0, 0x6c(%rbx)
movups %xmm0, 0x7c(%rbx)
movl %edx, 0x8c(%rbx)
testb %r8b, %cl
jne 0x29c7f
testb %al, %al
je 0x29c8b
leaq 0x10211(%rip), %rdi     # 0x39e97
callq 0x455c
testq %r14, %r14
jne 0x29ca4
cmpl $0x5, 0x4(%r15)
jl 0x29ca4
movq 0x10(%r12), %rdi
movl 0x34(%rbx), %esi
callq 0x28e87
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 0x29d0d
testq %r14, %r14
je 0x29ccf
movq %r14, 0x80(%rbx)
jmp 0x29ced
movq 0x8(%rbx), %rsi
movq %rsi, 0x80(%rbx)
movl 0x34(%rbx), %edx
testl %edx, %edx
je 0x29ced
movq 0x20(%rbx), %rdi
callq 0x25e19
movl 0x2c(%rbx), %eax
cmpl $0x2, %eax
jg 0x29d0d
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 0x33ae4
movq %rbx, %rdi
callq 0x4310
nop