// File: /workspace/github_cpp_makefile_star2_O1/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 $0x18, %rsp
movq %rsi, 0x8(%rsp)
movq %rdi, %rbx
movq 0x808(%rdi), %rax
movq 0x10(%rax), %rax
movzbl 0x6(%rax), %r14d
testq %r14, %r14
je 0xc152
addq $0x7, %rax
leaq 0x810(%rbx), %rdi
movq 0x8(%rsp), %rcx
movl %ecx, %edx
shll $0xf, %edx
subl %ecx, %edx
movl %edx, 0x4(%rsp)
leaq 0x3fd77(%rip), %r8      # 0x4bac0
leaq 0x3fa58(%rip), %r11     # 0x4b7a8
movslq %ecx, %rcx
movq %rcx, 0x10(%rsp)
xorl %r9d, %r9d
movzbl (%rax), %ecx
addl $-0x2, %ecx
cmpl $0x7, %ecx
ja 0xc0ac
imulq $0x70, %r9, %rbp
addq %rdi, %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), %r10d
movl %r10d, %r15d
andl $0x3ff, %r15d           # imm = 0x3FF
movl %r10d, %r12d
shrl $0x11, %r12d
movl 0x4(%rsp), %r13d
subl %r12d, %r13d
movl %r15d, %r12d
imull 0x7c14(%rbx,%r12,4), %r13d
andl $0xfffffc00, %r13d      # imm = 0xFFFFFC00
cmpq (%rbp), %r15
adcl %r10d, %r13d
movl %r13d, (%rcx,%rdx,4)
jmp 0xc0ac
movslq 0x8(%rbx,%r9,4), %rcx
movzwl 0x9c14(%rbx,%rcx,2), %ecx
movl 0x4(%rsp), %edx
subl %ecx, %edx
movq 0x8(%rbp), %rcx
movq 0x28(%rbp), %r10
movzbl 0x2(%rax), %esi
movl 0x8(%rbx,%rsi,4), %esi
imull %edx, %esi
addl $0x1000, %esi           # imm = 0x1000
sarl $0xd, %esi
addl (%r10,%rcx,8), %esi
movl $0x7ffff, %r15d         # imm = 0x7FFFF
cmpl %r15d, %esi
cmovgel %r15d, %esi
movl $0xfff80001, %r12d      # imm = 0xFFF80001
cmpl %r12d, %esi
movl $0xfff80000, %r13d      # imm = 0xFFF80000
cmovll %r13d, %esi
movl %esi, (%r10,%rcx,8)
addl $0x10, %edx
sarl $0x5, %edx
addl 0x4(%r10,%rcx,8), %edx
cmpl %r15d, %edx
cmovgel %r15d, %edx
cmpl %r12d, %edx
cmovll %r13d, %edx
movl %edx, 0x4(%r10,%rcx,8)
movq 0x10(%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 0xc0ac
movl 0x4(%rbx), %ecx
andl $0xf, %ecx
movq 0x40(%rbp), %rdx
addq 0x20(%rbp), %rdx
movzbl (%rcx,%rdx), %r10d
movq 0x10(%rsp), %rsi
leaq (%rsi,%r10,4), %r10
movb 0x1ac14(%rbx,%r10), %r10b
movb %r10b, (%rcx,%rdx)
movq 0x28(%rbp), %rcx
movq 0x30(%rbp), %rdx
decq %rdx
andq 0x8(%rbp), %rdx
movl (%rcx,%rdx,4), %r10d
movl %r10d, %ebp
shrl $0x8, %ebp
movl 0x4(%rsp), %r15d
subl %ebp, %r15d
sarl $0x2, %r15d
addl %r10d, %r15d
jmp 0xbf04
movq 0x28(%rbp), %rcx
movq 0x30(%rbp), %rdx
decq %rdx
andq 0x8(%rbp), %rdx
movl (%rcx,%rdx,4), %esi
movl %esi, %r8d
andl $0x3ff, %r8d            # imm = 0x3FF
movl %esi, %r10d
shrl $0x11, %r10d
movl 0x4(%rsp), %r15d
subl %r10d, %r15d
movl %r8d, %r10d
imull 0x7c14(%rbx,%r10,4), %r15d
andl $0xfffffc00, %r15d      # imm = 0xFFFFFC00
cmpq (%rbp), %r8
leaq 0x3fbbf(%rip), %r8      # 0x4bac0
adcl %esi, %r15d
movl %r15d, (%rcx,%rdx,4)
jmp 0xc0ac
movq 0x8(%rsp), %rsi
cmpl %esi, 0x20(%rbp)
je 0xbf1f
movq $0x0, 0x10(%rbp)
movq 0x40(%rbp), %rcx
movq 0x48(%rbp), %rdx
decq %rdx
andq (%rbp), %rdx
movb (%rcx,%rdx), %r10b
addb %r10b, %r10b
addb %sil, %r10b
movb %r10b, (%rcx,%rdx)
movq 0x8(%rbp), %rcx
incq %rcx
movq %rcx, 0x8(%rbp)
cmpq $0x8, %rcx
jne 0xc0ac
movq $0x0, 0x8(%rbp)
movq (%rbp), %r13
movq 0x10(%rbp), %rdx
incq %r13
movq %r13, (%rbp)
movb 0x2(%rax), %cl
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
shll %cl, %r10d
notl %r10d
andl %r10d, %r13d
movq %r13, (%rbp)
testq %rdx, %rdx
je 0xc0c7
cmpq $0xff, %rdx
adcq $0x0, %rdx
movq %rdx, 0x10(%rbp)
movq 0x28(%rbp), %rcx
movl 0x30(%rbp), %edx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
addl %esi, %edx
andl 0x408(%rbx,%r9,4), %edx
movl %r13d, (%rcx,%rdx,4)
jmp 0xc01f
movslq 0x8(%rbx,%r9,4), %rcx
movzwl 0x9c14(%rbx,%rcx,2), %ecx
movl 0x4(%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), %r8d
movl 0x8(%rbx,%r8,4), %r8d
movzbl 0x3(%rax), %r10d
subl 0x8(%rbx,%r10,4), %r8d
movzwl (%rsi,%rdx,2), %r10d
imull %ecx, %r8d
addl $0x1000, %r8d           # imm = 0x1000
sarl $0xd, %r8d
addl %r10d, %r8d
testl %r8d, %r8d
movl $0x0, %ecx
cmovlel %ecx, %r8d
movl $0xffff, %ecx           # imm = 0xFFFF
cmpl %ecx, %r8d
cmovgel %ecx, %r8d
movw %r8w, (%rsi,%rdx,2)
leaq 0x3fa9a(%rip), %r8      # 0x4bac0
jmp 0xc0ac
movzbl 0x3(%rax), %ecx
testq %rcx, %rcx
je 0xc0ac
movslq 0x8(%rbx,%r9,4), %rdx
movzwl 0x9c14(%rbx,%rdx,2), %edx
movl 0x4(%rsp), %esi
subl %edx, %esi
movzbl 0x4(%rax), %edx
imull %esi, %edx
sarl $0x4, %edx
movq 0x8(%rbp), %r13
shlq $0x2, %r13
addq 0x28(%rbp), %r13
xorl %r12d, %r12d
movzbl 0x2(%rax), %esi
addq %r12, %rsi
movl 0x8(%rbx,%rsi,4), %r10d
imull %edx, %r10d
addl $0x1000, %r10d          # imm = 0x1000
sarl $0xd, %r10d
addl (%r13,%r12,4), %r10d
movl $0x7ffff, %esi          # imm = 0x7FFFF
cmpl %esi, %r10d
jl 0xc090
movl $0x7ffff, %r10d         # imm = 0x7FFFF
cmpl $0xfff80001, %r10d      # imm = 0xFFF80001
jge 0xc09f
movl $0xfff80000, %r10d      # imm = 0xFFF80000
movl %r10d, (%r13,%r12,4)
incq %r12
cmpq %r12, %rcx
jne 0xc060
movzbl (%rax), %ecx
movslq (%r8,%rcx,4), %rcx
addq %rcx, %rax
incq %r9
cmpq %r14, %r9
jne 0xbd5b
jmp 0xc152
movl 0x30(%rbp), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
addl %ecx, %edx
andl 0x408(%rbx,%r9,4), %edx
movq 0x28(%rbp), %r10
movq 0x48(%rbp), %rcx
movl (%r10,%rdx,4), %esi
movq %r13, %r10
subq %rsi, %r10
movq %r10, 0x18(%rbp)
decq %rcx
testq %r10, %rcx
je 0xbf96
movq 0x10(%rbp), %r8
cmpq $0xfe, %r8
ja 0xbf96
movq 0x40(%rbp), %r15
leaq 0x1(%r8), %r10
notq %r8
addq %r8, %rsi
addq %r13, %r8
movq %r8, %r12
andq %rcx, %r12
movb (%r15,%r12), %r12b
movq %rsi, %rdx
andq %rcx, %rdx
cmpb (%r15,%rdx), %r12b
jne 0xbf96
movq %r10, 0x10(%rbp)
incq %r10
decq %rsi
decq %r8
cmpq $0x100, %r10            # imm = 0x100
jne 0xc11d
jmp 0xbf96
movl (%rbx), %eax
movq 0x8(%rsp), %rdx
leal (%rdx,%rax,2), %eax
movl %eax, (%rbx)
cmpl $0xff, %eax
jle 0xc1ba
movq 0x808(%rbx), %rdi
addl $0xffffff00, %eax       # imm = 0xFFFFFF00
movl %eax, %esi
callq 0xc1f6
movabsq $0x100000001, %rax      # imm = 0x100000001
movq %rax, (%rbx)
testq %r14, %r14
je 0xc1e6
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 0xc1a0
jmp 0xc1e6
andl $-0x10, %eax
movl 0x4(%rbx), %ecx
cmpl $0x10, %eax
jne 0xc1d4
andl $0xf, %ecx
shll $0x5, %ecx
shll $0x4, %edx
orl %ecx, %edx
incl %edx
jmp 0xc1e3
movl %ecx, %eax
andl $0x1f0, %eax            # imm = 0x1F0
leal (%rdx,%rcx,2), %edx
andl $0xf, %edx
orl %eax, %edx
movl %edx, 0x4(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop