// File: twekkel[P]mzpq/libzpaq.cpp
// Function: libzpaq::ZPAQL::memory()
double ZPAQL::memory() {
  double mem=pow2(header[2]+2)+pow2(header[3])  // hh hm
            +pow2(header[4]+2)+pow2(header[5])  // ph pm
            +header.size();
  int cp=7;  // start of comp list
  for (int i=0; i<header[6]; ++i) {  // n
    assert(cp<cend);
    double size=pow2(header[cp+1]); // sizebits
    switch(header[cp]) {
      case CM: mem+=4*size; break;
      case ICM: mem+=64*size+1024; break;
      case MATCH: mem+=4*size+pow2(header[cp+2]); break; // bufbits
      case MIX2: mem+=2*size; break;
      case MIX: mem+=4*size*header[cp+3]; break; // m
      case ISSE: mem+=64*size+2048; break;
      case SSE: mem+=128*size; break;
    }
    cp+=compsize[header[cp]];
  }
  return mem;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x50(%rbp)
addq $0x10, %rdi
movq %rdi, -0x38(%rbp)
movl $0x2, %esi
callq 0x30630
movzbl (%rax), %edi
addl $0x2, %edi
callq 0xf320
movq -0x38(%rbp), %rdi
movsd %xmm0, -0x48(%rbp)
movl $0x3, %esi
callq 0x30630
movzbl (%rax), %edi
callq 0xf320
movq -0x38(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x48(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0x4, %esi
callq 0x30630
movzbl (%rax), %edi
addl $0x2, %edi
callq 0xf320
movq -0x38(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x40(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0x5, %esi
callq 0x30630
movzbl (%rax), %edi
callq 0xf320
movq -0x38(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x30(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
callq 0x30610
movsd -0x28(%rbp), %xmm0
movq %rax, %xmm1
movaps 0x25245(%rip), %xmm2    # 0x34320
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x25249(%rip), %xmm2    # 0x34330
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movl $0x7, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x50(%rbp), %rdi
movl -0x18(%rbp), %eax
movl %eax, -0x54(%rbp)
addq $0x10, %rdi
movl $0x6, %esi
callq 0x30630
movq %rax, %rcx
movl -0x54(%rbp), %eax
movzbl (%rcx), %ecx
cmpl %ecx, %eax
jge 0xf311
movq -0x50(%rbp), %rdi
addq $0x10, %rdi
movq %rdi, -0x68(%rbp)
movl -0x14(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0x30630
movzbl (%rax), %edi
callq 0xf320
movq -0x68(%rbp), %rdi
movsd %xmm0, -0x20(%rbp)
movslq -0x14(%rbp), %rsi
callq 0x30630
movzbl (%rax), %eax
addl $-0x2, %eax
movl %eax, %ecx
movq %rcx, -0x60(%rbp)
subl $0x7, %eax
ja 0xf2dd
movq -0x60(%rbp), %rax
leaq 0x251f7(%rip), %rcx     # 0x34380
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movsd -0x20(%rbp), %xmm0
movsd -0x10(%rbp), %xmm1
movsd 0x251b4(%rip), %xmm2    # 0x34358
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
jmp 0xf2dd
movsd -0x20(%rbp), %xmm0
movsd 0x25185(%rip), %xmm1    # 0x34348
mulsd %xmm1, %xmm0
movsd 0x25191(%rip), %xmm1    # 0x34360
addsd %xmm1, %xmm0
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
jmp 0xf2dd
movq -0x50(%rbp), %rdi
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
addq $0x10, %rdi
movl -0x14(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x30630
movzbl (%rax), %edi
callq 0xf320
movaps %xmm0, %xmm1
movsd -0x70(%rbp), %xmm0
movsd 0x2513e(%rip), %xmm2    # 0x34358
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
jmp 0xf2dd
movsd -0x20(%rbp), %xmm0
movsd -0x10(%rbp), %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
jmp 0xf2dd
movq -0x50(%rbp), %rdi
movsd 0x250ff(%rip), %xmm0    # 0x34358
mulsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
addq $0x10, %rdi
movl -0x14(%rbp), %eax
addl $0x3, %eax
movslq %eax, %rsi
callq 0x30630
movsd -0x78(%rbp), %xmm0
movzbl (%rax), %eax
cvtsi2sd %eax, %xmm2
movsd -0x10(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
jmp 0xf2dd
movsd -0x20(%rbp), %xmm0
movsd 0x250a6(%rip), %xmm1    # 0x34348
mulsd %xmm1, %xmm0
movsd 0x250a2(%rip), %xmm1    # 0x34350
addsd %xmm1, %xmm0
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
jmp 0xf2dd
movsd -0x20(%rbp), %xmm0
movsd -0x10(%rbp), %xmm1
movsd 0x25070(%rip), %xmm2    # 0x34340
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movq -0x50(%rbp), %rdi
addq $0x10, %rdi
movslq -0x14(%rbp), %rsi
callq 0x30630
movzbl (%rax), %eax
movl %eax, %ecx
leaq 0x258c6(%rip), %rax     # 0x34bc0
movl (%rax,%rcx,4), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xf10d
movsd -0x10(%rbp), %xmm0
addq $0x80, %rsp
popq %rbp
retq
nop