// File: /workspace/github_cpp_makefile_star2_O3/twekkel[P]mzpq/libzpaq.cpp
// Function: libzpaq::Predictor::update0(int)
void Predictor::update0(int y) {
  assert(initTables);
  assert(y==0 || y==1);
  assert(c8>=1 && c8<=255);
  assert(hmap4>=1 && hmap4<=511);

  // Update components
  const U8* cp=&z.header[7];
  int n=z.header[6];
  assert(n>=1 && n<=255);
  assert(cp[-1]==n);
  for (int i=0; i<n; ++i) {
    Component& cr=comp[i];
    switch(cp[0]) {
      case CONS:  // c
        break;
      case CM:  // sizebits limit
        train(cr, y);
        break;
      case ICM: { // sizebits: cxt=ht[b]=bh, ht[c][0..15]=bh row, cxt=bh
        cr.ht[cr.c+(hmap4&15)]=st.next(cr.ht[cr.c+(hmap4&15)], y);
        U32& pn=cr.cm(cr.cxt);
        pn+=int(y*32767-(pn>>8))>>2;
      }
        break;
      case MATCH: // sizebits bufbits:
                  //   a=len, b=offset, c=bit, cm=index, cxt=bitpos
                  //   ht=buf, limit=pos
      {
        assert(cr.a<=255);
        assert(cr.c==0 || cr.c==1);
        assert(cr.cxt<8);
        assert(cr.cm.size()==(size_t(1)<<cp[1]));
        assert(cr.ht.size()==(size_t(1)<<cp[2]));
        assert(cr.limit<cr.ht.size());
        if (int(cr.c)!=y) cr.a=0;  // mismatch?
        cr.ht(cr.limit)+=cr.ht(cr.limit)+y;
        if (++cr.cxt==8) {
          cr.cxt=0;
          ++cr.limit;
          cr.limit&=(1<<cp[2])-1;
          if (cr.a==0) {  // look for a match
            cr.b=cr.limit-cr.cm(h[i]);
            if (cr.b&(cr.ht.size()-1))
              while (cr.a<255
                     && cr.ht(cr.limit-cr.a-1)==cr.ht(cr.limit-cr.a-cr.b-1))
                ++cr.a;
          }
          else cr.a+=cr.a<255;
          cr.cm(h[i])=cr.limit;
        }
      }
        break;
      case AVG:  // j k wt
        break;
      case MIX2: { // sizebits j k rate mask
                   // cm=wt[size], cxt=input
        assert(cr.a16.size()==cr.c);
        assert(cr.cxt<cr.a16.size());
        int err=(y*32767-squash(p[i]))*cp[4]>>5;
        int w=cr.a16[cr.cxt];
        w+=(err*(p[cp[2]]-p[cp[3]])+(1<<12))>>13;
        if (w<0) w=0;
        if (w>65535) w=65535;
        cr.a16[cr.cxt]=w;
      }
        break;
      case MIX: {   // sizebits j m rate mask
                    // cm=wt[size][m], cxt=input
        int m=cp[3];
        assert(m>0 && m<=i);
        assert(cr.cm.size()==m*cr.c);
        assert(cr.cxt+m<=cr.cm.size());
        int err=(y*32767-squash(p[i]))*cp[4]>>4;
        int* wt=(int*)&cr.cm[cr.cxt];
        for (int j=0; j<m; ++j)
          wt[j]=clamp512k(wt[j]+((err*p[cp[2]+j]+(1<<12))>>13));
      }
        break;
      case ISSE: { // sizebits j  -- c=hi, cxt=bh
        assert(cr.cxt==cr.ht[cr.c+(hmap4&15)]);
        int err=y*32767-squash(p[i]);
        int *wt=(int*)&cr.cm[cr.cxt*2];
        wt[0]=clamp512k(wt[0]+((err*p[cp[2]]+(1<<12))>>13));
        wt[1]=clamp512k(wt[1]+((err+16)>>5));
        cr.ht[cr.c+(hmap4&15)]=st.next(cr.cxt, y);
      }
        break;
      case SSE:  // sizebits j start limit
        train(cr, y);
        break;
      default:
        assert(0);
    }
    cp+=compsize[cp[0]];
    assert(cp>=&z.header[7] && cp<&z.header[z.cend] 
           && cp<&z.header[z.header.isize()-8]);
  }
  assert(cp[0]==NONE);

  // Save bit y in c8, hmap4
  c8+=c8+y;
  if (c8>=256) {
    z.run(c8-256);
    hmap4=1;
    c8=1;
    for (int i=0; i<n; ++i) h[i]=z.H(i);
  }
  else if (c8>=16 && c8<32)
    hmap4=(hmap4&0xf)<<5|y<<4|1;
  else
    hmap4=(hmap4&0x1f0)|(((hmap4&0xf)*2+y)&0xf);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %r13d
movq %rdi, %rbx
movq 0x808(%rdi), %rax
movq 0x10(%rax), %rax
movzbl 0x6(%rax), %r14d
testq %r14, %r14
je 0xc63a
addq $0x7, %rax
leaq 0x810(%rbx), %r8
movl %r13d, %ecx
shll $0xf, %ecx
subl %r13d, %ecx
movl %ecx, (%rsp)
leaq 0x2a073(%rip), %r10     # 0x36290
leaq 0x29d54(%rip), %r11     # 0x35f78
movslq %r13d, %rcx
movq %rcx, 0x18(%rsp)
xorl %r9d, %r9d
movq %r8, 0x8(%rsp)
movq %r13, 0x20(%rsp)
movzbl (%rax), %ecx
addl $-0x2, %ecx
cmpl $0x7, %ecx
ja 0xc624
imulq $0x70, %r9, %rbp
addq %r8, %rbp
movslq (%r11,%rcx,4), %rcx
addq %r11, %rcx
jmpq *%rcx
movq 0x28(%rbp), %rcx
movq 0x30(%rbp), %rdx
decq %rdx
andq 0x8(%rbp), %rdx
movl (%rcx,%rdx,4), %esi
movl %esi, %r10d
andl $0x3ff, %r10d           # imm = 0x3FF
movl %esi, %r15d
shrl $0x11, %r15d
movl (%rsp), %r12d
subl %r15d, %r12d
movl %r10d, %r15d
imull 0x7c14(%rbx,%r15,4), %r12d
andl $0xfffffc00, %r12d      # imm = 0xFFFFFC00
cmpq (%rbp), %r10
leaq 0x29ff0(%rip), %r10     # 0x36290
adcl %esi, %r12d
movl %r12d, (%rcx,%rdx,4)
jmp 0xc624
movslq 0x8(%rbx,%r9,4), %rcx
movzwl 0x9c14(%rbx,%rcx,2), %ecx
movl (%rsp), %edx
subl %ecx, %edx
movq 0x8(%rbp), %rcx
movq 0x28(%rbp), %rsi
movzbl 0x2(%rax), %edi
movl 0x8(%rbx,%rdi,4), %edi
imull %edx, %edi
addl $0x1000, %edi           # imm = 0x1000
sarl $0xd, %edi
addl (%rsi,%rcx,8), %edi
movl $0x7ffff, %r15d         # imm = 0x7FFFF
cmpl %r15d, %edi
cmovgel %r15d, %edi
movl $0xfff80001, %r12d      # imm = 0xFFF80001
cmpl %r12d, %edi
movl $0xfff80000, %r12d      # imm = 0xFFF80000
cmovll %r12d, %edi
movl %edi, (%rsi,%rcx,8)
addl $0x10, %edx
sarl $0x5, %edx
addl 0x4(%rsi,%rcx,8), %edx
cmpl %r15d, %edx
cmovgel %r15d, %edx
movl $0xfff80001, %edi       # imm = 0xFFF80001
cmpl %edi, %edx
cmovll %r12d, %edx
movl %edx, 0x4(%rsi,%rcx,8)
movq 0x18(%rsp), %rdx
leal (%rdx,%rcx,4), %ecx
movslq %ecx, %rcx
movb 0x1ac14(%rbx,%rcx), %cl
movl 0x4(%rbx), %edx
andl $0xf, %edx
movq 0x40(%rbp), %rsi
addq 0x20(%rbp), %rsi
movb %cl, (%rdx,%rsi)
jmp 0xc624
movl 0x4(%rbx), %ecx
andl $0xf, %ecx
movq 0x40(%rbp), %rdx
addq 0x20(%rbp), %rdx
movzbl (%rcx,%rdx), %esi
movq 0x18(%rsp), %rdi
leaq (%rdi,%rsi,4), %rsi
movb 0x1ac14(%rbx,%rsi), %sil
movb %sil, (%rcx,%rdx)
movq 0x28(%rbp), %rcx
movq 0x30(%rbp), %rdx
decq %rdx
andq 0x8(%rbp), %rdx
movl (%rcx,%rdx,4), %esi
movl %esi, %r10d
shrl $0x8, %r10d
movl (%rsp), %ebp
subl %r10d, %ebp
leaq 0x29efb(%rip), %r10     # 0x36290
sarl $0x2, %ebp
addl %esi, %ebp
movl %ebp, (%rcx,%rdx,4)
jmp 0xc624
movq 0x28(%rbp), %rcx
movq 0x30(%rbp), %rdx
decq %rdx
andq 0x8(%rbp), %rdx
movl (%rcx,%rdx,4), %esi
movl %esi, %edi
andl $0x3ff, %edi            # imm = 0x3FF
movl %esi, %r8d
shrl $0x11, %r8d
movl (%rsp), %r10d
subl %r8d, %r10d
movl %edi, %r8d
imull 0x7c14(%rbx,%r8,4), %r10d
movq 0x8(%rsp), %r8
andl $0xfffffc00, %r10d      # imm = 0xFFFFFC00
cmpq (%rbp), %rdi
adcl %esi, %r10d
movl %r10d, (%rcx,%rdx,4)
leaq 0x29e9c(%rip), %r10     # 0x36290
jmp 0xc624
cmpl %r13d, 0x20(%rbp)
je 0xc407
movq $0x0, 0x10(%rbp)
movq 0x40(%rbp), %rcx
movq 0x48(%rbp), %rdx
decq %rdx
andq (%rbp), %rdx
movb (%rcx,%rdx), %sil
addb %sil, %sil
addb %r13b, %sil
movb %sil, (%rcx,%rdx)
movq 0x8(%rbp), %rcx
incq %rcx
movq %rcx, 0x8(%rbp)
cmpq $0x8, %rcx
jne 0xc624
movq $0x0, 0x8(%rbp)
movq (%rbp), %r13
movq 0x10(%rbp), %rdx
incq %r13
movq %r13, (%rbp)
movb 0x2(%rax), %cl
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
shll %cl, %esi
notl %esi
andl %esi, %r13d
movq %r13, (%rbp)
testq %rdx, %rdx
je 0xc57b
cmpq $0xff, %rdx
adcq $0x0, %rdx
movq %rdx, 0x10(%rbp)
movl 0x408(%rbx,%r9,4), %esi
movq 0x28(%rbp), %rdx
movq 0x30(%rbp), %r12
jmp 0xc610
movslq 0x8(%rbx,%r9,4), %rcx
movzwl 0x9c14(%rbx,%rcx,2), %ecx
movl (%rsp), %edx
subl %ecx, %edx
movzbl 0x4(%rax), %ecx
imull %edx, %ecx
sarl $0x5, %ecx
movq 0x8(%rbp), %rdx
movq 0x58(%rbp), %rsi
movzbl 0x2(%rax), %edi
movl 0x8(%rbx,%rdi,4), %edi
movzbl 0x3(%rax), %r8d
subl 0x8(%rbx,%r8,4), %edi
movzwl (%rsi,%rdx,2), %r8d
imull %ecx, %edi
addl $0x1000, %edi           # imm = 0x1000
sarl $0xd, %edi
addl %r8d, %edi
movq 0x8(%rsp), %r8
testl %edi, %edi
movl $0x0, %ecx
cmovlel %ecx, %edi
movl $0xffff, %ecx           # imm = 0xFFFF
cmpl %ecx, %edi
cmovgel %ecx, %edi
movw %di, (%rsi,%rdx,2)
jmp 0xc624
movzbl 0x3(%rax), %ecx
testq %rcx, %rcx
je 0xc624
movslq 0x8(%rbx,%r9,4), %rdx
movzwl 0x9c14(%rbx,%rdx,2), %edx
movl (%rsp), %esi
subl %edx, %esi
movzbl 0x4(%rax), %edx
imull %esi, %edx
sarl $0x4, %edx
movq 0x8(%rbp), %r12
shlq $0x2, %r12
addq 0x28(%rbp), %r12
xorl %r15d, %r15d
movzbl 0x2(%rax), %esi
addq %r15, %rsi
movl 0x8(%rbx,%rsi,4), %esi
imull %edx, %esi
addl $0x1000, %esi           # imm = 0x1000
sarl $0xd, %esi
addl (%r12,%r15,4), %esi
movl $0x7ffff, %edi          # imm = 0x7FFFF
cmpl %edi, %esi
jl 0xc55d
movl $0x7ffff, %esi          # imm = 0x7FFFF
cmpl $0xfff80001, %esi       # imm = 0xFFF80001
jge 0xc56a
movl $0xfff80000, %esi       # imm = 0xFFF80000
movl %esi, (%r12,%r15,4)
incq %r15
cmpq %r15, %rcx
jne 0xc534
jmp 0xc624
movl 0x408(%rbx,%r9,4), %esi
movq 0x28(%rbp), %rdx
movq 0x30(%rbp), %r12
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
addl %r12d, %ecx
andl %esi, %ecx
movl (%rdx,%rcx,4), %edi
movq %r13, %rcx
subq %rdi, %rcx
movq %rcx, 0x18(%rbp)
movq 0x48(%rbp), %r10
decq %r10
testq %rcx, %r10
je 0xc609
movl %esi, 0x4(%rsp)
movq %rdx, 0x10(%rsp)
movq 0x40(%rbp), %rcx
decq %rdi
leaq -0x1(%r13), %r8
movl $0x1, %esi
movq %r8, %rdx
andq %r10, %rdx
movb (%rcx,%rdx), %dl
movq %rdi, %r15
andq %r10, %r15
cmpb (%rcx,%r15), %dl
jne 0xc5f2
movq %rsi, 0x10(%rbp)
incq %rsi
decq %rdi
decq %r8
cmpq $0x100, %rsi            # imm = 0x100
jne 0xc5c7
movq 0x8(%rsp), %r8
leaq 0x29c92(%rip), %r10     # 0x36290
movq 0x10(%rsp), %rdx
movl 0x4(%rsp), %esi
jmp 0xc610
leaq 0x29c80(%rip), %r10     # 0x36290
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
addl %ecx, %r12d
andl %esi, %r12d
movl %r13d, (%rdx,%r12,4)
movq 0x20(%rsp), %r13
movzbl (%rax), %ecx
movslq (%r10,%rcx,4), %rcx
addq %rcx, %rax
incq %r9
cmpq %r14, %r9
jne 0xc239
movl (%rbx), %eax
leal (%r13,%rax,2), %eax
movl %eax, (%rbx)
cmpl $0xff, %eax
jle 0xc69f
movq 0x808(%rbx), %rdi
addl $0xffffff00, %eax       # imm = 0xFFFFFF00
movl %eax, %esi
callq 0xc6e2
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, (%rbx)
testq %r14, %r14
je 0xc6d3
movq 0x808(%rbx), %rdx
movq 0x50(%rdx), %rax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
addq 0x58(%rdx), %rcx
xorl %edx, %edx
movq %rcx, %rsi
andq %rdx, %rsi
movl (%rax,%rsi,4), %esi
movl %esi, 0x408(%rbx,%rdx,4)
incq %rdx
cmpq %rdx, %r14
jne 0xc685
jmp 0xc6d3
andl $-0x10, %eax
movl 0x4(%rbx), %ecx
cmpl $0x10, %eax
jne 0xc6bc
andl $0xf, %ecx
shll $0x5, %ecx
shll $0x4, %r13d
orl %ecx, %r13d
incl %r13d
jmp 0xc6cf
movl %ecx, %eax
andl $0x1f0, %eax            # imm = 0x1F0
leal (%r13,%rcx,2), %r13d
andl $0xf, %r13d
orl %eax, %r13d
movl %r13d, 0x4(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq