// File: /workspace/github_c_makefile_star2_O2/macournoyer[P]peg/compile.c
// Function: Node_compile_c_ko
static void Node_compile_c_ko(Node *node, int ko)
{
  assert(node);
  switch (node->type)
    {
    case Rule:
      fprintf(stderr, "\ninternal error #1 (%s)\n", node->rule.name);
      exit(1);
      break;

    case Dot:
      fprintf(output, "  if (!yymatchDot()) goto l%d;", ko);
      break;

    case Name:
      fprintf(output, "  if (!yy_%s()) goto l%d;", node->name.rule->rule.name, ko);
      if (node->name.variable)
	fprintf(output, "  yyDo(yySet, %d, 0);", node->name.variable->variable.offset);
      break;

    case Character:
    case String:
      {
	int len= strlen(node->string.value);
	if (1 == len || (2 == len && '\\' == node->string.value[0]))
	  fprintf(output, "  if (!yymatchChar('%s')) goto l%d;", node->string.value, ko);
	else
	  fprintf(output, "  if (!yymatchString(\"%s\")) goto l%d;", node->string.value, ko);
      }
      break;

    case Class:
      fprintf(output, "  if (!yymatchClass((unsigned char *)\"%s\")) goto l%d;", makeCharClass(node->cclass.value), ko);
      break;

    case Action:
      fprintf(output, "  yyDo(yy%s, yybegin, yyend);", node->action.name);
      break;

    case Predicate:
      fprintf(output, "  yyText(yybegin, yyend);  if (!(%s)) goto l%d;", node->action.text, ko);
      break;

    case Alternate:
      {
	int ok= yyl();
	begin();
	save(ok);
	for (node= node->alternate.first;  node;  node= node->alternate.next)
	  if (node->alternate.next)
	    {
	      int next= yyl();
	      Node_compile_c_ko(node, next);
	      jump(ok);
	      label(next);
	      restore(ok);
	    }
	  else
	    Node_compile_c_ko(node, ko);
	end();
	label(ok);
      }
      break;

    case Sequence:
      for (node= node->sequence.first;  node;  node= node->sequence.next)
	Node_compile_c_ko(node, ko);
      break;

    case PeekFor:
      {
	int ok= yyl();
	begin();
	save(ok);
	Node_compile_c_ko(node->peekFor.element, ko);
	restore(ok);
	end();
      }
      break;

    case PeekNot:
      {
	int ok= yyl();
	begin();
	save(ok);
	Node_compile_c_ko(node->peekFor.element, ok);
	jump(ko);
	label(ok);
	restore(ok);
	end();
      }
      break;

    case Query:
      {
	int qko= yyl(), qok= yyl();
	begin();
	save(qko);
	Node_compile_c_ko(node->query.element, qko);
	jump(qok);
	label(qko);
	restore(qko);
	end();
	label(qok);
      }
      break;

    case Star:
      {
	int again= yyl(), out= yyl();
	label(again);
	begin();
	save(out);
	Node_compile_c_ko(node->star.element, out);
	jump(again);
	label(out);
	restore(out);
	end();
      }
      break;

    case Plus:
      {
	int again= yyl(), out= yyl();
	Node_compile_c_ko(node->plus.element, ko);
	label(again);
	begin();
	save(out);
	Node_compile_c_ko(node->plus.element, out);
	jump(again);
	label(out);
	restore(out);
	end();
      }
      break;

    default:
      fprintf(stderr, "\nNode_compile_c_ko: illegal node type %d\n", node->type);
      exit(1);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
testq %rdi, %rdi
je 0x3f07
movq %rdi, %r14
movl (%rdi), %edx
leal -0x1(%rdx), %eax
cmpl $0xf, %eax
ja 0x3f42
movl %esi, %r12d
leaq 0x1b63(%rip), %rcx      # 0x55b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10(%r14), %r14
movq %r14, %rdi
callq 0x1040
cmpl $0x1, %eax
je 0x3a7a
cmpl $0x2, %eax
jne 0x3a8d
cmpb $0x5c, (%r14)
jne 0x3a8d
leaq 0x672f(%rip), %rax      # 0xa1b0
movq (%rax), %rdi
leaq 0x3182(%rip), %rsi      # 0x6c0d
jmp 0x3a9e
leaq 0x671c(%rip), %rax      # 0xa1b0
movq (%rax), %rdi
leaq 0x3193(%rip), %rsi      # 0x6c31
movq %r14, %rdx
jmp 0x3ca2
movl 0x8714(%rip), %ebx      # 0xc1c0
leal 0x1(%rbx), %ebp
addl $0x2, %ebx
movl %ebx, 0x8708(%rip)      # 0xc1c0
movl %ebp, %edi
callq 0x3f62
callq 0x3f98
movl %ebx, %edi
callq 0x39f7
movq 0x10(%r14), %rdi
movl %ebx, %esi
callq 0x3a23
movl %ebp, %edi
callq 0x3fb4
movl %ebx, %edi
callq 0x3f62
movl %ebx, %edi
jmp 0x3d90
movl 0x86cf(%rip), %ebp      # 0xc1c0
incl %ebp
movl %ebp, 0x86c7(%rip)      # 0xc1c0
callq 0x3f98
movl %ebp, %edi
callq 0x39f7
movq 0x10(%r14), %rdi
movl %ebp, %esi
callq 0x3a23
movl %r12d, %edi
callq 0x3fb4
movl %ebp, %edi
callq 0x3f62
jmp 0x3bdb
movl 0x8696(%rip), %ebp      # 0xc1c0
incl %ebp
movl %ebp, 0x868e(%rip)      # 0xc1c0
callq 0x3f98
movl %ebp, %edi
callq 0x39f7
addq $0x10, %r14
movq (%r14), %rdi
testq %rdi, %rdi
je 0x3b90
leaq 0x8(%rdi), %r14
cmpq $0x0, 0x8(%rdi)
je 0x3b86
movl 0x8664(%rip), %r15d     # 0xc1c0
incl %r15d
movl %r15d, 0x865a(%rip)     # 0xc1c0
movl %r15d, %esi
callq 0x3a23
movl %ebp, %edi
callq 0x3fb4
movl %r15d, %edi
callq 0x3f62
movl %ebp, %edi
callq 0x3f7c
jmp 0x3b42
movl %r12d, %esi
callq 0x3a23
jmp 0x3b42
callq 0x3fce
movl %ebp, %edi
jmp 0x3cff
leaq 0x660d(%rip), %rax      # 0xa1b0
movq (%rax), %rdi
leaq 0x3011(%rip), %rsi      # 0x6bbe
movl %r12d, %edx
jmp 0x3c78
movl 0x8605(%rip), %ebp      # 0xc1c0
incl %ebp
movl %ebp, 0x85fd(%rip)      # 0xc1c0
callq 0x3f98
movl %ebp, %edi
callq 0x39f7
movq 0x10(%r14), %rdi
movl %r12d, %esi
callq 0x3a23
movl %ebp, %edi
jmp 0x3d90
leaq 0x65c7(%rip), %rax      # 0xa1b0
movq 0x10(%r14), %rbx
cmpb $0x5e, (%rbx)
movl %r12d, 0xc(%rsp)
jne 0x3da8
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x20(%rsp)
movdqa %xmm0, 0x10(%rsp)
incq %rbx
leaq 0x3d5(%rip), %r14       # 0x3fea
jmp 0x3dbf
addq $0x10, %r14
movq (%r14), %r14
testq %r14, %r14
je 0x3ef8
movq %r14, %rdi
movl %r12d, %esi
callq 0x3a23
addq $0x8, %r14
jmp 0x3c1e
leaq 0x656e(%rip), %rbx      # 0xa1b0
movq (%rbx), %rdi
movq 0x10(%r14), %rax
movq 0x10(%rax), %rdx
leaq 0x2f89(%rip), %rsi      # 0x6bdd
movl %r12d, %ecx
xorl %eax, %eax
callq 0x10c0
movq 0x18(%r14), %rax
testq %rax, %rax
je 0x3ef8
movq (%rbx), %rdi
movl 0x20(%rax), %edx
leaq 0x2f7f(%rip), %rsi      # 0x6bf7
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10c0
leaq 0x651c(%rip), %rax      # 0xa1b0
movq (%rax), %rdi
movq 0x10(%r14), %rdx
leaq 0x3009(%rip), %rsi      # 0x6cab
movl %r12d, %ecx
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10c0
movl 0x8500(%rip), %ebx      # 0xc1c0
leal 0x1(%rbx), %ebp
addl $0x2, %ebx
movl %ebx, 0x84f4(%rip)      # 0xc1c0
callq 0x3f98
movl %ebp, %edi
callq 0x39f7
movq 0x10(%r14), %rdi
movl %ebp, %esi
callq 0x3a23
movl %ebx, %edi
callq 0x3fb4
movl %ebp, %edi
callq 0x3f62
movl %ebp, %edi
callq 0x3f7c
callq 0x3fce
movl %ebx, %edi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3f62
leaq 0x6497(%rip), %rax      # 0xa1b0
movq (%rax), %rdi
movq 0x20(%r14), %rdx
leaq 0x2f66(%rip), %rsi      # 0x6c8d
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10c0
movl 0x847d(%rip), %r15d     # 0xc1c0
leal 0x1(%r15), %ebp
addl $0x2, %r15d
movl %r15d, 0x846e(%rip)     # 0xc1c0
movq 0x10(%r14), %rdi
movl %r12d, %esi
callq 0x3a23
movl %ebp, %edi
callq 0x3f62
callq 0x3f98
movl %r15d, %edi
callq 0x39f7
movq 0x10(%r14), %rdi
movl %r15d, %esi
callq 0x3a23
movl %ebp, %edi
callq 0x3fb4
movl %r15d, %edi
callq 0x3f62
movl %r15d, %edi
callq 0x3f7c
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3fce
pxor %xmm0, %xmm0
movdqa %xmm0, 0x20(%rsp)
movdqa %xmm0, 0x10(%rsp)
leaq 0x241(%rip), %r14       # 0x4000
movq (%rax), %rax
movq %rax, 0x30(%rsp)
pushq $-0x1
popq %rax
movl %eax, %r12d
leaq 0x1(%rbx), %r13
movzbl (%rbx), %ebp
cmpl $0x2d, %ebp
je 0x3e1e
cmpl $0x5c, %ebp
je 0x3de7
testl %ebp, %ebp
jne 0x3e33
jmp 0x3ea8
movzbl (%r13), %r12d
testl %r12d, %r12d
je 0x3e33
leal -0x61(%r12), %eax
cmpl $0x5, %eax
jbe 0x3e45
leal -0x6e(%r12), %eax
cmpl $0x8, %eax
leaq 0x10(%rsp), %rdi
ja 0x3e78
leaq 0x17ff(%rip), %rcx      # 0x5610
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0xa
jmp 0x3e74
movzbl (%r13), %r15d
testl %r15d, %r15d
sete %al
testl %r12d, %r12d
sets %cl
orb %al, %cl
je 0x3e87
leaq 0x10(%rsp), %rdi
movl %ebp, %esi
callq *%r14
movq %r13, %rbx
movl %ebp, %r12d
jmp 0x3dcd
leaq 0x17ac(%rip), %rcx      # 0x55f8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
leaq 0x10(%rsp), %rdi
jmpq *%rax
pushq $0x7
jmp 0x3e74
pushq $0xc
jmp 0x3e74
pushq $0x1b
jmp 0x3e74
pushq $0x8
jmp 0x3e74
pushq $0xb
jmp 0x3e74
pushq $0x9
jmp 0x3e74
pushq $0xd
popq %rax
movl %eax, %r12d
addq $0x2, %rbx
movl %r12d, %esi
callq *%r14
jmp 0x3dcd
leaq 0x10(%rsp), %r13
cmpl %r15d, %r12d
jg 0x3e9f
movq %r13, %rdi
movl %r12d, %esi
callq *%r14
incl %r12d
jmp 0x3e8c
addq $0x2, %rbx
jmp 0x3dc7
leaq 0x8321(%rip), %r15      # 0xc1d0
leaq 0x2e4f(%rip), %r12      # 0x6d05
xorl %ebx, %ebx
cmpq $0x20, %rbx
je 0x3eda
movzbl 0x10(%rsp,%rbx), %edx
movq %r15, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x1160
cltq
addq %rax, %r15
incq %rbx
jmp 0x3eb8
leaq 0x2d76(%rip), %rsi      # 0x6c57
leaq 0x82e8(%rip), %rdx      # 0xc1d0
movq 0x30(%rsp), %rdi
movl 0xc(%rsp), %ecx
xorl %eax, %eax
callq 0x10c0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x142c(%rip), %rdi      # 0x533a
leaq 0x2acd(%rip), %rsi      # 0x69e2
leaq 0x2c65(%rip), %rcx      # 0x6b81
pushq $0x65
popq %rdx
callq 0x1060
movq 0x60cd(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movq 0x10(%r14), %rdx
leaq 0x2c6c(%rip), %rsi      # 0x6ba5
xorl %eax, %eax
callq 0x10c0
jmp 0x3f5a
movq 0x60af(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
leaq 0x2d88(%rip), %rsi      # 0x6cdb
xorl %eax, %eax
callq 0x10c0
pushq $0x1
popq %rdi
callq 0x1170