// File: /workspace/github_c_makefile_star2_O3/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
movq $0x0, (%rsi)
movl 0x4c(%r14), %eax
testl %eax, %eax
jne 0x6152
movq 0x28(%r14), %rdi
testq %rdi, %rdi
je 0x5f36
movq 0x20(%r14), %rcx
xorl %edx, %edx
xorl %eax, %eax
cmpl $0x0, (%rcx,%rdx)
jg 0x6141
incl %eax
addq $0x4, %rdx
cmpq %rdi, %rdx
jb 0x5f21
movq 0x18(%r14), %rax
cmpq $0x29, %rax
jb 0x5f8e
movq 0x10(%r14), %rcx
leaq 0x50(%r14), %rdx
addq $-0x29, %rax
shrq $0x2, %rax
addq $0xa, %rax
movl $0xa, %r11d
movl (%rcx,%r11,4), %edi
testl %edi, %edi
jle 0x5f82
movl %r11d, %r8d
negl %r8d
movl %edi, %r9d
shrl $0x18, %edi
leaq (%rdi,%rdi,4), %rdi
movq (%rdx,%rdi,8), %r10
movl (%r10,%r9,4), %edi
movl %r8d, (%r10,%r9,4)
testl %edi, %edi
jg 0x5f68
leaq 0x1(%r11), %rdi
cmpq %rax, %r11
movq %rdi, %r11
jne 0x5f5a
movl 0x48(%r14), %ecx
xorl %eax, %eax
testl %ecx, %ecx
jle 0x6148
movq %rsi, -0x18(%rsp)
leaq 0x50(%r14), %rdx
leaq 0x70(%r14), %rax
movq %rax, -0x20(%rsp)
leaq 0x60b7(%rip), %r10      # 0xc06c
movl $0x3, %r11d
xorl %ebx, %ebx
xorl %r9d, %r9d
movq %r14, -0x10(%rsp)
leaq (%rbx,%rbx,4), %rax
movl %ebx, %ebp
shll $0x18, %ebp
movl 0x18(%rdx,%rax,8), %r15d
cmpl %r15d, %ebp
je 0x6115
movq %rax, -0x8(%rsp)
movq (%rdx,%rax,8), %r12
movq 0x8(%r14), %r13
movslq %ebp, %rax
incl %ebp
movslq (%r12,%rax,4), %rcx
addq %r13, %rcx
jmp 0x60e2
addq $0x3, %rsi
movq %rsi, %rcx
jmp 0x60e2
addq $0x2, %rsi
movq %rsi, %rcx
jmp 0x60e2
addq $0x2, %rsi
movq %rsi, %rcx
jmp 0x6029
addq $0x2, %rsi
movq %rsi, %rcx
movslq %ebp, %rax
addl %r9d, (%r12,%rax,4)
incl %ebp
jmp 0x60e2
movslq %ebp, %rax
incl %ebp
movl (%r12,%rax,4), %eax
addl %r9d, %eax
movzbl 0x1(%rsi), %ecx
addq $0x2, %rsi
andl %eax, %ecx
subl %ecx, %r9d
movq %rsi, %rcx
jmp 0x60e2
leaq 0x2(%rsi), %rcx
movb -0x1(%rsi), %al
movl %eax, %edi
andb $-0x10, %dil
xorl %esi, %esi
negb %dil
seto %sil
shll $0x2, %esi
cmpb $-0x17, %al
cmovel %r11d, %esi
xorl %eax, %eax
movslq %ebp, %r14
testl %esi, %esi
je 0x60da
movl (%r12,%r14,4), %edi
testl %edi, %edi
js 0x60da
movl %edi, %eax
shrl $0x18, %eax
leaq (%rax,%rax,4), %r8
movq (%rdx,%r8,8), %r8
movl (%r8,%rdi,4), %r8d
cmpl %ebp, %edi
jle 0x60b1
cmpq %rax, %rbx
jae 0x60b4
movq -0x20(%rsp), %rdi
addl (%rdi), %r8d
addq $0x28, %rdi
decq %rax
cmpq %rax, %rbx
jne 0x60a0
jmp 0x60b4
subl %r9d, %r8d
subl 0x4(%r12,%r14,4), %r8d
movl $0xffffff80, %eax       # imm = 0xFFFFFF80
subl %esi, %eax
cmpl $0x80, %r8d
movl $0x0, %edi
cmovgel %edi, %esi
cmpl %eax, %r8d
cmovll %edi, %esi
subl %esi, %r9d
movl %esi, %eax
movl %eax, 0x4(%r12,%r14,4)
addl $0x2, %ebp
movq %rcx, %rsi
incq %rcx
movzbl (%rsi), %eax
addl $0xffffff17, %eax       # imm = 0xFFFFFF17
cmpl $0x16, %eax
ja 0x60e2
movslq (%r10,%rax,4), %rax
addq %r10, %rax
jmpq *%rax
cmpl %r15d, %ebp
jne 0x5fe9
movq -0x10(%rsp), %r14
movl 0x48(%r14), %ecx
movq -0x8(%rsp), %rax
leaq (%rdx,%rax,8), %rax
movslq 0x20(%rax), %rax
movslq %r9d, %r9
addq %rax, %r9
incq %rbx
movslq %ecx, %rax
addq $0x28, -0x20(%rsp)
cmpq %rax, %rbx
jl 0x5fc5
movq -0x18(%rsp), %rsi
xorl %eax, %eax
jmp 0x614b
orl $0x22000000, %eax       # imm = 0x22000000
jmp 0x6152
xorl %r9d, %r9d
movq %r9, 0x40(%r14)
movq %r9, (%rsi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq