// File: twekkel[P]mzpq/libzpaq.cpp
// Function: libzpaq::PostProcessor::write(int)
int PostProcessor::write(int c) {
  assert(c>=-1 && c<=255);
  switch (state) {
    case 0:  // initial state
      if (c<0) error("Unexpected EOS");
      state=c+1;  // 1=PASS, 2=PROG
      if (state>2) error("unknown post processing type");
      if (state==1) z.clear();
      break;
    case 1:  // PASS
      z.outc(c);
      break;
    case 2: // PROG
      if (c<0) error("Unexpected EOS");
      hsize=c;  // low byte of size
      state=3;
      break;
    case 3:  // PROG psize[0]
      if (c<0) error("Unexpected EOS");
      hsize+=c*256;  // high byte of psize
      if (hsize<1) error("Empty PCOMP");
      z.header.resize(hsize+300);
      z.cend=8;
      z.hbegin=z.hend=z.cend+128;
      z.header[4]=ph;
      z.header[5]=pm;
      state=4;
      break;
    case 4:  // PROG psize[0..1] pcomp[0...]
      if (c<0) error("Unexpected EOS");
      assert(z.hend<z.header.isize());
      z.header[z.hend++]=c;  // one byte of pcomp
      if (z.hend-z.hbegin==hsize) {  // last byte of pcomp?
        hsize=z.cend-2+z.hend-z.hbegin;
        z.header[0]=hsize&255;  // header size with empty COMP
        z.header[1]=hsize>>8;
        z.initp();
        state=5;
      }
      break;
    case 5:  // PROG ... data
      z.run(c);
      if (c<0) z.flush();
      break;
  }
  return state;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movl (%rax), %eax
movq %rax, -0x18(%rbp)
subq $0x5, %rax
ja 0x13e23
movq -0x18(%rbp), %rax
leaq 0x20c1a(%rip), %rcx     # 0x3480c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, -0xc(%rbp)
jge 0x13c0d
leaq 0x24510(%rip), %rdi     # 0x38118
callq 0x5720
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
cmpl $0x2, (%rax)
jle 0x13c2a
leaq 0x24502(%rip), %rdi     # 0x38127
callq 0x5720
movq -0x20(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x13c40
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
callq 0xeb50
jmp 0x13e23
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
movl -0xc(%rbp), %esi
callq 0x309a0
jmp 0x13e23
cmpl $0x0, -0xc(%rbp)
jge 0x13c6c
leaq 0x244b1(%rip), %rdi     # 0x38118
callq 0x5720
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
movl %ecx, 0x4(%rax)
movl $0x3, (%rax)
jmp 0x13e23
cmpl $0x0, -0xc(%rbp)
jge 0x13c93
leaq 0x2448a(%rip), %rdi     # 0x38118
callq 0x5720
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
shll $0x8, %ecx
addl 0x4(%rax), %ecx
movl %ecx, 0x4(%rax)
cmpl $0x1, 0x4(%rax)
jge 0x13cb5
leaq 0x24494(%rip), %rdi     # 0x38144
callq 0x5720
movq -0x20(%rbp), %rax
movq %rax, %rdi
addq $0x10, %rdi
addq $0x10, %rdi
movl 0x4(%rax), %eax
addl $0x12c, %eax            # imm = 0x12C
movslq %eax, %rsi
xorl %edx, %edx
callq 0x30370
movq -0x20(%rbp), %rdi
movl $0x8, 0x38(%rdi)
movl 0x38(%rdi), %eax
addl $0x80, %eax
movl %eax, 0x40(%rdi)
movl %eax, 0x3c(%rdi)
movl 0x8(%rdi), %eax
movb %al, -0x22(%rbp)
addq $0x10, %rdi
addq $0x10, %rdi
movl $0x4, %esi
callq 0x30630
movb -0x22(%rbp), %cl
movq -0x20(%rbp), %rdi
movb %cl, (%rax)
movl 0xc(%rdi), %eax
movb %al, -0x21(%rbp)
addq $0x10, %rdi
addq $0x10, %rdi
movl $0x5, %esi
callq 0x30630
movb -0x21(%rbp), %dl
movq %rax, %rcx
movq -0x20(%rbp), %rax
movb %dl, (%rcx)
movl $0x4, (%rax)
jmp 0x13e23
cmpl $0x0, -0xc(%rbp)
jge 0x13d51
leaq 0x243cc(%rip), %rdi     # 0x38118
callq 0x5720
movq -0x20(%rbp), %rcx
movl -0xc(%rbp), %eax
movb %al, -0x23(%rbp)
movq %rcx, %rdi
addq $0x10, %rdi
addq $0x10, %rdi
movl 0x40(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x40(%rcx)
movslq %eax, %rsi
callq 0x30630
movb -0x23(%rbp), %dl
movq -0x20(%rbp), %rcx
movb %dl, (%rax)
movl 0x40(%rcx), %eax
subl 0x3c(%rcx), %eax
cmpl 0x4(%rcx), %eax
jne 0x13dfc
movq -0x20(%rbp), %rdi
movl 0x38(%rdi), %eax
subl $0x2, %eax
addl 0x40(%rdi), %eax
subl 0x3c(%rdi), %eax
movl %eax, 0x4(%rdi)
movl 0x4(%rdi), %eax
andl $0xff, %eax
movb %al, -0x25(%rbp)
addq $0x10, %rdi
addq $0x10, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x30630
movb -0x25(%rbp), %cl
movq -0x20(%rbp), %rdi
movb %cl, (%rax)
movl 0x4(%rdi), %eax
sarl $0x8, %eax
movb %al, -0x24(%rbp)
addq $0x10, %rdi
addq $0x10, %rdi
movl $0x1, %esi
callq 0x30630
movb -0x24(%rbp), %cl
movq -0x20(%rbp), %rdi
movb %cl, (%rax)
addq $0x10, %rdi
callq 0xef20
movq -0x20(%rbp), %rax
movl $0x5, (%rax)
jmp 0x13e23
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
movl -0xc(%rbp), %esi
callq 0x132c0
cmpl $0x0, -0xc(%rbp)
jge 0x13e21
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
callq 0xef70
jmp 0x13e23
movq -0x20(%rbp), %rax
movl (%rax), %eax
addq $0x30, %rsp
popq %rbp
retq
nop