// File: /workspace/github_c_makefile_star2_O0/zenkj[P]luajit-arm64/src/host/buildvm_fold.c
// Function: emit_fold
void emit_fold(BuildCtx *ctx)
{
  char buf[256];  /* We don't care about analyzing lines longer than that. */
  const char *fname = ctx->args[0];
  FILE *fp;

  if (fname == NULL) {
    fprintf(stderr, "Error: missing input filename\n");
    exit(1);
  }

  if (fname[0] == '-' && fname[1] == '\0') {
    fp = stdin;
  } else {
    fp = fopen(fname, "r");
    if (!fp) {
      fprintf(stderr, "Error: cannot open input file '%s': %s\n",
	      fname, strerror(errno));
      exit(1);
    }
  }

  fprintf(ctx->fp, "/* This is a generated file. DO NOT EDIT! */\n\n");
  fprintf(ctx->fp, "static const FoldFunc fold_func[] = {\n");

  lineno = 0;
  funcidx = 0;
  nkeys = 0;
  while (fgets(buf, sizeof(buf), fp) != NULL) {
    lineno++;
    /* The prefix must be at the start of a line, otherwise it's ignored. */
    if (!strncmp(buf, FOLDDEF_PREFIX, sizeof(FOLDDEF_PREFIX)-1)) {
      char *p = buf+sizeof(FOLDDEF_PREFIX)-1;
      char *q = strchr(p, ')');
      if (p[0] == '(' && q) {
	p++;
	*q = '\0';
	foldrule(p);
      } else if ((p[0] == 'F' || p[0] == 'X') && p[1] == '(' && q) {
	p += 2;
	*q = '\0';
	if (funcidx)
	  fprintf(ctx->fp, ",\n");
	if (p[-2] == 'X')
	  fprintf(ctx->fp, "  %s", p);
	else
	  fprintf(ctx->fp, "  fold_%s", p);
	funcidx++;
      } else {
	buf[strlen(buf)-1] = '\0';
	fprintf(stderr, "Error: unknown fold definition tag %s%s at line %d\n",
		FOLDDEF_PREFIX, p, lineno);
	exit(1);
      }
    }
  }
  fclose(fp);
  fprintf(ctx->fp, "\n};\n\n");

  makehash(ctx);
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x130(%rsp)
movq 0x130(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0xe3cd
movq 0xbc46(%rip), %rax      # 0x19ff8
movq (%rax), %rdi
leaq 0x80d7(%rip), %rsi      # 0x16493
movb $0x0, %al
callq 0x5110
movl $0x1, %edi
callq 0x5190
movq 0x28(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0xe3f9
movq 0x28(%rsp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0xe3f9
movq 0xbbe9(%rip), %rax      # 0x19fd8
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0xe461
movq 0x28(%rsp), %rdi
leaq 0x67f7(%rip), %rsi      # 0x14bfc
callq 0x5160
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
jne 0xe45f
movq 0xbbda(%rip), %rax      # 0x19ff8
movq (%rax), %rax
movq %rax, (%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x8(%rsp)
callq 0x5040
movl (%rax), %edi
callq 0x51b0
movq (%rsp), %rdi
movq 0x8(%rsp), %rdx
movq %rax, %rcx
leaq 0x7c9b(%rip), %rsi      # 0x160e9
movb $0x0, %al
callq 0x5110
movl $0x1, %edi
callq 0x5190
jmp 0xe461
movq 0x130(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x7565(%rip), %rsi      # 0x159d9
movb $0x0, %al
callq 0x5110
movq 0x130(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x8024(%rip), %rsi      # 0x164b2
movb $0x0, %al
callq 0x5110
movl $0x0, 0xddf1(%rip)      # 0x1c290
movl $0x0, 0xddeb(%rip)      # 0x1c294
movl $0x0, 0xdde5(%rip)      # 0x1c298
leaq 0x30(%rsp), %rdi
movq 0x20(%rsp), %rdx
movl $0x100, %esi            # imm = 0x100
callq 0x50e0
cmpq $0x0, %rax
je 0xe684
movl 0xddb9(%rip), %eax      # 0x1c290
addl $0x1, %eax
movl %eax, 0xddb0(%rip)      # 0x1c290
leaq 0x30(%rsp), %rdi
leaq 0x7fed(%rip), %rsi      # 0x164d9
movl $0x6, %edx
callq 0x5050
cmpl $0x0, %eax
jne 0xe67f
leaq 0x30(%rsp), %rax
addq $0x7, %rax
addq $-0x1, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
movl $0x29, %esi
callq 0x50b0
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x28, %eax
jne 0xe55f
cmpq $0x0, 0x10(%rsp)
je 0xe55f
movq 0x18(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %rax
movb $0x0, (%rax)
movq 0x18(%rsp), %rdi
callq 0xe6c0
jmp 0xe67d
movq 0x18(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x46, %eax
je 0xe57d
movq 0x18(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x58, %eax
jne 0xe633
movq 0x18(%rsp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x28, %eax
jne 0xe633
cmpq $0x0, 0x10(%rsp)
je 0xe633
movq 0x18(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %rax
movb $0x0, (%rax)
cmpl $0x0, 0xdcdc(%rip)      # 0x1c294
je 0xe5d4
movq 0x130(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x7ae7(%rip), %rsi      # 0x160b4
movb $0x0, %al
callq 0x5110
movq 0x18(%rsp), %rax
movsbl -0x2(%rax), %eax
cmpl $0x58, %eax
jne 0xe603
movq 0x130(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x18(%rsp), %rdx
leaq 0x7ee6(%rip), %rsi      # 0x164e0
movb $0x0, %al
callq 0x5110
jmp 0xe622
movq 0x130(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x18(%rsp), %rdx
leaq 0x7eca(%rip), %rsi      # 0x164e5
movb $0x0, %al
callq 0x5110
movl 0xdc6c(%rip), %eax      # 0x1c294
addl $0x1, %eax
movl %eax, 0xdc63(%rip)      # 0x1c294
jmp 0xe67b
leaq 0x30(%rsp), %rdi
callq 0x50a0
subq $0x1, %rax
movb $0x0, 0x30(%rsp,%rax)
movq 0xb9ab(%rip), %rax      # 0x19ff8
movq (%rax), %rdi
movq 0x18(%rsp), %rcx
movl 0xdc34(%rip), %r8d      # 0x1c290
leaq 0x7e8c(%rip), %rsi      # 0x164ef
leaq 0x7e6f(%rip), %rdx      # 0x164d9
movb $0x0, %al
callq 0x5110
movl $0x1, %edi
callq 0x5190
jmp 0xe67d
jmp 0xe67f
jmp 0xe4b3
movq 0x20(%rsp), %rdi
callq 0x5090
movq 0x130(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x7b66(%rip), %rsi      # 0x16207
movb $0x0, %al
callq 0x5110
movq 0x130(%rsp), %rdi
callq 0xe850
addq $0x138, %rsp            # imm = 0x138
retq
nopl (%rax)