// File: /workspace/github_c_makefile_star2_O0/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 %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 0x65b8
movq -0x18(%rsp), %rax
movl 0x4c(%rax), %eax
movl %eax, 0x4(%rsp)
jmp 0x69f6
movl $0x0, -0x24(%rsp)
movslq -0x24(%rsp), %rax
shlq $0x2, %rax
movq -0x18(%rsp), %rcx
cmpq 0x28(%rcx), %rax
jae 0x6609
movq -0x18(%rsp), %rax
movq 0x20(%rax), %rax
movslq -0x24(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jle 0x65fa
movl -0x24(%rsp), %eax
orl $0x22000000, %eax       # imm = 0x22000000
movl %eax, 0x4(%rsp)
jmp 0x69f6
jmp 0x65fc
movl -0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rsp)
jmp 0x65c0
movl $0xa, -0x28(%rsp)
movslq -0x28(%rsp), %rax
shlq $0x2, %rax
movq -0x18(%rsp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x669b
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 0x6689
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 0x663a
jmp 0x668b
movl -0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rsp)
jmp 0x6611
movl $0x0, -0x1c(%rsp)
movl -0x1c(%rsp), %eax
movq -0x18(%rsp), %rcx
cmpl 0x48(%rcx), %eax
jge 0x69d3
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 0x69b3
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)
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 0x69a9
movq -0x78(%rsp), %rax
leaq 0x9905(%rip), %rcx      # 0x1006c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rsp)
movq -0x58(%rsp), %rax
movzbl -0x3(%rax), %eax
movl %eax, -0x5c(%rsp)
jmp 0x679a
movq -0x58(%rsp), %rax
movzbl -0x2(%rax), %eax
movl %eax, -0x5c(%rsp)
cmpl $0xe9, -0x5c(%rsp)
jne 0x67af
movl $0x3, %eax
movl %eax, -0x7c(%rsp)
jmp 0x67cd
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 0x68d4
movq -0x48(%rsp), %rax
movslq -0x4c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x6c(%rsp)
cmpl $0x0, -0x6c(%rsp)
jge 0x67fd
jmp 0x68ca
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 0x6876
movl -0x1c(%rsp), %eax
movl %eax, -0x70(%rsp)
movl -0x70(%rsp), %eax
movl -0x6c(%rsp), %ecx
sarl $0x18, %ecx
cmpl %ecx, %eax
jge 0x6874
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 0x6838
jmp 0x6884
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 0x68c8
cmpl $0x7f, -0x68(%rsp)
jg 0x68c8
movl -0x64(%rsp), %ecx
movl -0x20(%rsp), %eax
subl %ecx, %eax
movl %eax, -0x20(%rsp)
jmp 0x68d2
jmp 0x68ca
movl $0x0, -0x64(%rsp)
jmp 0x68d4
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 0x69a9
movq -0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rsp)
movl -0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rsp)
jmp 0x69a9
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 0x69a9
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 0x69a9
movq -0x58(%rsp), %rax
addq $0x2, %rax
movq %rax, -0x58(%rsp)
jmp 0x69a9
movq -0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rsp)
jmp 0x69a9
jmp 0x69a9
jmp 0x69ae
jmp 0x672b
jmp 0x66f3
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 0x66a3
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
nopl (%rax)