// File: /workspace/github_cpp_makefile_star2_O3/twekkel[P]mzpq/libzpaq.cpp
// Function: libzpaq::Compiler::compile_comp(libzpaq::ZPAQL&)
int Compiler::compile_comp(ZPAQL& z) {
  int op=0;
  const int comp_begin=z.hend;
  while (true) {
    op=rtoken(opcodelist);
    if (op==POST || op==PCOMP || op==END) break;
    int operand=-1; // 0...255 if 2 bytes
    int operand2=-1;  // 0...255 if 3 bytes
    if (op==IF) {
      op=JF;
      operand=0; // set later
      if_stack.push(z.hend+1); // save jump target location
    }
    else if (op==IFNOT) {
      op=JT;
      operand=0;
      if_stack.push(z.hend+1); // save jump target location
    }
    else if (op==IFL || op==IFNOTL) {  // long if
      if (op==IFL) z.header[z.hend++]=(JT);
      if (op==IFNOTL) z.header[z.hend++]=(JF);
      z.header[z.hend++]=(3);
      op=LJ;
      operand=operand2=0;
      if_stack.push(z.hend+1);
    }
    else if (op==ELSE || op==ELSEL) {
      if (op==ELSE) op=JMP, operand=0;
      if (op==ELSEL) op=LJ, operand=operand2=0;
      int a=if_stack.pop();  // conditional jump target location
      assert(a>comp_begin && a<int(z.hend));
      if (z.header[a-1]!=LJ) {  // IF, IFNOT
        assert(z.header[a-1]==JT || z.header[a-1]==JF || z.header[a-1]==JMP);
        int j=z.hend-a+1+(op==LJ); // offset at IF
        assert(j>=0);
        if (j>127) syntaxError("IF too big, try IFL, IFNOTL");
        z.header[a]=j;
      }
      else {  // IFL, IFNOTL
        int j=z.hend-comp_begin+2+(op==LJ);
        assert(j>=0);
        z.header[a]=j&255;
        z.header[a+1]=(j>>8)&255;
      }
      if_stack.push(z.hend+1);  // save JMP target location
    }
    else if (op==ENDIF) {
      int a=if_stack.pop();  // jump target address
      assert(a>comp_begin && a<int(z.hend));
      int j=z.hend-a-1;  // jump offset
      assert(j>=0);
      if (z.header[a-1]!=LJ) {
        assert(z.header[a-1]==JT || z.header[a-1]==JF || z.header[a-1]==JMP);
        if (j>127) syntaxError("IF too big, try IFL, IFNOTL, ELSEL\n");
        z.header[a]=j;
      }
      else {
        assert(a+1<int(z.hend));
        j=z.hend-comp_begin;
        z.header[a]=j&255;
        z.header[a+1]=(j>>8)&255;
      }
    }
    else if (op==DO) {
      do_stack.push(z.hend);
    }
    else if (op==WHILE || op==UNTIL || op==FOREVER) {
      int a=do_stack.pop();
      assert(a>=comp_begin && a<int(z.hend));
      int j=a-z.hend-2;
      assert(j<=-2);
      if (j>=-127) {  // backward short jump
        if (op==WHILE) op=JT;
        if (op==UNTIL) op=JF;
        if (op==FOREVER) op=JMP;
        operand=j&255;
      }
      else {  // backward long jump
        j=a-comp_begin;
        assert(j>=0 && j<int(z.hend)-comp_begin);
        if (op==WHILE) {
          z.header[z.hend++]=(JF);
          z.header[z.hend++]=(3);
        }
        if (op==UNTIL) {
          z.header[z.hend++]=(JT);
          z.header[z.hend++]=(3);
        }
        op=LJ;
        operand=j&255;
        operand2=j>>8;
      }
    }
    else if ((op&7)==7) { // 2 byte operand, read N
      if (op==LJ) {
        operand=rtoken(0, 65535);
        operand2=operand>>8;
        operand&=255;
      }
      else if (op==JT || op==JF || op==JMP) {
        operand=rtoken(-128, 127);
        operand&=255;
      }
      else
        operand=rtoken(0, 255);
    }
    if (op>=0 && op<=255)
      z.header[z.hend++]=(op);
    if (operand>=0)
      z.header[z.hend++]=(operand);
    if (operand2>=0)
      z.header[z.hend++]=(operand2);
    if (z.hend>=z.header.isize()-130 || z.hend-z.hbegin+z.cend-2>65535)
      syntaxError("program too big");
  }
  z.header[z.hend++]=(0); // END
  return op;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl 0x30(%rsi), %eax
movl %eax, 0x4(%rsp)
leaq 0x340c7(%rip), %r15     # 0x419f0
leaq 0x2ec27(%rip), %r12     # 0x3c557
movq %r14, %rdi
movq %r15, %rsi
callq 0xd7be
cmpl $0x103, %eax            # imm = 0x103
je 0xd9d9
movl %eax, %ebp
cmpl $0x104, %eax            # imm = 0x104
je 0xda13
leal -0x100(%rbp), %eax
cmpl $0x3, %eax
jb 0xddfb
leal -0x10b(%rbp), %eax
cmpl $0x1, %eax
ja 0xdac1
cmpl $0x10b, %ebp            # imm = 0x10B
setne %al
movslq 0x30(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x30(%rbx)
movq 0x10(%rbx), %rdx
shlb $0x3, %al
orb $0x27, %al
movb %al, (%rdx,%rcx)
movslq 0x30(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x30(%rbx)
movq 0x10(%rbx), %rcx
movb $0x3, (%rcx,%rax)
movl 0x30(%rbx), %ebp
movq 0x48(%r14), %rax
cmpq 0x38(%r14), %rax
jb 0xd9bb
movq %r12, %rdi
callq 0x455c
movq 0x48(%r14), %rax
incl %ebp
leaq 0x1(%rax), %rcx
movq %rcx, 0x48(%r14)
movq 0x30(%r14), %rcx
movw %bp, (%rcx,%rax,2)
xorl %eax, %eax
movl $0xff, %ebp
xorl %r13d, %r13d
jmp 0xda4b
movl 0x30(%rbx), %ebp
movq 0x48(%r14), %rax
cmpq 0x38(%r14), %rax
jb 0xd9f2
movq %r12, %rdi
callq 0x455c
movq 0x48(%r14), %rax
incl %ebp
leaq 0x1(%rax), %rcx
movq %rcx, 0x48(%r14)
movq 0x30(%r14), %rcx
movw %bp, (%rcx,%rax,2)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %eax, %eax
movl $0x2f, %ebp
jmp 0xda4b
movl 0x30(%rbx), %ebp
movq 0x48(%r14), %rax
cmpq 0x38(%r14), %rax
jb 0xda2c
movq %r12, %rdi
callq 0x455c
movq 0x48(%r14), %rax
incl %ebp
leaq 0x1(%rax), %rcx
movq %rcx, 0x48(%r14)
movq 0x30(%r14), %rcx
movw %bp, (%rcx,%rax,2)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %eax, %eax
movl $0x27, %ebp
movslq 0x30(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x30(%rbx)
movq 0x10(%rbx), %rdx
movb %bpl, (%rdx,%rcx)
testl %eax, %eax
js 0xda72
movslq 0x30(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x30(%rbx)
movq 0x10(%rbx), %rdx
movb %al, (%rdx,%rcx)
testl %r13d, %r13d
js 0xda89
movslq 0x30(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x30(%rbx)
movq 0x10(%rbx), %rcx
movb %r13b, (%rcx,%rax)
movl 0x30(%rbx), %eax
movl 0x18(%rbx), %ecx
movl $0xffffff7e, %edx       # imm = 0xFFFFFF7E
addl %edx, %ecx
cmpl %ecx, %eax
jge 0xdaab
subl 0x2c(%rbx), %eax
addl 0x28(%rbx), %eax
cmpl $0x10002, %eax          # imm = 0x10002
jl 0xd930
movq %r14, %rdi
leaq 0x2c2b0(%rip), %rsi     # 0x39d65
xorl %edx, %edx
callq 0xd61e
jmp 0xd930
leal -0x105(%rbp), %eax
cmpl $0x8, %eax
ja 0xdc17
leaq 0x284e9(%rip), %rcx     # 0x35fc0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x3f, %ebp
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %r12d, %r12d
jmp 0xdb9a
movzwl 0x30(%rbx), %ebp
movq 0x68(%r14), %rax
cmpq 0x58(%r14), %rax
jb 0xdb0d
movq %r12, %rdi
callq 0x455c
movq 0x68(%r14), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x68(%r14)
movq 0x50(%r14), %rcx
movw %bp, (%rcx,%rax,2)
jmp 0xda89
movq 0x48(%r14), %rax
testq %rax, %rax
jne 0xdb3b
leaq 0x2ea3e(%rip), %rdi     # 0x3c570
callq 0x455c
movq 0x48(%r14), %rax
leaq -0x1(%rax), %rcx
movq %rcx, 0x48(%r14)
movq 0x30(%r14), %rcx
movzwl -0x2(%rcx,%rax,2), %ebp
movl 0x30(%rbx), %edx
movq 0x10(%rbx), %rax
cmpb $-0x1, -0x1(%rax,%rbp)
je 0xdd46
movl %ebp, %ecx
notl %ecx
addl %ecx, %edx
cmpl $0x80, %edx
jl 0xdb87
movq %r14, %rdi
leaq 0x2c1cb(%rip), %rsi     # 0x39d41
movl %edx, %r13d
xorl %edx, %edx
callq 0xd61e
movl %r13d, %edx
movq 0x10(%rbx), %rax
movb %dl, (%rax,%rbp)
jmp 0xda89
movl $0xff, %ebp
xorl %r13d, %r13d
movb $0x1, %r12b
movq 0x48(%r14), %rax
testq %rax, %rax
jne 0xdbb3
leaq 0x2e9c6(%rip), %rdi     # 0x3c570
callq 0x455c
movq 0x48(%r14), %rax
leaq -0x1(%rax), %rcx
movq %rcx, 0x48(%r14)
movq 0x30(%r14), %rcx
movzwl -0x2(%rcx,%rax,2), %esi
movq 0x10(%rbx), %rax
cmpb $-0x1, -0x1(%rax,%rsi)
movzbl %r12b, %ecx
je 0xdc9e
movl 0x30(%rbx), %edx
subl %esi, %ecx
leal (%rcx,%rdx), %r12d
incl %r12d
cmpl $0x80, %r12d
jl 0xdc0e
movq %r14, %rdi
movq %rsi, %r15
leaq 0x2c12c(%rip), %rsi     # 0x39d25
xorl %edx, %edx
callq 0xd61e
movq %r15, %rsi
leaq 0x33de6(%rip), %r15     # 0x419f0
movq 0x10(%rbx), %rax
movb %r12b, (%rax,%rsi)
jmp 0xdcb5
leal -0x108(%rbp), %eax
cmpl $0x2, %eax
ja 0xdcf5
movq 0x68(%r14), %rax
testq %rax, %rax
jne 0xdc3f
leaq 0x2e93a(%rip), %rdi     # 0x3c570
callq 0x455c
movq 0x68(%r14), %rax
leaq -0x1(%rax), %rcx
movq %rcx, 0x68(%r14)
movq 0x50(%r14), %rcx
movzwl -0x2(%rcx,%rax,2), %eax
movslq 0x30(%rbx), %rcx
movl %eax, %edx
subl %ecx, %edx
cmpl $-0x7d, %edx
jl 0xdd5a
addl $0xfe, %edx
cmpl $0x108, %ebp            # imm = 0x108
movl $0x27, %eax
cmovel %eax, %ebp
cmpl $0x109, %ebp            # imm = 0x109
movl $0x2f, %eax
cmovel %eax, %ebp
cmpl $0x10a, %ebp            # imm = 0x10A
movl $0x3f, %eax
cmovel %eax, %ebp
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl %edx, %eax
jmp 0xdda8
movl 0x30(%rbx), %edx
subl 0x4(%rsp), %ecx
addl %edx, %ecx
addl $0x2, %ecx
movb %cl, (%rax,%rsi)
movq 0x10(%rbx), %rax
movb %ch, 0x1(%rax,%rsi)
movl 0x30(%rbx), %r12d
movq 0x48(%r14), %rax
cmpq 0x38(%r14), %rax
jb 0xdcd3
leaq 0x2e88d(%rip), %rdi     # 0x3c557
callq 0x455c
movq 0x48(%r14), %rax
incl %r12d
leaq 0x1(%rax), %rcx
movq %rcx, 0x48(%r14)
movq 0x30(%r14), %rcx
movw %r12w, (%rcx,%rax,2)
xorl %eax, %eax
leaq 0x2e867(%rip), %r12     # 0x3c557
jmp 0xda4b
movl %ebp, %eax
notl %eax
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testb $0x7, %al
jne 0xddad
cmpl $0x3f, %ebp
ja 0xddc3
movl %ebp, %eax
movabsq $-0x7fff7f8000000000, %rcx # imm = 0x8000808000000000
btq %rax, %rcx
jae 0xddc3
movq %r14, %rdi
movl $0xffffff80, %esi       # imm = 0xFFFFFF80
movl $0x7f, %edx
callq 0xd852
movzbl %al, %eax
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0xda4b
subl 0x4(%rsp), %edx
movb %dl, (%rax,%rbp)
movq 0x10(%rbx), %rax
movb %dh, 0x1(%rax,%rbp)
jmp 0xda89
movl %ebp, %edx
andl $0x10a, %edx            # imm = 0x10A
cmpl $0x108, %edx            # imm = 0x108
jne 0xdd98
cmpl $0x108, %ebp            # imm = 0x108
sete %dl
shlb $0x3, %dl
orb $0x27, %dl
leal 0x1(%rcx), %esi
movl %esi, 0x30(%rbx)
movq 0x10(%rbx), %rsi
movb %dl, (%rsi,%rcx)
movslq 0x30(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x30(%rbx)
movq 0x10(%rbx), %rdx
movb $0x3, (%rdx,%rcx)
subl 0x4(%rsp), %eax
movl %eax, %r13d
sarl $0x8, %r13d
movl $0xff, %ebp
movzbl %al, %eax
jmp 0xddb2
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0xff, %ebp
jbe 0xda4b
jmp 0xda5d
movq %r14, %rdi
xorl %esi, %esi
cmpl $0xff, %ebp
jne 0xddef
movl $0xffff, %edx           # imm = 0xFFFF
callq 0xd852
movl %eax, %r13d
movzbl %r13b, %eax
sarl $0x8, %r13d
movl $0xff, %ebp
jmp 0xda4b
movl $0xff, %edx
callq 0xd852
jmp 0xddb2
movslq 0x30(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x30(%rbx)
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq