// File: /workspace/github_c_makefile_star2_O0/katlogic[P]ljx/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);
#if LJ_ARCH_PPC64
  fprintf(ctx->fp, "\t.abiversion 2\n");
#endif
  fprintf(ctx->fp, "\t.text\n");
  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
#if LJ_TARGET_MIPS
  fprintf(ctx->fp, ".set nomips16\n.abicalls\n.set noreorder\n.set nomacro\n");
#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
    /* 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:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x30(%rsp), %rax
movq 0x90(%rax), %rdx
leaq 0x9fa2(%rip), %rsi      # 0x16017
movb $0x0, %al
callq 0x5110
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x9fa5(%rip), %rsi      # 0x16031
movb $0x0, %al
callq 0x5110
movq 0x30(%rsp), %rdi
movl $0x4, %esi
callq 0xc390
movq 0x30(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x70(%rax), %rsi
xorl %ecx, %ecx
movl %ecx, %edx
callq 0xc400
movq 0x30(%rsp), %rax
cmpl $0x2, 0x8(%rax)
je 0xc0db
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x9f65(%rip), %rsi      # 0x16039
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 0xc2ca
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 0xc400
movl 0x28(%rsp), %ecx
movq 0x30(%rsp), %rdx
xorl %eax, %eax
cmpl 0x44(%rdx), %ecx
movb %al, 0x13(%rsp)
jge 0xc1a1
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 0xc1ae
jmp 0xc297
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 0xc231
movq 0x30(%rsp), %rax
cmpl $0x0, 0x8(%rax)
je 0xc1fa
movq 0x30(%rsp), %rax
cmpl $0x2, 0x8(%rax)
jne 0xc231
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 0xc530
jmp 0xc278
movq 0x30(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x28(%rax), %rsi
movslq 0x24(%rsp), %rax
addq %rax, %rsi
movl 0x14(%rsp), %edx
callq 0xc700
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 0xc7d0
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 0xc169
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 0xc700
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0xc0eb
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x9934(%rip), %rsi      # 0x15c0e
xorl %eax, %eax
callq 0x5110
movq 0x30(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0xc(%rsp)
testl %eax, %eax
je 0xc309
jmp 0xc2f3
movl 0xc(%rsp), %eax
subl $0x1, %eax
je 0xc320
jmp 0xc2fe
movl 0xc(%rsp), %eax
subl $0x2, %eax
je 0xc345
jmp 0xc36a
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x9d2a(%rip), %rsi      # 0x16043
movb $0x0, %al
callq 0x5110
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x30(%rsp), %rax
movq 0x88(%rax), %rdx
leaq 0x9d2f(%rip), %rsi      # 0x1606b
movb $0x0, %al
callq 0x5110
jmp 0xc36c
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x30(%rsp), %rax
movq 0x88(%rax), %rdx
leaq 0x9d18(%rip), %rsi      # 0x16079
movb $0x0, %al
callq 0x5110
jmp 0xc36c
jmp 0xc36c
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x9892(%rip), %rsi      # 0x15c0e
movb $0x0, %al
callq 0x5110
addq $0x38, %rsp
retq
nopl (%rax,%rax)