// File: /workspace/github_cpp_makefile_star2_O2/twekkel[P]mzpq/libzpaq.cpp
// Function: libzpaq::Compiler::Compiler(char const*, int*, libzpaq::ZPAQL&, libzpaq::ZPAQL&, libzpaq::Writer*)
Compiler::Compiler(const char* in_, int* args_, ZPAQL& hz_, ZPAQL& pz_,
                   Writer* out2_): in(in_), args(args_), hz(hz_), pz(pz_),
                   out2(out2_), if_stack(1000), do_stack(1000) {
  line=1;
  state=0;
  hz.clear();
  pz.clear();
  hz.header.resize(68000); 

  // Compile the COMP section of header
  rtoken("comp");
  hz.header[2]=rtoken(0, 255);  // hh
  hz.header[3]=rtoken(0, 255);  // hm
  hz.header[4]=rtoken(0, 255);  // ph
  hz.header[5]=rtoken(0, 255);  // pm
  const int n=hz.header[6]=rtoken(0, 255);  // n
  hz.cend=7;
  for (int i=0; i<n; ++i) {
    rtoken(i, i);
    CompType type=CompType(rtoken(compname));
    hz.header[hz.cend++]=type;
    int clen=libzpaq::compsize[type&255];
    if (clen<1 || clen>10) syntaxError("invalid component");
    for (int j=1; j<clen; ++j)
      hz.header[hz.cend++]=rtoken(0, 255);  // component arguments
  }
  hz.header[hz.cend++];  // end
  hz.hbegin=hz.hend=hz.cend+128;

  // Compile HCOMP
  rtoken("hcomp");
  int op=compile_comp(hz);

  // Compute header size
  int hsize=hz.cend-2+hz.hend-hz.hbegin;
  hz.header[0]=hsize&255;
  hz.header[1]=hsize>>8;

  // Compile POST 0 END
  if (op==POST) {
    rtoken(0, 0);
    rtoken("end");
  }

  // Compile PCOMP pcomp_cmd ; program... END
  else if (op==PCOMP) {
    pz.header.resize(68000);
    pz.header[4]=hz.header[4];  // ph
    pz.header[5]=hz.header[5];  // pm
    pz.cend=8;
    pz.hbegin=pz.hend=pz.cend+128;

    // get pcomp_cmd ending with ";" (case sensitive)
    next();
    while (*in && *in!=';') {
      if (out2)
        out2->put(*in);
      ++in;
    }
    if (*in) ++in;

    // Compile PCOMP
    op=compile_comp(pz);
    int len=pz.cend-2+pz.hend-pz.hbegin;  // insert header size
    assert(len>=0);
    pz.header[0]=len&255;
    pz.header[1]=len>>8;
    if (op!=END)
      syntaxError("expected END");
  }
  else if (op!=END)
    syntaxError("expected END or POST 0 END or PCOMP cmd ; ... END");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r15
movq %rsi, (%rdi)
movq %rdx, 0x8(%rdi)
movq %rcx, 0x10(%rdi)
movq %r8, 0x18(%rdi)
movq %r9, 0x20(%rdi)
addq $0x30, %rdi
movq %rdi, 0x10(%rsp)
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x1c9c2
leaq 0x50(%r15), %rdi
movq %rdi, 0x8(%rsp)
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x1c9c2
movq $0x1, 0x28(%r15)
movq 0x10(%r15), %rdi
callq 0x96e0
movq 0x18(%r15), %rdi
callq 0x96e0
movq 0x10(%r15), %rdi
addq $0x10, %rdi
movl $0x109a0, %esi          # imm = 0x109A0
xorl %edx, %edx
callq 0x1c46e
leaq 0x15517(%rip), %rsi     # 0x225e8
movq %r15, %rdi
callq 0xcb30
movq %r15, %rdi
xorl %esi, %esi
movl $0xff, %edx
callq 0xcb70
movq 0x10(%r15), %rcx
movq 0x10(%rcx), %rcx
movb %al, 0x2(%rcx)
movq %r15, %rdi
xorl %esi, %esi
movl $0xff, %edx
callq 0xcb70
movq 0x10(%r15), %rcx
movq 0x10(%rcx), %rcx
movb %al, 0x3(%rcx)
movq %r15, %rdi
xorl %esi, %esi
movl $0xff, %edx
callq 0xcb70
movq 0x10(%r15), %rcx
movq 0x10(%rcx), %rcx
movb %al, 0x4(%rcx)
movq %r15, %rdi
xorl %esi, %esi
movl $0xff, %edx
callq 0xcb70
movq 0x10(%r15), %rcx
movq 0x10(%rcx), %rcx
movb %al, 0x5(%rcx)
xorl %r12d, %r12d
movq %r15, %rdi
xorl %esi, %esi
movl $0xff, %edx
callq 0xcb70
movq 0x10(%r15), %rcx
movq 0x10(%rcx), %rcx
movb %al, 0x6(%rcx)
movzbl %al, %ebx
movq 0x10(%r15), %rax
movl $0x7, 0x28(%rax)
pushq $0x1
popq %r13
cmpl %ebx, %r12d
je 0xd20b
movq %r15, %rdi
movl %r12d, %esi
movl %r12d, %edx
callq 0xcb70
movq %r15, %rdi
leaq 0x1e06f(%rip), %rsi     # 0x2b200
callq 0xcae4
movq 0x10(%r15), %rcx
movslq 0x28(%rcx), %rdx
leal 0x1(%rdx), %esi
movl %esi, 0x28(%rcx)
movq 0x10(%rcx), %rcx
movb %al, (%rcx,%rdx)
movzbl %al, %eax
leaq 0x1193b(%rip), %rcx     # 0x1eaf0
movl (%rcx,%rax,4), %r14d
leal -0xb(%r14), %eax
cmpl $-0xa, %eax
jae 0xd1d3
movq %r15, %rdi
leaq 0x15409(%rip), %rsi     # 0x225d5
xorl %edx, %edx
callq 0xc98e
movl %r13d, %ebp
cmpl %r14d, %ebp
jge 0xd203
movq %r15, %rdi
xorl %esi, %esi
movl $0xff, %edx
callq 0xcb70
movq 0x10(%r15), %rcx
movslq 0x28(%rcx), %rdx
leal 0x1(%rdx), %esi
movl %esi, 0x28(%rcx)
movq 0x10(%rcx), %rcx
movb %al, (%rcx,%rdx)
incl %ebp
jmp 0xd1d6
incl %r12d
jmp 0xd170
movq 0x10(%r15), %rax
movl 0x28(%rax), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x28(%rax)
addl $0x81, %ecx
movl %ecx, 0x30(%rax)
movl %ecx, 0x2c(%rax)
leaq 0x153bc(%rip), %rsi     # 0x225e7
movq %r15, %rdi
callq 0xcb30
movq 0x10(%r15), %rsi
movq %r15, %rdi
callq 0xcc28
movq 0x10(%r15), %rdx
movl 0x28(%rdx), %ecx
addl 0x30(%rdx), %ecx
subl 0x2c(%rdx), %ecx
addl $-0x2, %ecx
movq 0x10(%rdx), %rdx
movb %cl, (%rdx)
movq 0x10(%r15), %rdx
movq 0x10(%rdx), %rdx
movb %ch, 0x1(%rdx)
cmpl $0x102, %eax            # imm = 0x102
je 0xd385
cmpl $0x101, %eax            # imm = 0x101
je 0xd29d
cmpl $0x100, %eax            # imm = 0x100
jne 0xd327
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xcb70
leaq 0x15242(%rip), %rsi     # 0x224d2
movq %r15, %rdi
callq 0xcb30
jmp 0xd385
movq 0x18(%r15), %rdi
addq $0x10, %rdi
movl $0x109a0, %esi          # imm = 0x109A0
xorl %edx, %edx
callq 0x1c46e
movq 0x10(%r15), %rax
movq 0x18(%r15), %rcx
movq 0x10(%rax), %rax
movb 0x4(%rax), %al
movq 0x10(%rcx), %rcx
movb %al, 0x4(%rcx)
movq 0x10(%r15), %rax
movq 0x18(%r15), %rcx
movq 0x10(%rax), %rax
movb 0x5(%rax), %al
movq 0x10(%rcx), %rcx
movb %al, 0x5(%rcx)
movq 0x18(%r15), %rax
movabsq $0x8800000008, %rcx     # imm = 0x8800000008
movq %rcx, 0x28(%rax)
movl $0x88, 0x30(%rax)
movq %r15, %rdi
callq 0xc89c
movq (%r15), %rax
movsbl (%rax), %esi
testl %esi, %esi
je 0xd340
cmpb $0x3b, %sil
je 0xd33a
movq 0x20(%r15), %rdi
testq %rdi, %rdi
je 0xd31f
movq (%rdi), %rax
callq *(%rax)
movq (%r15), %rax
incq %rax
movq %rax, (%r15)
jmp 0xd301
leaq 0x152cc(%rip), %rsi     # 0x225fa
movq %r15, %rdi
xorl %edx, %edx
callq 0xc98e
jmp 0xd385
incq %rax
movq %rax, (%r15)
movq 0x18(%r15), %rsi
movq %r15, %rdi
callq 0xcc28
movq 0x18(%r15), %rdx
movl 0x28(%rdx), %ecx
addl 0x30(%rdx), %ecx
subl 0x2c(%rdx), %ecx
addl $-0x2, %ecx
movq 0x10(%rdx), %rdx
movb %cl, (%rdx)
movq 0x18(%r15), %rdx
movq 0x10(%rdx), %rdx
movb %ch, 0x1(%rdx)
cmpl $0x102, %eax            # imm = 0x102
je 0xd385
leaq 0x15272(%rip), %rsi     # 0x225ed
movq %r15, %rdi
xorl %edx, %edx
callq 0xc98e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xd3ab
jmp 0xd3ab
movq %rax, %r15
jmp 0xd3b8
jmp 0xd3ab
jmp 0xd3ab
jmp 0xd3ab
jmp 0xd3ab
jmp 0xd3ab
jmp 0xd3ab
jmp 0xd3ab
movq %rax, %r15
movq 0x8(%rsp), %rdi
callq 0x1cdf0
movq 0x10(%rsp), %rdi
callq 0x1cdf0
movq %r15, %rdi
callq 0x4320