// File: /workspace/github_c_makefile_star2_O2/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), %rbx
testq %rbx, %rbx
je 0xa773
movq %rdi, %r12
cmpb $0x2d, (%rbx)
jne 0xa3bf
cmpb $0x0, 0x1(%rbx)
je 0xa6d4
leaq 0x5826(%rip), %rsi      # 0xfbec
movq %rbx, %rdi
callq 0x5190
movq %rax, %r14
testq %rax, %rax
je 0xa788
movq 0x10(%r12), %rcx
leaq 0x65c4(%rip), %rdi      # 0x109aa
pushq $0x2e
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x51d0
movq 0x10(%r12), %rcx
leaq 0x70d2(%rip), %rdi      # 0x114d2
pushq $0x26
popq %rsi
movq %rbx, %rdx
callq 0x51d0
andl $0x0, 0xde8e(%rip)      # 0x182a0
andl $0x0, 0xde8b(%rip)      # 0x182a4
andl $0x0, 0xde88(%rip)      # 0x182a8
leaq 0x10(%rsp), %r15
pushq $0x6
popq %rbp
movq %r12, 0x8(%rsp)
movq %r15, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x50f0
testq %rax, %rax
je 0xa5ee
movl 0xde54(%rip), %ebx      # 0x182a0
incl %ebx
movl %ebx, 0xde4c(%rip)      # 0x182a0
movq %r15, %rdi
leaq 0x709b(%rip), %rsi      # 0x114f9
movq %rbp, %rdx
callq 0x5170
testl %eax, %eax
jne 0xa42d
leaq 0x16(%rsp), %rdi
pushq $0x29
popq %rsi
callq 0x50b0
movzbl 0x16(%rsp), %ecx
cmpl $0x28, %ecx
sete %dl
testq %rax, %rax
setne %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xa55e
movq %r14, %r13
movq %rbp, %r14
movb $0x0, (%rax)
leaq 0x17(%rsp), %rax
movq %rax, 0x110(%rsp)
leaq 0x110(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0xa7ba
movl %eax, %r12d
movq %rbp, %rdi
xorl %esi, %esi
pushq $0x7f
popq %rdx
callq 0xa7ba
movl %eax, %ebx
movq %rbp, %rdi
pushq $0x1
popq %rsi
movl $0x3ff, %edx            # imm = 0x3FF
callq 0xa7ba
movl 0xddc0(%rip), %ecx      # 0x182a8
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0xa740
movl 0xdda9(%rip), %edx      # 0x182a4
shll $0x11, %r12d
shll $0xa, %ebx
orl %r12d, %ebx
orl %eax, %ebx
movl %ebx, %esi
andl $0xffffff, %esi         # imm = 0xFFFFFF
leaq 0xdd9a(%rip), %r10      # 0x182b0
leaq (%r10,%rcx,4), %rdi
movq %rcx, %rax
movq 0x8(%rsp), %r12
movq %r14, %rbp
movq %r13, %r14
testq %rax, %rax
je 0xa5d6
leal -0x1(%rax), %r8d
movl (%r10,%r8,4), %r8d
movl %r8d, %r9d
andl $0xffffff, %r9d         # imm = 0xFFFFFF
cmpl %esi, %r9d
jb 0xa5d6
je 0xa6e3
movl %r8d, (%rdi)
addq $-0x4, %rdi
decq %rax
jmp 0xa528
cmpl $0x58, %ecx
je 0xa56c
cmpl $0x46, %ecx
jne 0xa709
cmpb $0x28, 0x17(%rsp)
jne 0xa709
testq %rax, %rax
je 0xa709
movb $0x0, (%rax)
cmpl $0x0, 0xdd1a(%rip)      # 0x182a4
je 0xa5a3
movq 0x10(%r12), %rcx
leaq 0x6b5a(%rip), %rdi      # 0x110f2
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x51d0
cmpb $0x58, 0x16(%rsp)
movq 0x10(%r12), %rdi
leaq 0x6f51(%rip), %rsi      # 0x11505
leaq 0x6f45(%rip), %rax      # 0x11500
cmoveq %rax, %rsi
leaq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x5130
incl 0xdcd3(%rip)            # 0x182a4
jmp 0xa42d
shll $0x18, %edx
orl %edx, %ebx
movl %eax, %eax
movl %ebx, (%r10,%rax,4)
incl %ecx
movl %ecx, 0xdcbf(%rip)      # 0x182a8
jmp 0xa42d
movq %r14, %rdi
callq 0x5090
movq 0x10(%r12), %rcx
leaq 0x6c25(%rip), %rdi      # 0x11227
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
callq 0x51d0
movl 0xdc95(%rip), %ebp      # 0x182a8
orl $0x1, %ebp
leaq 0x110(%rsp), %rbx
pushq $0x1
popq %r12
leaq 0x7006(%rip), %r13      # 0x1162f
leaq 0x6fc9(%rip), %r14      # 0x115f9
cmpl $0x1fff, %ebp           # imm = 0x1FFF
ja 0xa75e
xorl %r15d, %r15d
cmpl $0x400, %r15d           # imm = 0x400
je 0xa660
movq %rbx, %rdi
movl %ebp, %esi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0xaa26
testl %eax, %eax
jne 0xa68d
incl %r15d
jmp 0xa63f
xorl %r15d, %r15d
cmpl $0x400, %r15d           # imm = 0x400
je 0xa685
movq %rbx, %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %r12d, %ecx
callq 0xaa26
testl %eax, %eax
jne 0xa68a
incl %r15d
jmp 0xa663
addl $0x2, %ebp
jmp 0xa630
movq %r13, %r14
leaq 0x110(%rsp), %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %edx
callq 0xab6a
movq 0x10(%rbx), %rdi
movl %r15d, %edx
shrl $0x5, %edx
andl $0x1f, %r15d
movq %r14, %rsi
movl %r15d, %ecx
movl %ebp, %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 0xb8fd(%rip), %rax      # 0x15fd8
movq (%rax), %r14
jmp 0xa3da
movq 0xb90e(%rip), %rax      # 0x15ff8
movq (%rax), %rdi
movl 0xdbad(%rip), %edx      # 0x182a0
leaq 0x6e7f(%rip), %rsi      # 0x11579
xorl %eax, %eax
callq 0x5130
pushq $0x1
popq %rdi
callq 0x51c0
movq %r15, %rdi
callq 0x50a0
movb $0x0, -0x1(%rax,%r15)
movq 0xb8da(%rip), %rax      # 0x15ff8
movq (%rax), %rdi
leaq 0x6de7(%rip), %rsi      # 0x1150f
leaq 0x6dca(%rip), %rdx      # 0x114f9
leaq 0x16(%rsp), %rcx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x5130
jmp 0xa701
movq 0xb8b1(%rip), %rax      # 0x15ff8
movq (%rax), %rcx
leaq 0x6df2(%rip), %rdi      # 0x11543
pushq $0x35
popq %rsi
pushq $0x1
popq %rdx
callq 0x51d0
jmp 0xa701
movq 0xb893(%rip), %rax      # 0x15ff8
movq (%rax), %rcx
leaq 0x6efe(%rip), %rdi      # 0x1166d
pushq $0x26
jmp 0xa753
movq 0xb87e(%rip), %rax      # 0x15ff8
movq (%rax), %rcx
leaq 0x6d2f(%rip), %rdi      # 0x114b3
pushq $0x1e
jmp 0xa753
movq 0xb869(%rip), %rax      # 0x15ff8
movq (%rax), %r14
callq 0x5040
movl (%rax), %edi
callq 0x51e0
leaq 0x6982(%rip), %rsi      # 0x11127
movq %r14, %rdi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x5130
jmp 0xa701