// File: /workspace/github_cpp_makefile_star2_O2/twekkel[P]mzpq/libzpaq.cpp
// Function: libzpaq::ZPAQL::read(libzpaq::Reader*)
int ZPAQL::read(Reader* in2) {

  // Get header size and allocate
  int hsize=in2->get();
  hsize+=in2->get()*256;
  header.resize(hsize+300);
  cend=hbegin=hend=0;
  header[cend++]=hsize&255;
  header[cend++]=hsize>>8;
  while (cend<7) header[cend++]=in2->get(); // hh hm ph pm n

  // Read COMP
  int n=header[cend-1];
  for (int i=0; i<n; ++i) {
    int type=in2->get();  // component type
    if (type<0 || type>255) error("unexpected end of file");
    header[cend++]=type;  // component type
    int size=compsize[type];
    if (size<1) error("Invalid component type");
    if (cend+size>hsize) error("COMP overflows header");
    for (int j=1; j<size; ++j)
      header[cend++]=in2->get();
  }
  if ((header[cend++]=in2->get())!=0) error("missing COMP END");

  // Insert a guard gap and read HCOMP
  hbegin=hend=cend+128;
  if (hend>hsize+129) error("missing HCOMP");
  while (hend<hsize+129) {
    assert(hend<header.isize()-8);
    int op=in2->get();
    if (op==-1) error("unexpected end of file");
    header[hend++]=op;
  }
  if ((header[hend++]=in2->get())!=0) error("missing HCOMP END");
  assert(cend>=7 && cend<header.isize());
  assert(hbegin==cend+128 && hbegin<header.isize());
  assert(hend>hbegin && hend<header.isize());
  assert(hsize==header[0]+256*header[1]);
  assert(hsize==cend-2+hend-hbegin);
  allocx(rcode, rcode_size, 0);  // clear JIT code
  return cend+hend-hbegin;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rax
movq %rsi, %rdi
callq *(%rax)
movl %eax, %r12d
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
shll $0x8, %eax
leaq 0x10(%rbx), %r15
leal (%rax,%r12), %ecx
addl $0x12c, %ecx            # imm = 0x12C
movl %eax, %r13d
addl %r12d, %r13d
movslq %ecx, %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x1c46e
andl $0x0, 0x30(%rbx)
movq $0x1, 0x28(%rbx)
movq 0x10(%rbx), %rax
movb %r12b, (%rax)
movl %r13d, %eax
shrl $0x8, %eax
movslq 0x28(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x28(%rbx)
movq 0x10(%rbx), %rdx
movb %al, (%rdx,%rcx)
movslq 0x28(%rbx), %rax
cmpq $0x6, %rax
jg 0x9562
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
jmp 0x953d
movq (%r15), %rcx
movzbl -0x1(%rcx,%rax), %eax
movl %eax, 0x4(%rsp)
xorl %r12d, %r12d
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
movl %eax, %ebp
cmpl 0x4(%rsp), %r12d
je 0x960e
cmpl $0x100, %ebp            # imm = 0x100
jb 0x959a
leaq 0x1885f(%rip), %rdi     # 0x21df4
callq 0x44dc
movslq 0x28(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x28(%rbx)
movq 0x10(%rbx), %rcx
movb %bpl, (%rcx,%rax)
movslq %ebp, %rax
leaq 0x1553a(%rip), %rcx     # 0x1eaf0
movl (%rcx,%rax,4), %ebp
testl %ebp, %ebp
jg 0x95c9
leaq 0x18847(%rip), %rdi     # 0x21e0b
callq 0x44dc
movl 0x28(%rbx), %eax
addl %ebp, %eax
cmpl %r13d, %eax
jle 0x95df
leaq 0x18848(%rip), %rdi     # 0x21e22
callq 0x44dc
pushq $0x1
popq %r15
cmpl %ebp, %r15d
jge 0x9606
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
movslq 0x28(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x28(%rbx)
movq 0x10(%rbx), %rdx
movb %al, (%rdx,%rcx)
incl %r15d
jmp 0x95e3
incl %r12d
jmp 0x9571
movslq 0x28(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x28(%rbx)
movq 0x10(%rbx), %rcx
movb %bpl, (%rcx,%rax)
testb %bpl, %bpl
je 0x9631
leaq 0x1880c(%rip), %rdi     # 0x21e38
callq 0x44dc
movl 0x28(%rbx), %eax
subl $-0x80, %eax
movl %eax, 0x30(%rbx)
movl %eax, 0x2c(%rbx)
addl $0x81, %r13d
cmpl %r13d, %eax
jle 0x9655
leaq 0x187f9(%rip), %rdi     # 0x21e49
callq 0x44dc
leaq 0x18798(%rip), %r15     # 0x21df4
movl 0x30(%rbx), %r12d
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
movl %eax, %ebp
cmpl %r13d, %r12d
jge 0x9690
cmpl $-0x1, %ebp
jne 0x967c
movq %r15, %rdi
callq 0x44dc
movslq 0x30(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x30(%rbx)
movq 0x10(%rbx), %rcx
movb %bpl, (%rcx,%rax)
jmp 0x965c
movslq 0x30(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x30(%rbx)
movq 0x10(%rbx), %rcx
movb %bpl, (%rcx,%rax)
testb %bpl, %bpl
je 0x96b3
leaq 0x187a9(%rip), %rdi     # 0x21e57
callq 0x44dc
leaq 0xb8(%rbx), %rdi
leaq 0xb4(%rbx), %rsi
xorl %edx, %edx
callq 0x4c24
movl 0x30(%rbx), %eax
addl 0x28(%rbx), %eax
subl 0x2c(%rbx), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq