// File: /workspace/github_cpp_makefile_star2_O1/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
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movl 0x30(%rsi), %eax
movl %eax, 0x10(%rsp)
leaq 0x4a5bc(%rip), %r15     # 0x579f0
movq %r14, %rdi
movq %r15, %rsi
callq 0xd290
cmpl $0x103, %eax            # imm = 0x103
je 0xd48c
movl %eax, %ebp
cmpl $0x104, %eax            # imm = 0x104
je 0xd4c2
leal -0x100(%rbp), %eax
cmpl $0x3, %eax
jb 0xd95a
leal -0x10b(%rbp), %eax
cmpl $0x1, %eax
ja 0xd57f
cmpl $0x10b, %ebp            # imm = 0x10B
je 0xd5ab
cmpl $0x10c, %ebp            # imm = 0x10C
jne 0xd5be
movb $0x2f, %al
jmp 0xd5ad
movl 0x30(%rbx), %ebp
movq 0x48(%r14), %rax
cmpq 0x38(%r14), %rax
jb 0xd4a5
leaq 0x448e7(%rip), %rdi     # 0x51d87
callq 0x455c
incl %ebp
movq 0x30(%r14), %rax
movq 0x48(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x48(%r14)
movw %bp, (%rax,%rcx,2)
movl $0x2f, %ebp
jmp 0xd4f6
movl 0x30(%rbx), %ebp
movq 0x48(%r14), %rax
cmpq 0x38(%r14), %rax
jb 0xd4db
leaq 0x448b1(%rip), %rdi     # 0x51d87
callq 0x455c
incl %ebp
movq 0x30(%r14), %rax
movq 0x48(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x48(%r14)
movw %bp, (%rax,%rcx,2)
movl $0x27, %ebp
xorl %r12d, %r12d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0xff, %ebp
ja 0xd519
movslq 0x30(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x30(%rbx)
movq 0x10(%rbx), %rcx
movb %bpl, (%rcx,%rax)
testl %r12d, %r12d
js 0xd530
movslq 0x30(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x30(%rbx)
movq 0x10(%rbx), %rcx
movb %r12b, (%rcx,%rax)
testl %r13d, %r13d
js 0xd547
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 0xd569
subl 0x2c(%rbx), %eax
addl 0x28(%rbx), %eax
cmpl $0x10002, %eax          # imm = 0x10002
jl 0xd434
movq %r14, %rdi
leaq 0x42022(%rip), %rsi     # 0x4f595
xorl %edx, %edx
callq 0xd0f0
jmp 0xd434
leal -0x105(%rbp), %eax
cmpl $0x8, %eax
ja 0xd753
leaq 0x3e25b(%rip), %rcx     # 0x4b7f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x3f, %ebp
xorl %r12d, %r12d
jmp 0xd6b8
movb $0x27, %al
movslq 0x30(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x30(%rbx)
movq 0x10(%rbx), %rdx
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 0xd5e9
leaq 0x447a3(%rip), %rdi     # 0x51d87
callq 0x455c
incl %ebp
movq 0x30(%r14), %rax
movq 0x48(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x48(%r14)
movw %bp, (%rax,%rcx,2)
movl $0xff, %ebp
xorl %r13d, %r13d
xorl %r12d, %r12d
jmp 0xd4ff
movzwl 0x30(%rbx), %ebp
movq 0x68(%r14), %rax
cmpq 0x58(%r14), %rax
jb 0xd629
leaq 0x44763(%rip), %rdi     # 0x51d87
callq 0x455c
movq 0x50(%r14), %rax
movq 0x68(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x68(%r14)
movw %bp, (%rax,%rcx,2)
movl $0x107, %ebp            # imm = 0x107
jmp 0xd89e
cmpq $0x0, 0x48(%r14)
jne 0xd65a
leaq 0x4474b(%rip), %rdi     # 0x51da0
callq 0x455c
movq 0x30(%r14), %rax
movq 0x48(%r14), %rcx
leaq -0x1(%rcx), %rdx
movq %rdx, 0x48(%r14)
movzwl -0x2(%rax,%rcx,2), %ebp
movl 0x30(%rbx), %ecx
movq 0x10(%rbx), %rax
cmpb $-0x1, -0x1(%rax,%rbp)
je 0xd88a
movl %ebp, %eax
notl %eax
addl %eax, %ecx
cmpl $0x80, %ecx
jl 0xd6a6
movq %r14, %rdi
leaq 0x41ed8(%rip), %rsi     # 0x4f571
xorl %edx, %edx
movl %ecx, %r12d
callq 0xd0f0
movl %r12d, %ecx
movq 0x10(%rbx), %rax
movb %cl, (%rax,%rbp)
jmp 0xd899
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
cmpl $0x10d, %ebp            # imm = 0x10D
movl $0xff, %eax
cmovel %eax, %ebp
setne 0xf(%rsp)
movl $0x0, %eax
cmovel %eax, %r12d
cmpq $0x0, 0x48(%r14)
jne 0xd6ea
leaq 0x446bb(%rip), %rdi     # 0x51da0
callq 0x455c
movq 0x30(%r14), %rax
movq 0x48(%r14), %rcx
leaq -0x1(%rcx), %rdx
movq %rdx, 0x48(%r14)
movzwl -0x2(%rax,%rcx,2), %r15d
movq 0x10(%rbx), %rax
cmpb $-0x1, -0x1(%rax,%r15)
je 0xd7d8
movl 0x30(%rbx), %eax
xorl %ecx, %ecx
cmpl $0xff, %ebp
sete %cl
subl %r15d, %ecx
addl %eax, %ecx
incl %ecx
cmpl $0x80, %ecx
jl 0xd746
movq %r14, %rdi
leaq 0x41e1e(%rip), %rsi     # 0x4f555
xorl %edx, %edx
movl %ecx, 0x14(%rsp)
callq 0xd0f0
movl 0x14(%rsp), %ecx
movq 0x10(%rbx), %rax
movb %cl, (%rax,%r15)
jmp 0xd7fe
leal -0x108(%rbp), %eax
cmpl $0x2, %eax
ja 0xd846
cmpq $0x0, 0x68(%r14)
jne 0xd775
leaq 0x44630(%rip), %rdi     # 0x51da0
callq 0x455c
movq 0x50(%r14), %rax
movq 0x68(%r14), %rcx
leaq -0x1(%rcx), %rdx
movq %rdx, 0x68(%r14)
movzwl -0x2(%rax,%rcx,2), %eax
movslq 0x30(%rbx), %rdx
movl %eax, %ecx
subl %edx, %ecx
cmpl $-0x7d, %ecx
jl 0xd8af
addl $0xfe, %ecx
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 %ecx, %eax
jmp 0xd913
movl 0x30(%rbx), %ecx
xorl %edx, %edx
cmpl $0xff, %ebp
sete %dl
subl 0x10(%rsp), %edx
addl %edx, %ecx
addl $0x2, %ecx
movb %cl, (%rax,%r15)
movq 0x10(%rbx), %rax
movl %r15d, %edx
movb %ch, 0x1(%rax,%rdx)
movl 0x30(%rbx), %r15d
movq 0x48(%r14), %rax
cmpq 0x38(%r14), %rax
jb 0xd818
leaq 0x44574(%rip), %rdi     # 0x51d87
callq 0x455c
movb 0xf(%rsp), %al
movb %al, %r13b
negl %r13d
incl %r15d
movq 0x30(%r14), %rax
movq 0x48(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x48(%r14)
movw %r15w, (%rax,%rcx,2)
leaq 0x4a1af(%rip), %r15     # 0x579f0
jmp 0xd4ff
movl %ebp, %eax
notl %eax
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testb $0x7, %al
jne 0xd8a4
cmpl $0x3f, %ebp
ja 0xd91c
movl %ebp, %eax
movabsq $-0x7fff7f8000000000, %rcx # imm = 0x8000808000000000
btq %rax, %rcx
jae 0xd91c
movq %r14, %rdi
movl $0xffffff80, %esi       # imm = 0xFFFFFF80
movl $0x7f, %edx
callq 0xd348
jmp 0xd913
subl 0x10(%rsp), %ecx
movb %cl, (%rax,%rbp)
movq 0x10(%rbx), %rax
movb %ch, 0x1(%rax,%rbp)
movl $0x106, %ebp            # imm = 0x106
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0xd4ff
cmpl $0x108, %ebp            # imm = 0x108
jne 0xd8d7
leal 0x1(%rdx), %ecx
movl %ecx, 0x30(%rbx)
movq 0x10(%rbx), %rcx
movb $0x2f, (%rcx,%rdx)
movslq 0x30(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x30(%rbx)
movq 0x10(%rbx), %rdx
movb $0x3, (%rdx,%rcx)
cmpl $0x109, %ebp            # imm = 0x109
jne 0xd903
movslq 0x30(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x30(%rbx)
movq 0x10(%rbx), %rdx
movb $0x27, (%rdx,%rcx)
movslq 0x30(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x30(%rbx)
movq 0x10(%rbx), %rdx
movb $0x3, (%rdx,%rcx)
subl 0x10(%rsp), %eax
movl %eax, %r13d
sarl $0x8, %r13d
movl $0xff, %ebp
movzbl %al, %r12d
jmp 0xd4ff
movq %r14, %rdi
xorl %esi, %esi
cmpl $0xff, %ebp
jne 0xd948
movl $0xffff, %edx           # imm = 0xFFFF
callq 0xd348
movl %eax, %r13d
movzbl %r13b, %r12d
sarl $0x8, %r13d
movl $0xff, %ebp
jmp 0xd4ff
movl $0xff, %edx
callq 0xd348
movl %eax, %r12d
jmp 0xd4ff
movslq 0x30(%rbx), %rax
leal 0x1(%rax), %ecx
movl %ecx, 0x30(%rbx)
movq 0x10(%rbx), %rcx
movb $0x0, (%rcx,%rax)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop