// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq (%rdi), %r13
andq $0x0, (%rsi)
movl 0x4c(%r13), %eax
testl %eax, %eax
jne 0x5cc8
movq 0x28(%r13), %rcx
xorl %edx, %edx
xorl %eax, %eax
cmpq %rcx, %rdx
jae 0x5aa6
movq 0x20(%r13), %rdi
cmpl $0x0, (%rdi,%rdx)
jg 0x5cc3
incl %eax
addq $0x4, %rdx
jmp 0x5a8b
movq 0x18(%r13), %rcx
leaq 0x50(%r13), %rax
movabsq $0xa, %rdx
leaq (,%rdx,4), %rdi
cmpq %rcx, %rdi
jae 0x5af3
movq 0x10(%r13), %rdi
movl (%rdi,%rdx,4), %edi
movl %edx, %r10d
negl %r10d
testl %edi, %edi
jle 0x5aee
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 0x5ad2
incq %rdx
jmp 0x5ab8
movq %rsi, -0x18(%rsp)
leaq 0x70(%r13), %rcx
movq %rcx, -0x20(%rsp)
xorl %edi, %edi
leaq 0x5572(%rip), %r8       # 0xb07c
movl $0x3, %r9d
xorl %ebx, %ebx
xorl %r11d, %r11d
movq %r13, -0x8(%rsp)
movslq 0x48(%r13), %rcx
cmpq %rcx, %rbx
jge 0x5cb0
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 0x5c99
movslq %r12d, %rcx
incl %r12d
movslq (%r15,%rcx,4), %r14
addq 0x8(%r13), %r14
xorl %edx, %edx
movl %edx, %r13d
movq %r14, %rcx
incq %r14
movzbl (%rcx), %edx
leal -0xe9(%rdx), %esi
cmpl $0x16, %esi
ja 0x5b62
movslq (%r8,%rsi,4), %r10
addq %r8, %r10
movslq %r12d, %rsi
movl %r13d, %edx
jmpq *%r10
addq $0x2, %rcx
movq %rcx, %r14
incl %r12d
movl %r13d, %edx
jmp 0x5b62
addq $0x2, %rcx
movq %rcx, %r14
leal 0x1(%rsi), %r12d
addl %r11d, (%r15,%rsi,4)
movl %r13d, %edx
jmp 0x5b62
addq $0x2, %rcx
movq %rcx, %r14
movl %r13d, %edx
andl $0xf0, %edx
xorl %ecx, %ecx
cmpl $0x80, %edx
sete %cl
shll $0x2, %ecx
cmpl $0xe9, %r13d
cmovel %r9d, %ecx
xorl %ebp, %ebp
testl %ecx, %ecx
je 0x5c7e
movl (%r15,%rsi,4), %edx
testl %edx, %edx
js 0x5c7e
movl %edx, %r10d
shrl $0x18, %r10d
imulq $0x28, %r10, %r10
movq (%rax,%r10), %r10
movl (%r10,%rdx,4), %ebp
cmpl %r12d, %edx
jle 0x5c5c
shrl $0x18, %edx
cmpq %rdx, %rbx
cmovaq %rbx, %rdx
movq -0x20(%rsp), %r10
cmpq %rdx, %rbx
je 0x5c5f
addl (%r10), %ebp
decq %rdx
addq $0x28, %r10
jmp 0x5c12
leal 0x1(%rsi), %r12d
movl (%r15,%rsi,4), %edx
addl %r11d, %edx
movzbl 0x1(%rcx), %esi
addq $0x2, %rcx
andl %edx, %esi
subl %esi, %r11d
jmp 0x5c41
addq $0x3, %rcx
movq %rcx, %r14
movl %r13d, %edx
jmp 0x5b62
movzbl 0x1(%rcx), %edx
addq $0x2, %rcx
movq %rcx, %r14
jmp 0x5b62
subl %r11d, %ebp
subl 0x4(%r15,%rsi,4), %ebp
movl $0xffffff80, %edx       # imm = 0xFFFFFF80
subl %ecx, %edx
cmpl $0x80, %ebp
cmovgel %edi, %ecx
cmpl %edx, %ebp
cmovll %edi, %ecx
subl %ecx, %r11d
movl %ecx, %ebp
movl %ebp, 0x4(%r15,%rsi,4)
addl $0x2, %r12d
movl %r13d, %edx
jmp 0x5b62
movq -0x8(%rsp), %r13
jmp 0x5b47
movq -0x10(%rsp), %rcx
addl 0x20(%rcx), %r11d
incq %rbx
addq $0x28, -0x20(%rsp)
jmp 0x5b1a
movslq %r11d, %rax
movq %rax, 0x40(%r13)
movq -0x18(%rsp), %rcx
movq %rax, (%rcx)
xorl %eax, %eax
jmp 0x5cc8
orl $0x22000000, %eax       # imm = 0x22000000
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq