// File: /workspace/github_c_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8118, %rsp           # imm = 0x8118
movq 0x20(%rdi), %rax
movq (%rax), %r15
testq %r15, %r15
je 0xb1df
movq %rdi, %rbx
cmpb $0x2d, (%r15)
jne 0xae71
cmpb $0x0, 0x1(%r15)
je 0xb1b4
leaq 0x5d74(%rip), %rsi      # 0x10bec
movq %r15, %rdi
callq 0x5170
movq %rax, %r14
testq %rax, %rax
je 0xb1e4
movq 0x10(%rbx), %rcx
leaq 0x6b32(%rip), %rdi      # 0x119c9
movl $0x2e, %esi
movl $0x1, %edx
callq 0x51b0
movq %rbx, 0x8(%rsp)
movq 0x10(%rbx), %rcx
leaq 0x762c(%rip), %rdi      # 0x124e2
movl $0x26, %esi
movl $0x1, %edx
callq 0x51b0
xorl %eax, %eax
movl %eax, 0xe3c3(%rip)      # 0x19290
movl %eax, 0xe3c1(%rip)      # 0x19294
movl %eax, 0xe3bf(%rip)      # 0x19298
leaq 0x10(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x50f0
testq %rax, %rax
je 0xb0c5
movl $0x4f464a4c, %r13d      # imm = 0x4F464A4C
leaq 0xe39f(%rip), %rbx      # 0x192a0
leaq 0x10(%rsp), %rbp
movl 0xe383(%rip), %r12d     # 0x19290
incl %r12d
movl %r12d, 0xe379(%rip)     # 0x19290
movl 0x10(%rsp), %eax
xorl %r13d, %eax
movzwl 0x14(%rsp), %ecx
xorl $0x444c, %ecx           # imm = 0x444C
orl %eax, %ecx
jne 0xb0ac
leaq 0x16(%rsp), %rdi
movl $0x29, %esi
callq 0x50b0
movzbl 0x16(%rsp), %ecx
cmpl $0x28, %ecx
sete %dl
testq %rax, %rax
setne %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xb032
movb $0x0, (%rax)
leaq 0x17(%rsp), %rax
movq %rax, 0x110(%rsp)
leaq 0x110(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xb1ec
movl %eax, %r15d
movq %r13, %rdi
xorl %esi, %esi
movl $0x7f, %edx
callq 0xb1ec
movl %eax, %r12d
movq %r13, %rdi
movl $0x1, %esi
movl $0x3ff, %edx            # imm = 0x3FF
callq 0xb1ec
movl 0xe2e8(%rip), %ecx      # 0x19298
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0xb1da
movl 0xe2d1(%rip), %edx      # 0x19294
shll $0x11, %r15d
shll $0xa, %r12d
orl %r15d, %r12d
orl %eax, %r12d
movl %ecx, %eax
testl %ecx, %ecx
movl $0x4f464a4c, %r13d      # imm = 0x4F464A4C
je 0xb01b
movl %r12d, %esi
andl $0xffffff, %esi         # imm = 0xFFFFFF
leaq (%rbx,%rcx,4), %rdi
movq %rcx, %rax
leal -0x1(%rax), %r8d
movl (%rbx,%r8,4), %r9d
movl %r9d, %r10d
andl $0xffffff, %r10d        # imm = 0xFFFFFF
cmpl %esi, %r10d
jb 0xb01b
je 0xb1c3
movl %r9d, (%rdi)
addq $-0x4, %rdi
decq %rax
testq %r8, %r8
jne 0xafed
xorl %eax, %eax
shll $0x18, %edx
orl %edx, %r12d
movl %eax, %eax
movl %r12d, (%rbx,%rax,4)
leal 0x1(%rcx), %eax
movl %eax, 0xe268(%rip)      # 0x19298
jmp 0xb0ac
cmpl $0x58, %ecx
je 0xb040
cmpl $0x46, %ecx
jne 0xb1c8
cmpb $0x28, 0x17(%rsp)
jne 0xb1c8
testq %rax, %rax
je 0xb1c8
movb $0x0, (%rax)
cmpl $0x0, 0xe236(%rip)      # 0x19294
movq 0x8(%rsp), %r15
je 0xb07f
movq 0x10(%r15), %rcx
movl $0x2, %esi
movl $0x1, %edx
leaq 0x7088(%rip), %rdi      # 0x12102
callq 0x51b0
cmpb $0x58, 0x16(%rsp)
movq 0x10(%r15), %rdi
leaq 0x7486(%rip), %rsi      # 0x12515
leaq 0x747a(%rip), %rax      # 0x12510
cmoveq %rax, %rsi
leaq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x5120
incl 0xe1e8(%rip)            # 0x19294
movq %rbp, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x50f0
testq %rax, %rax
jne 0xaf06
movq %r14, %rdi
callq 0x5090
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rcx
leaq 0x715a(%rip), %rdi      # 0x12237
movl $0x5, %esi
movl $0x1, %edx
callq 0x51b0
movl 0xe1a5(%rip), %r14d     # 0x19298
cmpl $0x1fff, %r14d          # imm = 0x1FFF
ja 0xb167
orl $0x1, %r14d
leaq 0x110(%rsp), %r12
leaq 0x74fa(%rip), %r15      # 0x12609
leaq 0x7529(%rip), %rbx      # 0x1263f
xorl %ebp, %ebp
movq %r12, %rdi
movl %r14d, %esi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0xb4d4
testl %eax, %eax
jne 0xb16f
incl %ebp
cmpl $0x400, %ebp            # imm = 0x400
jne 0xb118
xorl %ebp, %ebp
movq %r12, %rdi
movl %r14d, %esi
movl %ebp, %edx
movl $0x1, %ecx
callq 0xb4d4
testl %eax, %eax
jne 0xb16c
incl %ebp
cmpl $0x400, %ebp            # imm = 0x400
jne 0xb137
leal 0x2(%r14), %eax
cmpl $0x1ffe, %r14d          # imm = 0x1FFE
movl %eax, %r14d
jb 0xb116
callq 0x563c
movq %rbx, %r15
leaq 0x110(%rsp), %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movl %r14d, %edx
callq 0xb623
movq 0x10(%rbx), %rdi
movl %ebp, %edx
shrl $0x5, %edx
andl $0x1f, %ebp
movq %r15, %rsi
movl %ebp, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x5120
addq $0x8118, %rsp           # imm = 0x8118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xbe1d(%rip), %rax      # 0x16fd8
movq (%rax), %r14
jmp 0xae8c
callq 0x55f0
leaq 0x10(%rsp), %rdi
leaq 0x16(%rsp), %rsi
movl %r12d, %edx
callq 0x55ab
callq 0x5617
callq 0x5661
movq %r15, %rdi
callq 0x556f