// File: /workspace/github_c_makefile_star2_O2/zenkj[P]luajit-arm64/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++];
      while (1) {
	int op, action = *p++;
	switch (action) {
	case DASM_REL_LG: p++; op = p[-3]; goto rel_pc;
	case DASM_REL_PC: op = p[-2]; 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;
	}
	case DASM_SPACE: case DASM_IMM_LG: case DASM_VREG: p++;
	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++;
	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: p++; break;
	case DASM_MARK: break;
	case DASM_SECTION: case DASM_STOP: goto stop;
	}
      }
      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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq (%rdi), %r14
andq $0x0, (%rsi)
movl 0x4c(%r14), %eax
testl %eax, %eax
jne 0x5c80
movq 0x28(%r14), %rcx
xorl %edx, %edx
xorl %eax, %eax
cmpq %rcx, %rdx
jae 0x5a7f
movq 0x20(%r14), %rdi
cmpl $0x0, (%rdi,%rdx)
jg 0x5c7b
incl %eax
addq $0x4, %rdx
jmp 0x5a64
movq 0x18(%r14), %rcx
leaq 0x50(%r14), %rax
movabsq $0xa, %rdx
leaq (,%rdx,4), %rdi
cmpq %rcx, %rdi
jae 0x5acc
movq 0x10(%r14), %rdi
movl (%rdi,%rdx,4), %edi
movl %edx, %r10d
negl %r10d
testl %edi, %edi
jle 0x5ac7
movl %edi, %r8d
shrl $0x18, %edi
imulq $0x28, %rdi, %rdi
movq (%rax,%rdi), %r9
movl (%r9,%r8,4), %edi
movl %r10d, (%r9,%r8,4)
jmp 0x5aab
incq %rdx
jmp 0x5a91
movq %rsi, -0x18(%rsp)
leaq 0x70(%r14), %rcx
movq %rcx, -0x20(%rsp)
xorl %edi, %edi
leaq 0x5589(%rip), %r8       # 0xb06c
movl $0x3, %r9d
movl $0xffffff80, %r10d      # imm = 0xFFFFFF80
xorl %ebx, %ebx
xorl %r11d, %r11d
movq %r14, -0x8(%rsp)
movslq 0x48(%r14), %rcx
cmpq %rcx, %rbx
jge 0x5c68
imulq $0x28, %rbx, %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, -0x10(%rsp)
movq (%rax,%rcx), %r15
movl %ebx, %r12d
shll $0x18, %r12d
movl 0x18(%rax,%rcx), %ecx
movl %ecx, -0x24(%rsp)
cmpl -0x24(%rsp), %r12d
je 0x5c51
movslq %r12d, %rcx
incl %r12d
movslq (%r15,%rcx,4), %r13
addq 0x8(%r14), %r13
movq %r13, %rsi
incq %r13
movzbl (%rsi), %ecx
addl $0xffffff17, %ecx       # imm = 0xFFFFFF17
cmpl $0x16, %ecx
ja 0x5b3f
movslq (%r8,%rcx,4), %rcx
addq %r8, %rcx
movslq %r12d, %r14
jmpq *%rcx
addq $0x2, %rsi
movq %rsi, %r13
incl %r12d
jmp 0x5b3f
addq $0x2, %rsi
movq %rsi, %r13
jmp 0x5b3f
addq $0x2, %rsi
movq %rsi, %r13
leal 0x1(%r14), %r12d
addl %r11d, (%r15,%r14,4)
jmp 0x5b3f
leaq 0x2(%rsi), %r13
movb -0x1(%rsi), %cl
movl %ecx, %edx
andb $-0x10, %dl
xorl %esi, %esi
negb %dl
seto %sil
shll $0x2, %esi
cmpb $-0x17, %cl
cmovel %r9d, %esi
xorl %ecx, %ecx
testl %esi, %esi
je 0x5c39
movl (%r15,%r14,4), %ebp
testl %ebp, %ebp
js 0x5c39
movl %ebp, %ecx
shrl $0x18, %ecx
imulq $0x28, %rcx, %rcx
movq (%rax,%rcx), %rcx
movl (%rcx,%rbp,4), %ecx
cmpl %r12d, %ebp
jle 0x5c19
shrl $0x18, %ebp
cmpq %rbp, %rbx
cmovaq %rbx, %rbp
movq -0x20(%rsp), %rdx
cmpq %rbp, %rbx
je 0x5c1c
addl (%rdx), %ecx
decq %rbp
addq $0x28, %rdx
jmp 0x5bdd
leal 0x1(%r14), %r12d
movl (%r15,%r14,4), %ecx
addl %r11d, %ecx
movzbl 0x1(%rsi), %edx
addq $0x2, %rsi
andl %ecx, %edx
subl %edx, %r11d
movq %rsi, %r13
jmp 0x5b3f
addq $0x3, %rsi
movq %rsi, %r13
jmp 0x5b3f
subl %r11d, %ecx
subl 0x4(%r15,%r14,4), %ecx
movl %r10d, %edx
subl %esi, %edx
cmpl $0x80, %ecx
cmovgel %edi, %esi
cmpl %edx, %ecx
cmovll %edi, %esi
subl %esi, %r11d
movl %esi, %ecx
movl %ecx, 0x4(%r15,%r14,4)
addl $0x2, %r12d
jmp 0x5b3f
movq -0x8(%rsp), %r14
jmp 0x5b26
movq -0x10(%rsp), %rcx
addl 0x20(%rcx), %r11d
incq %rbx
addq $0x28, -0x20(%rsp)
jmp 0x5af9
movslq %r11d, %rax
movq %rax, 0x40(%r14)
movq -0x18(%rsp), %rcx
movq %rax, (%rcx)
xorl %eax, %eax
jmp 0x5c80
orl $0x22000000, %eax       # imm = 0x22000000
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq