// File: /workspace/github_c_makefile_star2_O2/fanf2[P]luajit-2/src/buildvm_asm.c
// Function: emit_asm
void emit_asm(BuildCtx *ctx)
{
  int i, rel;

  fprintf(ctx->fp, "\t.file \"buildvm_%s.dasc\"\n", ctx->dasm_arch);
  fprintf(ctx->fp, "\t.text\n");
  emit_asm_align(ctx, 4);

  emit_asm_label(ctx, ctx->beginsym, 0, 0);
  if (ctx->mode != BUILD_machasm)
    fprintf(ctx->fp, ".Lbegin:\n");

  for (i = rel = 0; i < ctx->nsym; i++) {
    int32_t ofs = ctx->sym[i].ofs;
    int32_t next = ctx->sym[i+1].ofs;
    emit_asm_label(ctx, ctx->sym[i].name, next - ofs, 1);
    while (rel < ctx->nreloc && ctx->reloc[rel].ofs < next) {
      BuildReloc *r = &ctx->reloc[rel];
      int n = r->ofs - ofs;
#if LJ_TARGET_X86ORX64
      if (ctx->mode == BUILD_machasm && r->type != 0) {
	emit_asm_reloc_mach(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]);
      } else {
	emit_asm_bytes(ctx, ctx->code+ofs, n);
	emit_asm_reloc(ctx, r->type, ctx->relocsym[r->sym]);
      }
      ofs += n+4;
#else
      emit_asm_wordreloc(ctx, ctx->code+ofs, n, ctx->relocsym[r->sym]);
      ofs += n;
#endif
      rel++;
    }
#if LJ_TARGET_X86ORX64
    emit_asm_bytes(ctx, ctx->code+ofs, next-ofs);
#else
    emit_asm_words(ctx, ctx->code+ofs, next-ofs);
#endif
  }

  fprintf(ctx->fp, "\n");
  switch (ctx->mode) {
  case BUILD_elfasm:
    fprintf(ctx->fp, "\t.section .note.GNU-stack,\"\",@progbits\n");
#if LJ_TARGET_PPCSPE
    /* Soft-float ABI + SPE. */
    fprintf(ctx->fp, "\t.gnu_attribute 4, 2\n\t.gnu_attribute 8, 3\n");
#elif LJ_TARGET_PPC
    /* Hard-float ABI. */
    fprintf(ctx->fp, "\t.gnu_attribute 4, 1\n");
#endif
    /* fallthrough */
  case BUILD_coffasm:
    fprintf(ctx->fp, "\t.ident \"%s\"\n", ctx->dasm_ident);
    break;
  case BUILD_machasm:
    fprintf(ctx->fp,
      "\t.cstring\n"
      "\t.ascii \"%s\\0\"\n", ctx->dasm_ident);
    break;
  default:
    break;
  }
  fprintf(ctx->fp, "\n");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
movq 0x88(%rbx), %rdx
leaq 0x76b9(%rip), %rsi      # 0xf774
xorl %eax, %eax
callq 0x4130
movq 0x10(%rbx), %rcx
leaq 0x76c1(%rip), %rdi      # 0xf78e
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x41d0
movl 0x8(%rbx), %eax
cmpq $0x2, %rax
ja 0x80fd
leaq 0x7890(%rip), %rcx      # 0xf978
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
movq 0x10(%rbx), %rdi
pushq $0x4
popq %rdx
xorl %eax, %eax
callq 0x4130
movq 0x70(%rbx), %rsi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x838d
cmpl $0x2, 0x8(%rbx)
je 0x8129
movq 0x10(%rbx), %rcx
leaq 0x7678(%rip), %rdi      # 0xf796
pushq $0x9
popq %rsi
pushq $0x1
popq %rdx
callq 0x41d0
leaq 0x98(%rbx), %rax
movq %rax, 0x8(%rsp)
xorl %edx, %edx
xorl %r12d, %r12d
movslq 0x40(%rbx), %rax
cmpq %rax, %rdx
jge 0x82f8
movq 0x58(%rbx), %rax
movq %rdx, %rcx
shlq $0x4, %rcx
movl 0x8(%rax,%rcx), %r15d
incq %rdx
movq %rdx, 0x10(%rsp)
shlq $0x4, %rdx
movl 0x8(%rax,%rdx), %edx
movq (%rax,%rcx), %rsi
movl %edx, 0x4(%rsp)
subl %r15d, %edx
movq %rbx, %rdi
pushq $0x1
popq %rcx
callq 0x838d
movslq %r12d, %r12
imulq $0xc, %r12, %r14
addq 0x8(%rsp), %r14
movslq 0x44(%rbx), %rax
movslq %r15d, %rsi
cmpq %rax, %r12
jge 0x82d6
movl -0x8(%r14), %ebp
cmpl 0x4(%rsp), %ebp
jge 0x82d6
movl %ebp, %edx
subl %r15d, %edx
cmpl $0x2, 0x8(%rbx)
jne 0x81f5
cmpl $0x0, (%r14)
je 0x81f5
movq 0x60(%rbx), %rax
movslq -0x4(%r14), %rcx
movq (%rax,%rcx,8), %r15
testl %edx, %edx
jle 0x836a
addq 0x28(%rbx), %rsi
leal -0x1(%rdx), %eax
movl %eax, %ecx
movzbl (%rsi,%rcx), %ecx
cmpl $0xe8, %ecx
je 0x825c
cmpl $0xe9, %ecx
jne 0x8265
leaq 0x76a6(%rip), %r13      # 0xf896
jmp 0x82a2
addq 0x28(%rbx), %rsi
movq %rbx, %rdi
callq 0x8454
movl (%r14), %r13d
movq 0x60(%rbx), %rax
movslq -0x4(%r14), %rcx
movq (%rax,%rcx,8), %r15
movl 0x8(%rbx), %eax
cmpl $0x1, %eax
je 0x8222
testl %eax, %eax
je 0x8237
movq 0x10(%rbx), %rdi
jmp 0x8249
movq 0x10(%rbx), %rdi
leaq 0x762b(%rip), %rsi      # 0xf858
movq %r15, %rdx
xorl %eax, %eax
callq 0x4130
movq 0x10(%rbx), %rdi
testl %r13d, %r13d
je 0x8249
leaq 0x76d7(%rip), %rsi      # 0xf91e
jmp 0x8250
leaq 0x76dd(%rip), %rsi      # 0xf92d
movq %r15, %rdx
xorl %eax, %eax
callq 0x4130
jmp 0x82c4
leaq 0x5df5(%rip), %r13      # 0xe058
jmp 0x82a2
testb %cl, %cl
jns 0x836a
cmpl $0x1, %edx
je 0x836a
cmpb $-0x71, %cl
ja 0x836a
movl %edx, %eax
cmpb $0xf, -0x2(%rsi,%rax)
jne 0x836a
andl $0x7f, %ecx
leaq 0x76a2(%rip), %rax      # 0xf938
movslq (%rax,%rcx,4), %r13
addq %rax, %r13
addl $-0x2, %edx
movl %edx, %eax
movq %rbx, %rdi
movl %eax, %edx
callq 0x8454
movq 0x10(%rbx), %rdi
leaq 0x7618(%rip), %rsi      # 0xf8cf
movq %r13, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x4130
addl $0x4, %ebp
incq %r12
addq $0xc, %r14
movl %ebp, %r15d
jmp 0x8189
movq 0x28(%rbx), %rax
addq %rsi, %rax
movl 0x4(%rsp), %edx
subl %esi, %edx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x8454
movq 0x10(%rsp), %rdx
jmp 0x813a
movq 0x10(%rbx), %rsi
pushq $0xa
popq %rdi
callq 0x40d0
movl 0x8(%rbx), %eax
cmpl $0x2, %eax
je 0x8334
leaq 0x74b5(%rip), %r14      # 0xf7c8
cmpl $0x1, %eax
je 0x833b
testl %eax, %eax
jne 0x8350
movq 0x10(%rbx), %rcx
leaq 0x7479(%rip), %rdi      # 0xf7a0
pushq $0x27
popq %rsi
pushq $0x1
popq %rdx
callq 0x41d0
jmp 0x833b
leaq 0x749b(%rip), %r14      # 0xf7d6
movq 0x10(%rbx), %rdi
movq 0x80(%rbx), %rdx
movq %r14, %rsi
xorl %eax, %eax
callq 0x4130
movq 0x10(%rbx), %rsi
pushq $0xa
popq %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x40d0
movq 0xbc87(%rip), %rax      # 0x13ff8
movq (%rax), %rdi
leaq 0x751f(%rip), %rsi      # 0xf89a
movq %r15, %rdx
xorl %eax, %eax
callq 0x4130
pushq $0x1
popq %rdi
callq 0x41c0