// File: /workspace/github_c_makefile_star2_O0/LuaJIT[P]LuaJIT/src/host/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");
#if LJ_TARGET_MIPS32 && !LJ_ABI_SOFTFP
  fprintf(ctx->fp, "\t.module fp=32\n");
#endif
#if LJ_TARGET_MIPS
  fprintf(ctx->fp, "\t.set nomips16\n\t.abicalls\n\t.set noreorder\n\t.set nomacro\n");
#endif
  emit_asm_align(ctx, 4);

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

#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND
  /* This should really be moved into buildvm_arm.dasc. */
#if LJ_ARCH_HASFPU
  fprintf(ctx->fp,
	  ".fnstart\n"
	  ".save {r5, r6, r7, r8, r9, r10, r11, lr}\n"
	  ".vsave {d8-d15}\n"
	  ".save {r4}\n"
	  ".pad #28\n");
#else
  fprintf(ctx->fp,
	  ".fnstart\n"
	  ".save {r4, r5, r6, r7, r8, r9, r10, r11, lr}\n"
	  ".pad #28\n");
#endif
#endif

  for (i = rel = 0; i < ctx->nsym; i++) {
    int32_t ofs = ctx->sym[i].ofs;
    int32_t next = ctx->sym[i+1].ofs;
#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND && LJ_HASFFI
    if (!strcmp(ctx->sym[i].name, "lj_vm_ffi_call"))
      fprintf(ctx->fp,
	      ".globl lj_err_unwind_arm\n"
	      ".personality lj_err_unwind_arm\n"
	      ".fnend\n"
	      ".fnstart\n"
	      ".save {r4, r5, r11, lr}\n"
	      ".setfp r11, sp\n");
#endif
    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 (r->type != 0 &&
	  (ctx->mode == BUILD_elfasm || ctx->mode == BUILD_machasm)) {
	emit_asm_reloc_text(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
  }

#if LJ_TARGET_ARM && defined(__GNUC__) && !LJ_NO_UNWIND
  fprintf(ctx->fp,
#if !LJ_HASFFI
	  ".globl lj_err_unwind_arm\n"
	  ".personality lj_err_unwind_arm\n"
#endif
	  ".fnend\n");
#endif

  fprintf(ctx->fp, "\n");
  switch (ctx->mode) {
  case BUILD_elfasm:
#if !(LJ_TARGET_PS3 || LJ_TARGET_PSVITA)
    fprintf(ctx->fp, "\t.section .note.GNU-stack,\"\"," ELFASM_PX "progbits\n");
#endif
#if LJ_TARGET_PPC && !LJ_TARGET_PS3 && !LJ_ABI_SOFTFP
    /* 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:
#if defined(__apple_build_version__) && __apple_build_version__ >= 15000000 && __apple_build_version__ < 15000300
    /* Workaround for XCode 15.0 - 15.2. */
    fprintf(ctx->fp, "\t.subsections_via_symbols\n");
#endif
    fprintf(ctx->fp,
      "\t.cstring\n"
      "\t.ascii \"%s\\0\"\n", ctx->dasm_ident);
    break;
  default:
    break;
  }
  fprintf(ctx->fp, "\n");
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x30(%rsp), %rax
movq 0x90(%rax), %rdx
leaq 0x9918(%rip), %rsi      # 0x1588d
movb $0x0, %al
callq 0x5110
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x991b(%rip), %rsi      # 0x158a7
movb $0x0, %al
callq 0x5110
movq 0x30(%rsp), %rdi
movl $0x4, %esi
callq 0xc290
movq 0x30(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x70(%rax), %rsi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0xc300
movq 0x30(%rsp), %rax
cmpl $0x2, 0x8(%rax)
je 0xbfdb
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x98db(%rip), %rsi      # 0x158af
movb $0x0, %al
callq 0x5110
movl $0x0, 0x28(%rsp)
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movq 0x30(%rsp), %rcx
cmpl 0x40(%rcx), %eax
jge 0xc1ca
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movslq 0x2c(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, 0x24(%rsp)
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movl 0x2c(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, 0x20(%rsp)
movq 0x30(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x58(%rax), %rax
movslq 0x2c(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movl 0x20(%rsp), %edx
subl 0x24(%rsp), %edx
movl $0x1, %ecx
callq 0xc300
movl 0x28(%rsp), %ecx
movq 0x30(%rsp), %rdx
xorl %eax, %eax
cmpl 0x44(%rdx), %ecx
movb %al, 0x13(%rsp)
jge 0xc0a1
movq 0x30(%rsp), %rax
addq $0x98, %rax
movslq 0x28(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl 0x20(%rsp), %eax
setle %al
movb %al, 0x13(%rsp)
movb 0x13(%rsp), %al
testb $0x1, %al
jne 0xc0ae
jmp 0xc197
movq 0x30(%rsp), %rax
addq $0x98, %rax
movslq 0x28(%rsp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movl (%rax), %eax
subl 0x24(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x18(%rsp), %rax
cmpl $0x0, 0x8(%rax)
je 0xc131
movq 0x30(%rsp), %rax
cmpl $0x0, 0x8(%rax)
je 0xc0fa
movq 0x30(%rsp), %rax
cmpl $0x2, 0x8(%rax)
jne 0xc131
movq 0x30(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x28(%rax), %rsi
movslq 0x24(%rsp), %rax
addq %rax, %rsi
movl 0x14(%rsp), %edx
movq 0x30(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x18(%rsp), %rcx
movslq 0x4(%rcx), %rcx
movq (%rax,%rcx,8), %rcx
callq 0xc440
jmp 0xc178
movq 0x30(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x28(%rax), %rsi
movslq 0x24(%rsp), %rax
addq %rax, %rsi
movl 0x14(%rsp), %edx
callq 0xc610
movq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rax
movl 0x8(%rax), %esi
movq 0x30(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x18(%rsp), %rcx
movslq 0x4(%rcx), %rcx
movq (%rax,%rcx,8), %rdx
callq 0xc6e0
movl 0x14(%rsp), %eax
addl $0x4, %eax
addl 0x24(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0xc069
movq 0x30(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x28(%rax), %rsi
movslq 0x24(%rsp), %rax
addq %rax, %rsi
movl 0x20(%rsp), %edx
subl 0x24(%rsp), %edx
callq 0xc610
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0xbfeb
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x9243(%rip), %rsi      # 0x1541d
xorl %eax, %eax
callq 0x5110
movq 0x30(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0xc(%rsp)
testl %eax, %eax
je 0xc209
jmp 0xc1f3
movl 0xc(%rsp), %eax
subl $0x1, %eax
je 0xc220
jmp 0xc1fe
movl 0xc(%rsp), %eax
subl $0x2, %eax
je 0xc245
jmp 0xc26a
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x96a0(%rip), %rsi      # 0x158b9
movb $0x0, %al
callq 0x5110
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x30(%rsp), %rax
movq 0x88(%rax), %rdx
leaq 0x96a5(%rip), %rsi      # 0x158e1
movb $0x0, %al
callq 0x5110
jmp 0xc26c
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x30(%rsp), %rax
movq 0x88(%rax), %rdx
leaq 0x968e(%rip), %rsi      # 0x158ef
movb $0x0, %al
callq 0x5110
jmp 0xc26c
jmp 0xc26c
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x91a1(%rip), %rsi      # 0x1541d
movb $0x0, %al
callq 0x5110
addq $0x38, %rsp
retq
nopl (%rax,%rax)