// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
movq 0x90(%rbx), %rdx
leaq 0x81d5(%rip), %rsi      # 0x10ff8
xorl %eax, %eax
callq 0x5130
movq 0x10(%rbx), %rcx
leaq 0x81dd(%rip), %rdi      # 0x11012
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
callq 0x51d0
movl 0x8(%rbx), %eax
cmpq $0x2, %rax
ja 0x8e65
leaq 0x83b8(%rip), %rcx      # 0x11208
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
movq 0x10(%rbx), %rdi
pushq $0x4
popq %rdx
xorl %eax, %eax
callq 0x5130
movq 0x70(%rbx), %rsi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x9120
cmpl $0x2, 0x8(%rbx)
je 0x8e91
movq 0x10(%rbx), %rcx
leaq 0x8194(%rip), %rdi      # 0x1101a
pushq $0x9
popq %rsi
pushq $0x1
popq %rdx
callq 0x51d0
leaq 0xa0(%rbx), %rax
movq %rax, 0x8(%rsp)
xorl %edx, %edx
xorl %r12d, %r12d
movslq 0x40(%rbx), %rax
cmpq %rax, %rdx
jge 0x908b
movq 0x58(%rbx), %rax
movq %rdx, %rcx
shlq $0x4, %rcx
movl 0x8(%rax,%rcx), %ebp
incq %rdx
movq %rdx, 0x10(%rsp)
shlq $0x4, %rdx
movl 0x8(%rax,%rdx), %edx
movq (%rax,%rcx), %rsi
movl %edx, 0x4(%rsp)
subl %ebp, %edx
movq %rbx, %rdi
pushq $0x1
popq %rcx
callq 0x9120
movslq %r12d, %r12
imulq $0xc, %r12, %r15
addq 0x8(%rsp), %r15
movslq 0x44(%rbx), %rax
movslq %ebp, %rsi
cmpq %rax, %r12
jge 0x906f
movl -0x8(%r15), %r13d
cmpl 0x4(%rsp), %r13d
jg 0x906f
movl %r13d, %edx
subl %ebp, %edx
cmpl $0x0, (%r15)
je 0x8f5f
testl $0xfffffffd, 0x8(%rbx)  # imm = 0xFFFFFFFD
jne 0x8f5f
movq 0x60(%rbx), %rax
movslq -0x4(%r15), %rcx
movq (%rax,%rcx,8), %rbp
testl %edx, %edx
jle 0x90fd
addq 0x28(%rbx), %rsi
leal -0x1(%rdx), %eax
movl %eax, %ecx
movzbl (%rsi,%rcx), %ecx
cmpl $0xe8, %ecx
je 0x8fc9
cmpl $0xe9, %ecx
jne 0x8fd2
leaq 0x81c0(%rip), %r14      # 0x1111a
jmp 0x900f
addq 0x28(%rbx), %rsi
movq %rbx, %rdi
callq 0x91e7
movl (%r15), %r14d
movq 0x60(%rbx), %rax
movslq -0x4(%r15), %rcx
movq (%rax,%rcx,8), %rbp
movl 0x8(%rbx), %eax
cmpl $0x1, %eax
je 0x8f8c
testl %eax, %eax
je 0x8fa1
movq 0x10(%rbx), %rdi
jmp 0x8fb3
movq 0x10(%rbx), %rdi
leaq 0x8145(%rip), %rsi      # 0x110dc
movq %rbp, %rdx
xorl %eax, %eax
callq 0x5130
movq 0x10(%rbx), %rdi
testl %r14d, %r14d
je 0x8fb3
leaq 0x81fd(%rip), %rsi      # 0x111ae
jmp 0x8fba
leaq 0x8203(%rip), %rsi      # 0x111bd
movq %rbp, %rdx
xorl %eax, %eax
callq 0x5130
jmp 0x905c
leaq 0x6588(%rip), %r14      # 0xf558
jmp 0x900f
testb %cl, %cl
jns 0x90fd
cmpl $0x1, %edx
je 0x90fd
cmpb $-0x71, %cl
ja 0x90fd
movl %edx, %eax
cmpb $0xf, -0x2(%rsi,%rax)
jne 0x90fd
andl $0x7f, %ecx
leaq 0x81c5(%rip), %rax      # 0x111c8
movslq (%rax,%rcx,4), %r14
addq %rax, %r14
addl $-0x2, %edx
movl %edx, %eax
movq %rbx, %rdi
movl %eax, %edx
callq 0x91e7
xorl %eax, %eax
cmpb $0x5f, (%rbp)
sete %al
cmpb $0x6c, (%rbp,%rax)
jne 0x9037
cmpb $0x6a, 0x1(%rbp,%rax)
jne 0x9037
cmpb $0x5f, 0x2(%rbp,%rax)
je 0x9044
cmpl $0x0, 0x8(%rbx)
leaq 0x8111(%rip), %rsi      # 0x11153
je 0x904b
leaq 0x8114(%rip), %rsi      # 0x1115f
movq 0x10(%rbx), %rdi
movq %r14, %rdx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x5130
addl $0x4, %r13d
incq %r12
addq $0xc, %r15
movl %r13d, %ebp
jmp 0x8eef
addq 0x28(%rbx), %rsi
movl 0x4(%rsp), %edx
subl %ebp, %edx
movq %rbx, %rdi
callq 0x91e7
movq 0x10(%rsp), %rdx
jmp 0x8ea2
movq 0x10(%rbx), %rsi
pushq $0xa
popq %rdi
callq 0x50d0
movl 0x8(%rbx), %eax
cmpl $0x2, %eax
je 0x90c7
leaq 0x7fa6(%rip), %r14      # 0x1104c
cmpl $0x1, %eax
je 0x90ce
testl %eax, %eax
jne 0x90e3
movq 0x10(%rbx), %rcx
leaq 0x7f6a(%rip), %rdi      # 0x11024
pushq $0x27
popq %rsi
pushq $0x1
popq %rdx
callq 0x51d0
jmp 0x90ce
leaq 0x7f8c(%rip), %r14      # 0x1105a
movq 0x10(%rbx), %rdi
movq 0x88(%rbx), %rdx
movq %r14, %rsi
xorl %eax, %eax
callq 0x5130
movq 0x10(%rbx), %rsi
pushq $0xa
popq %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x50d0
movq 0xcef4(%rip), %rax      # 0x15ff8
movq (%rax), %rdi
leaq 0x8010(%rip), %rsi      # 0x1111e
movq %rbp, %rdx
xorl %eax, %eax
callq 0x5130
pushq $0x1
popq %rdi
callq 0x51c0