// File: /workspace/github_c_makefile_star2_O0/LuaJIT[P]LuaJIT/src/./../dynasm/dasm_x86.h
// Function: dasm_link
int dasm_link(Dst_DECL, size_t *szp)
{
  dasm_State *D = Dst_REF;
  int secnum;
  int ofs = 0;

#ifdef DASM_CHECKS
  *szp = 0;
  if (D->status != DASM_S_OK) return D->status;
  {
    int pc;
    for (pc = 0; pc*sizeof(int) < D->pcsize; pc++)
      if (D->pclabels[pc] > 0) return DASM_S_UNDEF_PC|pc;
  }
#endif

  { /* Handle globals not defined in this translation unit. */
    int idx;
    for (idx = 10; idx*sizeof(int) < D->lgsize; idx++) {
      int n = D->lglabels[idx];
      /* Undefined label: Collapse rel chain and replace with marker (< 0). */
      while (n > 0) { int *pb = DASM_POS2PTR(D, n); n = *pb; *pb = -idx; }
    }
  }

  /* Combine all code sections. No support for data sections (yet). */
  for (secnum = 0; secnum < D->maxsection; secnum++) {
    dasm_Section *sec = D->sections + secnum;
    int *b = sec->rbuf;
    int pos = DASM_SEC2POS(secnum);
    int lastpos = sec->pos;

    while (pos != lastpos) {
      dasm_ActList p = D->actionlist + b[pos++];
      int op = 0;
      while (1) {
	int action = *p++;
	switch (action) {
	case DASM_REL_LG: p++;
	  /* fallthrough */
	case DASM_REL_PC: {
	  int shrink = op == 0xe9 ? 3 : ((op&0xf0) == 0x80 ? 4 : 0);
	  if (shrink) {  /* Shrinkable branch opcode? */
	    int lofs, lpos = b[pos];
	    if (lpos < 0) goto noshrink;  /* Ext global? */
	    lofs = *DASM_POS2PTR(D, lpos);
	    if (lpos > pos) {  /* Fwd label: add cumulative section offsets. */
	      int i;
	      for (i = secnum; i < DASM_POS2SEC(lpos); i++)
		lofs += D->sections[i].ofs;
	    } else {
	      lofs -= ofs;  /* Bkwd label: unfix offset. */
	    }
	    lofs -= b[pos+1];  /* Short branch ok? */
	    if (lofs >= -128-shrink && lofs <= 127) ofs -= shrink;  /* Yes. */
	    else { noshrink: shrink = 0; }  /* No, cannot shrink op. */
	  }
	  b[pos+1] = shrink;
	  pos += 2;
	  break;
	}
	  /* fallthrough */
	case DASM_SPACE: case DASM_IMM_LG: case DASM_VREG: p++;
	  /* fallthrough */
	case DASM_DISP: case DASM_IMM_S: case DASM_IMM_B: case DASM_IMM_W:
	case DASM_IMM_D: case DASM_IMM_WB: case DASM_IMM_DB:
	case DASM_SETLABEL: case DASM_REL_A: case DASM_IMM_PC: pos++; break;
	case DASM_LABEL_LG: p++;
	  /* fallthrough */
	case DASM_LABEL_PC: b[pos++] += ofs; break; /* Fix label offset. */
	case DASM_ALIGN: ofs -= (b[pos++]+ofs)&*p++; break; /* Adjust ofs. */
	case DASM_EXTERN: p += 2; break;
	case DASM_ESC: op = *p++; break;
	case DASM_MARK: break;
	case DASM_SECTION: case DASM_STOP: goto stop;
	default: op = action; break;
	}
      }
      stop: (void)0;
    }
    ofs += sec->ofs;  /* Next section starts right after current section. */
  }

  D->codesize = ofs;  /* Total size of all code sections */
  *szp = ofs;
  return DASM_S_OK;
}

