// File: /workspace/github_c_makefile_star2_O3/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 0xb146
movq %rdi, %rbx
cmpb $0x2d, (%r15)
jne 0xadc9
cmpb $0x0, 0x1(%r15)
je 0xb11b
leaq 0x5e1c(%rip), %rsi      # 0x10bec
movq %r15, %rdi
callq 0x5180
movq %rax, %r14
testq %rax, %rax
je 0xb14b
movq 0x10(%rbx), %rcx
leaq 0x6bbb(%rip), %rdi      # 0x119aa
movl $0x2e, %esi
movl $0x1, %edx
callq 0x51c0
movq %rbx, 0x8(%rsp)
movq 0x10(%rbx), %rcx
leaq 0x76c4(%rip), %rdi      # 0x124d2
movl $0x26, %esi
movl $0x1, %edx
callq 0x51c0
xorl %eax, %eax
movl %eax, 0xd47b(%rip)      # 0x182a0
movl %eax, 0xd479(%rip)      # 0x182a4
movl %eax, 0xd477(%rip)      # 0x182a8
leaq 0x10(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x50f0
testq %rax, %rax
je 0xb02c
movl $0x4f464a4c, %r13d      # imm = 0x4F464A4C
leaq 0xd457(%rip), %rbx      # 0x182b0
leaq 0x10(%rsp), %rbp
movl 0xd43b(%rip), %r12d     # 0x182a0
incl %r12d
movl %r12d, 0xd431(%rip)     # 0x182a0
movl 0x10(%rsp), %eax
xorl %r13d, %eax
movzwl 0x14(%rsp), %ecx
xorl $0x444c, %ecx           # imm = 0x444C
orl %eax, %ecx
jne 0xb013
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 0xaf7d
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 0xb153
movl %eax, %r15d
movq %r13, %rdi
xorl %esi, %esi
movl $0x7f, %edx
callq 0xb153
movl %eax, %r12d
movq %r13, %rdi
movl $0x1, %esi
movl $0x3ff, %edx            # imm = 0x3FF
callq 0xb153
movl 0xd3a0(%rip), %ecx      # 0x182a8
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0xb141
movl 0xd389(%rip), %edx      # 0x182a4
shll $0x11, %r15d
shll $0xa, %r12d
orl %r15d, %r12d
orl %eax, %r12d
testq %rcx, %rcx
je 0xaff9
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 0xaf70
je 0xb12a
movl %r9d, (%rdi)
addq $-0x4, %rdi
decq %rax
testq %r8, %r8
jne 0xaf42
xorl %eax, %eax
movl $0x4f464a4c, %r13d      # imm = 0x4F464A4C
movl %eax, %eax
jmp 0xb001
cmpl $0x58, %ecx
je 0xaf8b
cmpl $0x46, %ecx
jne 0xb12f
cmpb $0x28, 0x17(%rsp)
jne 0xb12f
testq %rax, %rax
je 0xb12f
movb $0x0, (%rax)
cmpl $0x0, 0xd2fb(%rip)      # 0x182a4
movq 0x8(%rsp), %r15
je 0xafca
movq 0x10(%r15), %rcx
movl $0x2, %esi
movl $0x1, %edx
leaq 0x712d(%rip), %rdi      # 0x120f2
callq 0x51c0
cmpb $0x58, 0x16(%rsp)
movq 0x10(%r15), %rdi
leaq 0x752b(%rip), %rsi      # 0x12505
leaq 0x751f(%rip), %rax      # 0x12500
cmoveq %rax, %rsi
leaq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x5130
incl 0xd2ad(%rip)            # 0x182a4
jmp 0xb013
xorl %eax, %eax
movl $0x4f464a4c, %r13d      # imm = 0x4F464A4C
shll $0x18, %edx
orl %edx, %r12d
movl %r12d, (%rbx,%rax,4)
incl %ecx
movl %ecx, 0xd295(%rip)      # 0x182a8
movq %rbp, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x50f0
testq %rax, %rax
jne 0xae5e
movq %r14, %rdi
callq 0x5090
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rcx
leaq 0x71e3(%rip), %rdi      # 0x12227
movl $0x5, %esi
movl $0x1, %edx
callq 0x51c0
movl 0xd24e(%rip), %r14d     # 0x182a8
cmpl $0x1fff, %r14d          # imm = 0x1FFF
ja 0xb0ce
orl $0x1, %r14d
leaq 0x110(%rsp), %r12
leaq 0x7583(%rip), %r15      # 0x125f9
leaq 0x75b2(%rip), %rbx      # 0x1262f
xorl %ebp, %ebp
movq %r12, %rdi
movl %r14d, %esi
movl %ebp, %edx
xorl %ecx, %ecx
callq 0xb406
testl %eax, %eax
jne 0xb0d6
incl %ebp
cmpl $0x400, %ebp            # imm = 0x400
jne 0xb07f
xorl %ebp, %ebp
movq %r12, %rdi
movl %r14d, %esi
movl %ebp, %edx
movl $0x1, %ecx
callq 0xb406
testl %eax, %eax
jne 0xb0d3
incl %ebp
cmpl $0x400, %ebp            # imm = 0x400
jne 0xb09e
leal 0x2(%r14), %eax
cmpl $0x1ffe, %r14d          # imm = 0x1FFE
movl %eax, %r14d
jb 0xb07d
callq 0x561b
movq %rbx, %r15
leaq 0x110(%rsp), %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movl %r14d, %edx
callq 0xb555
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 0x5130
addq $0x8118, %rsp           # imm = 0x8118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xaeb6(%rip), %rax      # 0x15fd8
movq (%rax), %r14
jmp 0xade4
callq 0x55cf
leaq 0x10(%rsp), %rdi
leaq 0x16(%rsp), %rsi
movl %r12d, %edx
callq 0x558a
callq 0x55f6
callq 0x5640
movq %r15, %rdi
callq 0x554e