// File: /workspace/github_c_makefile_star2_O3/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), %r14
movq $0x0, (%rsi)
movl 0x4c(%r14), %eax
testl %eax, %eax
jne 0x6200
movq 0x28(%r14), %rdi
testq %rdi, %rdi
je 0x5fba
movq 0x20(%r14), %rcx
xorl %edx, %edx
xorl %eax, %eax
cmpl $0x0, (%rcx,%rdx)
jg 0x61ef
incl %eax
addq $0x4, %rdx
cmpq %rdi, %rdx
jb 0x5fa5
movq 0x18(%r14), %rax
cmpq $0x29, %rax
jb 0x6012
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 0x6006
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 0x5fec
leaq 0x1(%r11), %rdi
cmpq %rax, %r11
movq %rdi, %r11
jne 0x5fde
movl 0x48(%r14), %edi
xorl %eax, %eax
testl %edi, %edi
jle 0x61f6
movq %rsi, -0x20(%rsp)
leaq 0x50(%r14), %rdx
leaq 0x70(%r14), %rax
movq %rax, -0x28(%rsp)
xorl %r8d, %r8d
leaq 0x6040(%rip), %r10      # 0xc07c
movl $0x3, %r11d
xorl %ebx, %ebx
xorl %r9d, %r9d
movq %r14, -0x18(%rsp)
leaq (%rbx,%rbx,4), %rax
movl %ebx, %ebp
shll $0x18, %ebp
movl 0x18(%rdx,%rax,8), %ecx
movl %ecx, -0x2c(%rsp)
cmpl %ecx, %ebp
je 0x61c3
movq %rax, -0x10(%rsp)
movq (%rdx,%rax,8), %r12
movq 0x8(%r14), %rax
movq %rax, -0x8(%rsp)
movslq %ebp, %rax
incl %ebp
movslq (%r12,%rax,4), %rsi
addq -0x8(%rsp), %rsi
xorl %eax, %eax
movl %eax, %ecx
movq %rsi, %r14
incq %rsi
movzbl (%r14), %eax
leal -0xe9(%rax), %edi
cmpl $0x16, %edi
ja 0x6087
movslq (%r10,%rdi,4), %rdi
addq %r10, %rdi
movl %ecx, %eax
jmpq *%rdi
addq $0x2, %r14
movq %r14, %rsi
incl %ebp
movl %ecx, %eax
jmp 0x6087
addq $0x2, %r14
movq %r14, %rsi
movslq %ebp, %rax
incl %ebp
addl %r9d, (%r12,%rax,4)
movl %ecx, %eax
jmp 0x6087
addq $0x2, %r14
movq %r14, %rsi
movl %ecx, %eax
andl $0xf0, %eax
xorl %r14d, %r14d
cmpl $0x80, %eax
sete %r14b
shll $0x2, %r14d
cmpl $0xe9, %ecx
cmovel %r11d, %r14d
xorl %eax, %eax
movslq %ebp, %r13
testl %r14d, %r14d
je 0x619c
movl (%r12,%r13,4), %edi
testl %edi, %edi
js 0x619c
movl %edi, %r15d
shrl $0x18, %r15d
leaq (%r15,%r15,4), %rax
movq (%rdx,%rax,8), %rax
movl (%rax,%rdi,4), %eax
cmpl %ebp, %edi
jle 0x6177
cmpq %r15, %rbx
jae 0x617a
movq -0x28(%rsp), %rdi
addl (%rdi), %eax
addq $0x28, %rdi
decq %r15
cmpq %r15, %rbx
jne 0x612c
jmp 0x617a
movslq %ebp, %rax
incl %ebp
movl (%r12,%rax,4), %eax
addl %r9d, %eax
movzbl 0x1(%r14), %esi
addq $0x2, %r14
andl %eax, %esi
subl %esi, %r9d
jmp 0x615c
addq $0x3, %r14
movq %r14, %rsi
movl %ecx, %eax
jmp 0x6087
movzbl 0x1(%r14), %eax
addq $0x2, %r14
movq %r14, %rsi
jmp 0x6087
subl %r9d, %eax
subl 0x4(%r12,%r13,4), %eax
movl $0xffffff80, %edi       # imm = 0xFFFFFF80
subl %r14d, %edi
cmpl $0x80, %eax
cmovgel %r8d, %r14d
cmpl %edi, %eax
cmovll %r8d, %r14d
subl %r14d, %r9d
movl %r14d, %eax
movl %eax, 0x4(%r12,%r13,4)
addl $0x2, %ebp
movl %ecx, %eax
jmp 0x6087
cmpl -0x2c(%rsp), %ebp
jne 0x6077
movq -0x18(%rsp), %r14
movl 0x48(%r14), %edi
movq -0x10(%rsp), %rax
leaq (%rdx,%rax,8), %rcx
movslq 0x20(%rcx), %rcx
movslq %r9d, %r9
addq %rcx, %r9
incq %rbx
movslq %edi, %rcx
addq $0x28, -0x28(%rsp)
cmpq %rcx, %rbx
jl 0x604c
movq -0x20(%rsp), %rsi
xorl %eax, %eax
jmp 0x61f9
orl $0x22000000, %eax       # imm = 0x22000000
jmp 0x6200
xorl %r9d, %r9d
movq %r9, 0x40(%r14)
movq %r9, (%rsi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq