// File: /workspace/github_cpp_makefile_star2_O1/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, %ebp
addl %r12d, %ebp
movslq %ecx, %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x4a126
movl $0x0, 0x30(%rbx)
movq $0x1, 0x28(%rbx)
movq 0x10(%rbx), %rax
movb %r12b, (%rax)
movslq 0x28(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x28(%rbx)
movq 0x10(%rbx), %rcx
movl %ebp, %edx
movl %ebp, %r13d
movb %dh, (%rcx,%rax)
movl 0x28(%rbx), %eax
cmpl $0x6, %eax
jg 0x99a0
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)
movl 0x28(%rbx), %eax
cmpl $0x7, %eax
jl 0x997f
movq (%r15), %rcx
movl %eax, %eax
movzbl -0x1(%rcx,%rax), %r12d
testl %r12d, %r12d
je 0x9a49
xorl %r15d, %r15d
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
movl %eax, %ebp
cmpl $0x100, %eax            # imm = 0x100
jb 0x99d4
leaq 0x453f5(%rip), %rdi     # 0x4edc4
callq 0x455c
movslq 0x28(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x28(%rbx)
movq 0x10(%rbx), %rcx
movb %bpl, (%rcx,%rax)
movslq %ebp, %rax
leaq 0x420d0(%rip), %rcx     # 0x4bac0
movl (%rcx,%rax,4), %ebp
testl %ebp, %ebp
jg 0x9a03
leaq 0x453dd(%rip), %rdi     # 0x4eddb
callq 0x455c
movl 0x28(%rbx), %eax
addl %ebp, %eax
cmpl %r13d, %eax
jle 0x9a19
leaq 0x453de(%rip), %rdi     # 0x4edf2
callq 0x455c
cmpl $0x2, %ebp
jl 0x9a3d
decl %ebp
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)
decl %ebp
jne 0x9a20
incl %r15d
cmpl %r12d, %r15d
jne 0x99b7
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)
testb %al, %al
je 0x9a72
leaq 0x4539b(%rip), %rdi     # 0x4ee08
callq 0x455c
movl 0x28(%rbx), %eax
subl $-0x80, %eax
movl %eax, 0x30(%rbx)
movl %eax, 0x2c(%rbx)
addl $0x81, %r13d
movl %r13d, %r12d
cmpl %r13d, %eax
jle 0x9a99
leaq 0x45385(%rip), %rdi     # 0x4ee19
callq 0x455c
cmpl %r12d, 0x30(%rbx)
jge 0x9ad5
leaq 0x4531e(%rip), %r15     # 0x4edc4
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
movl %eax, %ebp
cmpl $-0x1, %eax
jne 0x9abd
movq %r15, %rdi
callq 0x455c
movslq 0x30(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x30(%rbx)
movq 0x10(%rbx), %rcx
movb %bpl, (%rcx,%rax)
cmpl %r12d, 0x30(%rbx)
jl 0x9aa6
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
movslq 0x30(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x30(%rbx)
movq 0x10(%rbx), %rdx
movb %al, (%rdx,%rcx)
testb %al, %al
je 0x9afe
leaq 0x4532e(%rip), %rdi     # 0x4ee27
callq 0x455c
movq 0xb8(%rbx), %rdi
testq %rdi, %rdi
sete %cl
movl 0xb4(%rbx), %eax
testl %eax, %eax
sete %dl
testb %dl, %cl
jne 0x9b3c
testq %rdi, %rdi
je 0x9b27
movslq %eax, %rsi
callq 0x40f0
movq $0x0, 0xb8(%rbx)
movl $0x0, 0xb4(%rbx)
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