// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x5a48
jmp 0x5a67
leaq 0x196f(%rip), %rdi      # 0x73be
leaq 0x3038(%rip), %rsi      # 0x8a8e
movl $0x65, %edx
leaq 0x31cb(%rip), %rcx      # 0x8c2d
callq 0x1060
movq -0x8(%rbp), %rax
movl (%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0xf, %eax
ja 0x5e91
movq -0x40(%rbp), %rax
leaq 0x1bbf(%rip), %rcx      # 0x7648
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x655f(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x31a6(%rip), %rsi      # 0x8c51
movb $0x0, %al
callq 0x10c0
movl $0x1, %edi
callq 0x1170
leaq 0x66fd(%rip), %rax      # 0xc1c0
movq (%rax), %rdi
movl -0xc(%rbp), %edx
leaq 0x319a(%rip), %rsi      # 0x8c6a
movb $0x0, %al
callq 0x10c0
jmp 0x5eb9
leaq 0x66dd(%rip), %rax      # 0xc1c0
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rdx
movl -0xc(%rbp), %ecx
leaq 0x318d(%rip), %rsi      # 0x8c89
movb $0x0, %al
callq 0x10c0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x5b31
leaq 0x66ab(%rip), %rax      # 0xc1c0
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x20(%rax), %edx
leaq 0x3179(%rip), %rsi      # 0x8ca3
movb $0x0, %al
callq 0x10c0
jmp 0x5eb9
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x1040
movl %eax, -0x10(%rbp)
movl $0x1, %eax
cmpl -0x10(%rbp), %eax
je 0x5b6e
movl $0x2, %eax
cmpl -0x10(%rbp), %eax
jne 0x5b93
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %ecx
movl $0x5c, %eax
cmpl %ecx, %eax
jne 0x5b93
leaq 0x664b(%rip), %rax      # 0xc1c0
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdx
movl -0xc(%rbp), %ecx
leaq 0x312f(%rip), %rsi      # 0x8cb9
movb $0x0, %al
callq 0x10c0
jmp 0x5bb6
leaq 0x6626(%rip), %rax      # 0xc1c0
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdx
movl -0xc(%rbp), %ecx
leaq 0x312e(%rip), %rsi      # 0x8cdd
movb $0x0, %al
callq 0x10c0
jmp 0x5eb9
leaq 0x65fe(%rip), %rax      # 0xc1c0
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x5f20
movq -0x48(%rbp), %rdi
movq %rax, %rdx
movl -0xc(%rbp), %ecx
leaq 0x311c(%rip), %rsi      # 0x8d03
movb $0x0, %al
callq 0x10c0
jmp 0x5eb9
leaq 0x65c6(%rip), %rax      # 0xc1c0
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0x312d(%rip), %rsi      # 0x8d39
movb $0x0, %al
callq 0x10c0
jmp 0x5eb9
leaq 0x65a1(%rip), %rax      # 0xc1c0
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdx
movl -0xc(%rbp), %ecx
leaq 0x3123(%rip), %rsi      # 0x8d57
movb $0x0, %al
callq 0x10c0
jmp 0x5eb9
callq 0x59a0
movl %eax, -0x14(%rbp)
callq 0x6130
movl -0x14(%rbp), %edi
callq 0x59c0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x5cbd
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x5ca1
callq 0x59a0
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x5a30
movl -0x14(%rbp), %edi
callq 0x6150
movl -0x18(%rbp), %edi
callq 0x5ec0
movl -0x14(%rbp), %edi
callq 0x5ef0
jmp 0x5cad
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x5a30
jmp 0x5caf
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x5c61
callq 0x6180
movl -0x14(%rbp), %edi
callq 0x5ec0
jmp 0x5eb9
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x5cfc
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x5a30
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x5cdb
jmp 0x5eb9
callq 0x59a0
movl %eax, -0x1c(%rbp)
callq 0x6130
movl -0x1c(%rbp), %edi
callq 0x59c0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0xc(%rbp), %esi
callq 0x5a30
movl -0x1c(%rbp), %edi
callq 0x5ef0
callq 0x6180
jmp 0x5eb9
callq 0x59a0
movl %eax, -0x20(%rbp)
callq 0x6130
movl -0x20(%rbp), %edi
callq 0x59c0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x20(%rbp), %esi
callq 0x5a30
movl -0xc(%rbp), %edi
callq 0x6150
movl -0x20(%rbp), %edi
callq 0x5ec0
movl -0x20(%rbp), %edi
callq 0x5ef0
callq 0x6180
jmp 0x5eb9
callq 0x59a0
movl %eax, -0x24(%rbp)
callq 0x59a0
movl %eax, -0x28(%rbp)
callq 0x6130
movl -0x24(%rbp), %edi
callq 0x59c0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x24(%rbp), %esi
callq 0x5a30
movl -0x28(%rbp), %edi
callq 0x6150
movl -0x24(%rbp), %edi
callq 0x5ec0
movl -0x24(%rbp), %edi
callq 0x5ef0
callq 0x6180
movl -0x28(%rbp), %edi
callq 0x5ec0
jmp 0x5eb9
callq 0x59a0
movl %eax, -0x2c(%rbp)
callq 0x59a0
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %edi
callq 0x5ec0
callq 0x6130
movl -0x30(%rbp), %edi
callq 0x59c0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x30(%rbp), %esi
callq 0x5a30
movl -0x2c(%rbp), %edi
callq 0x6150
movl -0x30(%rbp), %edi
callq 0x5ec0
movl -0x30(%rbp), %edi
callq 0x5ef0
callq 0x6180
jmp 0x5eb9
callq 0x59a0
movl %eax, -0x34(%rbp)
callq 0x59a0
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0xc(%rbp), %esi
callq 0x5a30
movl -0x34(%rbp), %edi
callq 0x5ec0
callq 0x6130
movl -0x38(%rbp), %edi
callq 0x59c0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x38(%rbp), %esi
callq 0x5a30
movl -0x34(%rbp), %edi
callq 0x6150
movl -0x38(%rbp), %edi
callq 0x5ec0
movl -0x38(%rbp), %edi
callq 0x5ef0
callq 0x6180
jmp 0x5eb9
movq 0x6160(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl (%rax), %edx
leaq 0x2edf(%rip), %rsi      # 0x8d87
movb $0x0, %al
callq 0x10c0
movl $0x1, %edi
callq 0x1170
addq $0x50, %rsp
popq %rbp
retq
nop