// Assembly:
pushq %rax
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movq -0x8(%rsp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rsp)
movl $0x0, -0x20(%rsp)
movq -0x10(%rsp), %rax
movq $0x0, (%rax)
movq -0x18(%rsp), %rax
cmpl $0x0, 0x4c(%rax)
je 0x6678
movq -0x18(%rsp), %rax
movl 0x4c(%rax), %eax
movl %eax, 0x4(%rsp)
jmp 0x6ab4
movl $0x0, -0x24(%rsp)
movslq -0x24(%rsp), %rax
shlq $0x2, %rax
movq -0x18(%rsp), %rcx
cmpq 0x28(%rcx), %rax
jae 0x66c9
movq -0x18(%rsp), %rax
movq 0x20(%rax), %rax
movslq -0x24(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jle 0x66ba
movl -0x24(%rsp), %eax
orl $0x22000000, %eax       # imm = 0x22000000
movl %eax, 0x4(%rsp)
jmp 0x6ab4
jmp 0x66bc
movl -0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rsp)
jmp 0x6680
movl $0xa, -0x28(%rsp)
movslq -0x28(%rsp), %rax
shlq $0x2, %rax
movq -0x18(%rsp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x675b
movq -0x18(%rsp), %rax
movq 0x10(%rax), %rax
movslq -0x28(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x2c(%rsp)
cmpl $0x0, -0x2c(%rsp)
jle 0x6749
movq -0x18(%rsp), %rax
addq $0x50, %rax
movl -0x2c(%rsp), %ecx
sarl $0x18, %ecx
movslq %ecx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x2c(%rsp), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rsp)
movq -0x38(%rsp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rsp)
xorl %ecx, %ecx
subl -0x28(%rsp), %ecx
movq -0x38(%rsp), %rax
movl %ecx, (%rax)
jmp 0x66fa
jmp 0x674b
movl -0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rsp)
jmp 0x66d1
movl $0x0, -0x1c(%rsp)
movl -0x1c(%rsp), %eax
movq -0x18(%rsp), %rcx
cmpl 0x48(%rcx), %eax
jge 0x6a91
movq -0x18(%rsp), %rax
addq $0x50, %rax
movslq -0x1c(%rsp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rsp)
movq -0x40(%rsp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rsp)
movl -0x1c(%rsp), %eax
shll $0x18, %eax
movl %eax, -0x4c(%rsp)
movq -0x40(%rsp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x50(%rsp)
movl -0x4c(%rsp), %eax
cmpl -0x50(%rsp), %eax
je 0x6a71
movq -0x18(%rsp), %rax
movq 0x8(%rax), %rax
movq -0x48(%rsp), %rcx
movl -0x4c(%rsp), %edx
movl %edx, %esi
addl $0x1, %esi
movl %esi, -0x4c(%rsp)
movslq %edx, %rdx
movslq (%rcx,%rdx,4), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rsp)
movl $0x0, -0x5c(%rsp)
movq -0x58(%rsp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x58(%rsp)
movzbl (%rax), %eax
movl %eax, -0x60(%rsp)
movl -0x60(%rsp), %eax
addl $0xffffff17, %eax       # imm = 0xFFFFFF17
movl %eax, %ecx
movq %rcx, -0x78(%rsp)
subl $0x16, %eax
ja 0x6a5f
movq -0x78(%rsp), %rax
leaq 0x883d(%rip), %rcx      # 0xf06c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rsp)
cmpl $0xe9, -0x5c(%rsp)
jne 0x685b
movl $0x3, %eax
movl %eax, -0x7c(%rsp)
jmp 0x6879
movl -0x5c(%rsp), %edx
andl $0xf0, %edx
xorl %eax, %eax
movl $0x4, %ecx
cmpl $0x80, %edx
cmovel %ecx, %eax
movl %eax, -0x7c(%rsp)
movl -0x7c(%rsp), %eax
movl %eax, -0x64(%rsp)
cmpl $0x0, -0x64(%rsp)
je 0x6980
movq -0x48(%rsp), %rax
movslq -0x4c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x6c(%rsp)
cmpl $0x0, -0x6c(%rsp)
jge 0x68a9
jmp 0x6976
movq -0x18(%rsp), %rax
addq $0x50, %rax
movl -0x6c(%rsp), %ecx
sarl $0x18, %ecx
movslq %ecx, %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x6c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x68(%rsp)
movl -0x6c(%rsp), %eax
cmpl -0x4c(%rsp), %eax
jle 0x6922
movl -0x1c(%rsp), %eax
movl %eax, -0x70(%rsp)
movl -0x70(%rsp), %eax
movl -0x6c(%rsp), %ecx
sarl $0x18, %ecx
cmpl %ecx, %eax
jge 0x6920
movq -0x18(%rsp), %rax
addq $0x50, %rax
movslq -0x70(%rsp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
addl -0x68(%rsp), %eax
movl %eax, -0x68(%rsp)
movl -0x70(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rsp)
jmp 0x68e4
jmp 0x6930
movl -0x20(%rsp), %ecx
movl -0x68(%rsp), %eax
subl %ecx, %eax
movl %eax, -0x68(%rsp)
movq -0x48(%rsp), %rax
movl -0x4c(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
movl -0x68(%rsp), %eax
subl %ecx, %eax
movl %eax, -0x68(%rsp)
movl -0x68(%rsp), %eax
movl $0xffffff80, %ecx       # imm = 0xFFFFFF80
subl -0x64(%rsp), %ecx
cmpl %ecx, %eax
jl 0x6974
cmpl $0x7f, -0x68(%rsp)
jg 0x6974
movl -0x64(%rsp), %ecx
movl -0x20(%rsp), %eax
subl %ecx, %eax
movl %eax, -0x20(%rsp)
jmp 0x697e
jmp 0x6976
movl $0x0, -0x64(%rsp)
jmp 0x6980
movl -0x64(%rsp), %edx
movq -0x48(%rsp), %rax
movl -0x4c(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x4c(%rsp), %eax
addl $0x2, %eax
movl %eax, -0x4c(%rsp)
jmp 0x6a67
movq -0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rsp)
movl -0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rsp)
jmp 0x6a67
movq -0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rsp)
movl -0x20(%rsp), %edx
movq -0x48(%rsp), %rax
movl -0x4c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x4c(%rsp)
movslq %ecx, %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
jmp 0x6a67
movq -0x48(%rsp), %rax
movl -0x4c(%rsp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x4c(%rsp)
movslq %ecx, %rcx
movl (%rax,%rcx,4), %ecx
addl -0x20(%rsp), %ecx
movq -0x58(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, -0x58(%rsp)
movzbl (%rax), %eax
andl %eax, %ecx
movl -0x20(%rsp), %eax
subl %ecx, %eax
movl %eax, -0x20(%rsp)
jmp 0x6a67
movq -0x58(%rsp), %rax
addq $0x2, %rax
movq %rax, -0x58(%rsp)
jmp 0x6a67
movq -0x58(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rsp)
movzbl (%rax), %eax
movl %eax, -0x5c(%rsp)
jmp 0x6a67
jmp 0x6a67
jmp 0x6a6c
movl -0x60(%rsp), %eax
movl %eax, -0x5c(%rsp)
jmp 0x67f3
jmp 0x67b3
movq -0x40(%rsp), %rax
movl 0x20(%rax), %eax
addl -0x20(%rsp), %eax
movl %eax, -0x20(%rsp)
movl -0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rsp)
jmp 0x6763
movslq -0x20(%rsp), %rcx
movq -0x18(%rsp), %rax
movq %rcx, 0x40(%rax)
movslq -0x20(%rsp), %rcx
movq -0x10(%rsp), %rax
movq %rcx, (%rax)
movl $0x0, 0x4(%rsp)
movl 0x4(%rsp), %eax
popq %rcx
retq
nopw (%rax,%rax)