// File: /workspace/github_c_makefile_star2_O3/LuaJIT[P]LuaJIT/src/host/buildvm_lib.c
// Function: emit_lib
void emit_lib(BuildCtx *ctx)
{
  const char *fname;

  if (ctx->mode == BUILD_ffdef || ctx->mode == BUILD_libdef ||
      ctx->mode == BUILD_recdef)
    fprintf(ctx->fp, "/* This is a generated file. DO NOT EDIT! */\n\n");
  else if (ctx->mode == BUILD_vmdef)
    fprintf(ctx->fp, "ffnames = {\n[0]=\"Lua\",\n\"C\",\n");
  if (ctx->mode == BUILD_recdef)
    fprintf(ctx->fp, "static const uint16_t recff_idmap[] = {\n0,\n0x0100");
  recffid = ffid = FF_C+1;
  ffasmfunc = 0;

  while ((fname = *ctx->args++)) {
    char buf[256];  /* We don't care about analyzing lines longer than that. */
    FILE *fp;
    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);
      }
    }
    modstate = 0;
    regfunc = REGFUNC_OK;
    while (fgets(buf, sizeof(buf), fp) != NULL) {
      char *p;
      /* Simplistic pre-processor. Only handles top-level #if/#endif. */
      if (buf[0] == '#' && buf[1] == 'i' && buf[2] == 'f') {
	int ok = 1;
	size_t len = strlen(buf);
	if (buf[len-1] == '\n') {
	  buf[len-1] = 0;
	  if (buf[len-2] == '\r') {
	    buf[len-2] = 0;
	  }
	}
	if (!strcmp(buf, "#if LJ_52"))
	  ok = LJ_52;
	else if (!strcmp(buf, "#if LJ_HASJIT"))
	  ok = LJ_HASJIT;
	else if (!strcmp(buf, "#if LJ_HASFFI"))
	  ok = LJ_HASFFI;
	else if (!strcmp(buf, "#if LJ_HASBUFFER"))
	  ok = LJ_HASBUFFER;
	if (!ok) {
	  int lvl = 1;
	  while (fgets(buf, sizeof(buf), fp) != NULL) {
	    if (buf[0] == '#' && buf[1] == 'e' && buf[2] == 'n') {
	      if (--lvl == 0) break;
	    } else if (buf[0] == '#' && buf[1] == 'i' && buf[2] == 'f') {
	      lvl++;
	    }
	  }
	  continue;
	}
      }
      for (p = buf; (p = strstr(p, LIBDEF_PREFIX)) != NULL; ) {
	const LibDefHandler *ldh;
	p += sizeof(LIBDEF_PREFIX)-1;
	for (ldh = libdef_handlers; ldh->suffix != NULL; ldh++) {
	  size_t n, len = strlen(ldh->suffix);
	  if (!strncmp(p, ldh->suffix, len)) {
	    p += len;
	    n = ldh->stop ? strcspn(p, ldh->stop) : 0;
	    if (!p[n]) break;
	    p[n] = '\0';
	    ldh->func(ctx, p, ldh->arg);
	    p += n+1;
	    break;
	  }
	}
	if (ldh->suffix == NULL) {
	  buf[strlen(buf)-1] = '\0';
	  fprintf(stderr, "Error: unknown library definition tag %s%s\n",
		  LIBDEF_PREFIX, p);
	  exit(1);
	}
      }
    }
    fclose(fp);
    if (ctx->mode == BUILD_libdef) {
      libdef_endmodule(ctx);
    }
  }

  if (ctx->mode == BUILD_ffdef) {
    fprintf(ctx->fp, "\n#undef FFDEF\n\n");
    fprintf(ctx->fp,
      "#ifndef FF_NUM_ASMFUNC\n#define FF_NUM_ASMFUNC %d\n#endif\n\n",
      ffasmfunc);
  } else if (ctx->mode == BUILD_vmdef) {
    fprintf(ctx->fp, "},\n\n");
  } else if (ctx->mode == BUILD_bcdef) {
    int i;
    fprintf(ctx->fp, "\n};\n\n");
    fprintf(ctx->fp, "LJ_DATADEF const uint16_t lj_bc_mode[] = {\n");
    fprintf(ctx->fp, "BCDEF(BCMODE)\n");
    for (i = ffasmfunc-1; i > 0; i--)
      fprintf(ctx->fp, "BCMODE_FF,\n");
    fprintf(ctx->fp, "BCMODE_FF\n};\n\n");
  } else if (ctx->mode == BUILD_recdef) {
    char *p = (char *)obuf;
    fprintf(ctx->fp, "\n};\n\n");
    fprintf(ctx->fp, "static const RecordFunc recff_func[] = {\n"
	    "recff_nyi,\n"
	    "recff_c");
    while (*p) {
      fprintf(ctx->fp, ",\nrecff_%s", p);
      p += strlen(p)+1;
    }
    fprintf(ctx->fp, "\n};\n\n");
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %rbx
movl 0x8(%rdi), %eax
leal -0x6(%rax), %ecx
cmpl $0x3, %ecx
jae 0x9e49
movq 0x10(%rbx), %rcx
leaq 0x8538(%rip), %rdi      # 0x1237a
movl $0x2e, %esi
jmp 0x9e5e
cmpl $0x9, %eax
jne 0x9e88
movq 0x10(%rbx), %rcx
leaq 0x8eb4(%rip), %rdi      # 0x12d0d
movl $0x1c, %esi
movl $0x1, %edx
callq 0x51d0
cmpl $0x8, 0x8(%rbx)
jne 0x9e88
movq 0x10(%rbx), %rcx
leaq 0x8eb1(%rip), %rdi      # 0x12d2a
movl $0x31, %esi
movl $0x1, %edx
callq 0x51d0
movl $0x2, %eax
movl %eax, 0xd37d(%rip)      # 0x17210
movl %eax, 0xd37b(%rip)      # 0x17214
movl $0x0, 0xd375(%rip)      # 0x17218
movq 0x20(%rbx), %rax
leaq 0x8(%rax), %rcx
movq %rbx, %r13
movq %rcx, 0x20(%rbx)
movq (%rax), %rbp
testq %rbp, %rbp
je 0xa102
leaq 0x8ec9(%rip), %r15      # 0x12d8e
cmpb $0x2d, (%rbp)
jne 0x9ed5
cmpb $0x0, 0x1(%rbp)
je 0xa0f3
movq %rbp, %rdi
leaq 0x6b2c(%rip), %rsi      # 0x10a0b
callq 0x5190
movq %rax, %r14
testq %rax, %rax
je 0xa2a5
xorl %eax, %eax
movl %eax, 0xd324(%rip)      # 0x1721c
movl %eax, 0xd322(%rip)      # 0x17220
leaq 0x10(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x50f0
testq %rax, %rax
je 0xa0bf
movq %r14, 0x8(%rsp)
cmpb $0x23, 0x10(%rsp)
jne 0x9f7c
cmpb $0x69, 0x11(%rsp)
jne 0x9f7c
cmpb $0x66, 0x12(%rsp)
jne 0x9f7c
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x50a0
cmpb $0xa, -0x1(%rax,%rbx)
jne 0x9f58
movb $0x0, 0xf(%rsp,%rax)
cmpb $0xd, 0xe(%rsp,%rax)
jne 0x9f58
movb $0x0, 0xe(%rsp,%rax)
movq 0x10(%rsp), %rax
movabsq $0x355f4a4c20666923, %rcx # imm = 0x355F4A4C20666923
xorq %rcx, %rax
movzwl 0x18(%rsp), %ecx
xorq $0x32, %rcx
orq %rax, %rcx
je 0xa04c
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x51f0
testq %rax, %rax
je 0xa02a
movq %rax, %rbp
addq $0x6, %rbp
leaq 0xcc70(%rip), %rbx      # 0x16c10
leaq 0x8f01(%rip), %r12      # 0x12ea8
movq %r12, %rdi
callq 0x50a0
movq %rax, %r14
movq %rbp, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x5050
testl %eax, %eax
je 0x9fd5
movq (%rbx), %r12
addq $0x20, %rbx
testq %r12, %r12
jne 0x9fa7
jmp 0xa298
addq %r14, %rbp
movq -0x18(%rbx), %rsi
testq %rsi, %rsi
je 0x9fee
movq %rbp, %rdi
callq 0x50e0
movq %rax, %r12
jmp 0x9ff1
xorl %r12d, %r12d
cmpb $0x0, (%rbp,%r12)
je 0xa013
addq %rbp, %r12
movb $0x0, (%r12)
movl -0x8(%rbx), %edx
movq %r13, %rdi
movq %rbp, %rsi
callq *-0x10(%rbx)
incq %r12
movq %r12, %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x51f0
movq %rax, %rbp
testq %rax, %rax
jne 0x9f95
leaq 0x10(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq 0x8(%rsp), %r14
movq %r14, %rdx
callq 0x50f0
testq %rax, %rax
jne 0x9f1e
jmp 0xa0bf
leaq 0x10(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0x50f0
testq %rax, %rax
je 0xa02a
movl $0x1, %ebx
movb 0x10(%rsp), %al
movb 0x11(%rsp), %cl
xorb $0x23, %al
movl %ecx, %esi
xorb $0x65, %sil
orb %al, %sil
movb 0x12(%rsp), %dl
movl %edx, %edi
xorb $0x6e, %dil
orb %sil, %dil
jne 0xa090
decl %ebx
jne 0xa0a1
jmp 0xa02a
xorb $0x69, %cl
orb %cl, %al
xorb $0x66, %dl
xorl %ecx, %ecx
orb %al, %dl
sete %cl
addl %ecx, %ebx
leaq 0x10(%rsp), %rdi
movl $0x100, %esi            # imm = 0x100
movq 0x8(%rsp), %rdx
callq 0x50f0
testq %rax, %rax
jne 0xa068
jmp 0xa02a
movq %r14, %rdi
callq 0x5090
movq %r13, %rbx
cmpl $0x7, 0x8(%r13)
jne 0xa0d9
movq %rbx, %rdi
callq 0xa2ad
movq 0x20(%rbx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x20(%rbx)
movq (%rax), %rbp
testq %rbp, %rbp
jne 0x9ec5
jmp 0xa102
movq 0xcede(%rip), %rax      # 0x16fd8
movq (%rax), %r14
jmp 0x9ef0
movl 0x8(%r13), %eax
addl $-0x5, %eax
cmpl $0x4, %eax
ja 0xa286
leaq 0x89c7(%rip), %rcx      # 0x12ae0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x10(%r13), %rcx
leaq 0x8d2e(%rip), %rdi      # 0x12e5b
movl $0x5, %esi
movl $0x1, %edx
callq 0x51d0
movq 0x10(%r13), %rcx
leaq 0x8cc4(%rip), %rdi      # 0x12e0b
movl $0x2b, %esi
movl $0x1, %edx
callq 0x51d0
movq 0x10(%r13), %rcx
leaq 0x8cd6(%rip), %rdi      # 0x12e37
movl $0xe, %esi
movl $0x1, %edx
callq 0x51d0
movl 0xd0a2(%rip), %ebx      # 0x17218
cmpl $0x2, %ebx
jl 0xa1a1
incl %ebx
leaq 0x8cc2(%rip), %r14      # 0x12e46
movq 0x10(%r13), %rcx
movl $0xb, %esi
movl $0x1, %edx
movq %r14, %rdi
callq 0x51d0
decl %ebx
cmpl $0x2, %ebx
ja 0xa184
movq 0x10(%r13), %rcx
leaq 0x8ca6(%rip), %rdi      # 0x12e52
movl $0xe, %esi
jmp 0xa27c
movq 0x10(%r13), %rcx
leaq 0x8c9a(%rip), %rdi      # 0x12e5b
movl $0x5, %esi
movl $0x1, %edx
callq 0x51d0
movq 0x10(%r13), %rcx
leaq 0x8c86(%rip), %rdi      # 0x12e61
movl $0x3b, %esi
movl $0x1, %edx
callq 0x51d0
cmpb $0x0, 0xd03f(%rip)      # 0x17230
je 0xa226
leaq 0xd036(%rip), %r14      # 0x17230
leaq 0x8c9c(%rip), %r15      # 0x12e9d
movq 0x10(%r13), %rdi
movq %r15, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x5130
movq %r14, %rdi
callq 0x50a0
addq %rax, %r14
incq %r14
cmpb $0x0, (%r14)
jne 0xa201
movq 0x10(%r13), %rcx
leaq 0x8c2a(%rip), %rdi      # 0x12e5b
movl $0x5, %esi
jmp 0xa27c
movq 0x10(%r13), %rcx
leaq 0x8b7e(%rip), %rdi      # 0x12dc1
movl $0xf, %esi
movl $0x1, %edx
callq 0x51d0
movq 0x10(%r13), %rdi
movl 0xcfbc(%rip), %edx      # 0x17218
leaq 0x8b6e(%rip), %rsi      # 0x12dd1
xorl %eax, %eax
callq 0x5130
jmp 0xa286
movq 0x10(%r13), %rcx
leaq 0x8233(%rip), %rdi      # 0x124aa
movl $0x4, %esi
movl $0x1, %edx
callq 0x51d0
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x535b
movq %rbp, %rdi
callq 0x531f