// File: 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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
movq -0x38(%rbp), %rdi
shll $0x8, %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
addq $0x10, %rdi
movl -0x14(%rbp), %eax
addl $0x12c, %eax            # imm = 0x12C
movslq %eax, %rsi
xorl %edx, %edx
callq 0x30370
movq -0x38(%rbp), %rcx
movl $0x0, 0x30(%rcx)
movl $0x0, 0x2c(%rcx)
movl $0x0, 0x28(%rcx)
movl -0x14(%rbp), %eax
andl $0xff, %eax
movb %al, -0x39(%rbp)
movq %rcx, %rdi
addq $0x10, %rdi
movl 0x28(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x28(%rcx)
movslq %eax, %rsi
callq 0x30630
movb -0x39(%rbp), %dl
movq -0x38(%rbp), %rcx
movb %dl, (%rax)
movl -0x14(%rbp), %eax
sarl $0x8, %eax
movb %al, -0x2d(%rbp)
movq %rcx, %rdi
addq $0x10, %rdi
movl 0x28(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x28(%rcx)
movslq %eax, %rsi
callq 0x30630
movb -0x2d(%rbp), %cl
movb %cl, (%rax)
movq -0x38(%rbp), %rax
cmpl $0x7, 0x28(%rax)
jge 0xe8ea
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
movq -0x38(%rbp), %rcx
movb %al, -0x3a(%rbp)
movq %rcx, %rdi
addq $0x10, %rdi
movl 0x28(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x28(%rcx)
movslq %eax, %rsi
callq 0x30630
movb -0x3a(%rbp), %cl
movb %cl, (%rax)
jmp 0xe8af
movq -0x38(%rbp), %rax
movq %rax, %rdi
addq $0x10, %rdi
movl 0x28(%rax), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x30630
movzbl (%rax), %eax
movl %eax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xea03
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jl 0xe937
cmpl $0xff, -0x20(%rbp)
jle 0xe943
leaq 0x295b6(%rip), %rdi     # 0x37ef4
callq 0x5720
movq -0x38(%rbp), %rcx
movl -0x20(%rbp), %eax
movb %al, -0x3b(%rbp)
movq %rcx, %rdi
addq $0x10, %rdi
movl 0x28(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x28(%rcx)
movslq %eax, %rsi
callq 0x30630
movb -0x3b(%rbp), %cl
movb %cl, (%rax)
movslq -0x20(%rbp), %rcx
leaq 0x26249(%rip), %rax     # 0x34bc0
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
cmpl $0x1, -0x24(%rbp)
jge 0xe98f
leaq 0x29581(%rip), %rdi     # 0x37f0b
callq 0x5720
movq -0x38(%rbp), %rax
movl 0x28(%rax), %eax
addl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jle 0xe9aa
leaq 0x2957d(%rip), %rdi     # 0x37f22
callq 0x5720
movl $0x1, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xe9f3
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
movq -0x38(%rbp), %rcx
movb %al, -0x3c(%rbp)
movq %rcx, %rdi
addq $0x10, %rdi
movl 0x28(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x28(%rcx)
movslq %eax, %rsi
callq 0x30630
movb -0x3c(%rbp), %cl
movb %cl, (%rax)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xe9b1
jmp 0xe9f5
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xe910
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
movq -0x38(%rbp), %rcx
movb %al, -0x3d(%rbp)
movq %rcx, %rdi
addq $0x10, %rdi
movl 0x28(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x28(%rcx)
movslq %eax, %rsi
callq 0x30630
movq %rax, %rcx
movb -0x3d(%rbp), %al
movb %al, (%rcx)
movzbl %al, %eax
cmpl $0x0, %eax
je 0xea49
leaq 0x294f4(%rip), %rdi     # 0x37f38
callq 0x5720
movq -0x38(%rbp), %rax
movl 0x28(%rax), %ecx
addl $0x80, %ecx
movl %ecx, 0x30(%rax)
movl %ecx, 0x2c(%rax)
movl 0x30(%rax), %eax
movl -0x14(%rbp), %ecx
addl $0x81, %ecx
cmpl %ecx, %eax
jle 0xea78
leaq 0x294d6(%rip), %rdi     # 0x37f49
callq 0x5720
jmp 0xea7a
movq -0x38(%rbp), %rax
movl 0x30(%rax), %eax
movl -0x14(%rbp), %ecx
addl $0x81, %ecx
cmpl %ecx, %eax
jge 0xead7
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
jne 0xeaac
leaq 0x2944d(%rip), %rdi     # 0x37ef4
callq 0x5720
movq -0x38(%rbp), %rcx
movl -0x2c(%rbp), %eax
movb %al, -0x3e(%rbp)
movq %rcx, %rdi
addq $0x10, %rdi
movl 0x30(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x30(%rcx)
movslq %eax, %rsi
callq 0x30630
movb -0x3e(%rbp), %cl
movb %cl, (%rax)
jmp 0xea7a
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
callq *(%rax)
movq -0x38(%rbp), %rcx
movb %al, -0x3f(%rbp)
movq %rcx, %rdi
addq $0x10, %rdi
movl 0x30(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x30(%rcx)
movslq %eax, %rsi
callq 0x30630
movq %rax, %rcx
movb -0x3f(%rbp), %al
movb %al, (%rcx)
movzbl %al, %eax
cmpl $0x0, %eax
je 0xeb1d
leaq 0x2943f(%rip), %rdi     # 0x37f57
callq 0x5720
movq -0x38(%rbp), %rsi
movq %rsi, %rdi
addq $0xb8, %rdi
addq $0xb4, %rsi
xorl %edx, %edx
callq 0x65c0
movq -0x38(%rbp), %rcx
movl 0x28(%rcx), %eax
addl 0x30(%rcx), %eax
subl 0x2c(%rcx), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)