// File: /workspace/github_c_makefile_star2_O3/LuaJIT[P]LuaJIT/src/./../dynasm/dasm_x86.h
// Function: dasm_encode
int dasm_encode(Dst_DECL, void *buffer)
{
  dasm_State *D = Dst_REF;
  unsigned char *base = (unsigned char *)buffer;
  unsigned char *cp = base;
  int secnum;

  /* Encode 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->buf;
    int *endb = sec->rbuf + sec->pos;

    while (b != endb) {
      dasm_ActList p = D->actionlist + *b++;
      unsigned char *mark = NULL;
      while (1) {
	int action = *p++;
	int n = (action >= DASM_DISP && action <= DASM_ALIGN) ? *b++ : 0;
	switch (action) {
	case DASM_DISP: if (!mark) mark = cp; {
	  unsigned char *mm = mark;
	  if (*p != DASM_IMM_DB && *p != DASM_IMM_WB) mark = NULL;
	  if (n == 0) { int mrm = mm[-1]&7; if (mrm == 4) mrm = mm[0]&7;
	    if (mrm != 5) { mm[-1] -= 0x80; break; } }
	  if (((n+128) & -256) != 0) goto wd; else mm[-1] -= 0x40;
	}
	  /* fallthrough */
	case DASM_IMM_S: case DASM_IMM_B: wb: dasmb(n); break;
	case DASM_IMM_DB: if (((n+128)&-256) == 0) {
	    db: if (!mark) mark = cp; mark[-2] += 2; mark = NULL; goto wb;
	  } else mark = NULL;
	  /* fallthrough */
	case DASM_IMM_D: wd: dasmd(n); break;
	case DASM_IMM_WB: if (((n+128)&-256) == 0) goto db; else mark = NULL;
	  /* fallthrough */
	case DASM_IMM_W: dasmw(n); break;
	case DASM_VREG: {
	  int t = *p++;
	  unsigned char *ex = cp - (t&7);
	  if ((n & 8) && t < 0xa0) {
	    if (*ex & 0x80) ex[1] ^= 0x20 << (t>>6); else *ex ^= 1 << (t>>6);
	    n &= 7;
	  } else if (n & 0x10) {
	    if (*ex & 0x80) {
	      *ex = 0xc5; ex[1] = (ex[1] & 0x80) | ex[2]; ex += 2;
	    }
	    while (++ex < cp) ex[-1] = *ex;
	    if (mark) mark--;
	    cp--;
	    n &= 7;
	  }
	  if (t >= 0xc0) n <<= 4;
	  else if (t >= 0x40) n <<= 3;
	  else if (n == 4 && t < 0x20) { cp[-1] ^= n; *cp++ = 0x20; }
	  cp[-1] ^= n;
	  break;
	}
	case DASM_REL_LG: p++; if (n >= 0) goto rel_pc;
	  b++; n = (int)(ptrdiff_t)D->globals[-n-10];
	  /* fallthrough */
	case DASM_REL_A: rel_a:
	  n -= (unsigned int)(ptrdiff_t)(cp+4); goto wd; /* !x64 */
	case DASM_REL_PC: rel_pc: {
	  int shrink = *b++;
	  int *pb = DASM_POS2PTR(D, n); if (*pb < 0) { n = pb[1]; goto rel_a; }
	  n = *pb - ((int)(cp-base) + 4-shrink);
	  if (shrink == 0) goto wd;
	  if (shrink == 4) { cp--; cp[-1] = *cp-0x10; } else cp[-1] = 0xeb;
	  goto wb;
	}
	case DASM_IMM_LG:
	  p++;
	  if (n < 0) { dasma((ptrdiff_t)D->globals[-n-10]); break; }
	  /* fallthrough */
	case DASM_IMM_PC: {
	  int *pb = DASM_POS2PTR(D, n);
	  dasma(*pb < 0 ? (ptrdiff_t)pb[1] : (*pb + (ptrdiff_t)base));
	  break;
	}
	case DASM_LABEL_LG: {
	  int idx = *p++;
	  if (idx >= 10)
	    D->globals[idx-10] = (void *)(base + (*p == DASM_SETLABEL ? *b : n));
	  break;
	}
	case DASM_LABEL_PC: case DASM_SETLABEL: break;
	case DASM_SPACE: { int fill = *p++; while (n--) *cp++ = fill; break; }
	case DASM_ALIGN:
	  n = *p++;
	  while (((cp-base) & n)) *cp++ = 0x90; /* nop */
	  break;
	case DASM_EXTERN: n = DASM_EXTERN(Dst, cp, p[1], *p); p += 2; goto wd;
	case DASM_MARK: mark = cp; break;
	case DASM_ESC: action = *p++;
	  /* fallthrough */
	default: *cp++ = action; break;
	case DASM_SECTION: case DASM_STOP: goto stop;
	}
      }
      stop: (void)0;
    }
  }

  if (base + D->codesize != cp)  /* Check for phase errors. */
    return DASM_S_PHASE;
  return DASM_S_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r8
movq (%rdi), %rax
movq %rax, 0x8(%rsp)
movl 0x48(%rax), %eax
movq %rsi, %r15
testl %eax, %eax
jle 0x679a
movq %rdi, %r9
movq 0x8(%rsp), %rcx
leaq 0x50(%rcx), %r10
leaq 0x98(%rdi), %rcx
movq %rcx, 0x40(%rsp)
movl $0x1, %ecx
subq %r8, %rcx
movq %rcx, 0x38(%rsp)
xorl %edx, %edx
leaq 0x5e78(%rip), %r11      # 0xc0d8
movq %r8, %r15
movq %r8, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
movq %r10, 0x10(%rsp)
movq %rdx, 0x28(%rsp)
leaq (%rdx,%rdx,4), %rcx
movq 0x8(%r10,%rcx,8), %r12
movslq 0x18(%r10,%rcx,8), %rdx
shlq $0x2, %rdx
addq (%r10,%rcx,8), %rdx
movq %rdx, 0x30(%rsp)
cmpq %rdx, %r12
je 0x6786
movslq (%r12), %rdx
addq $0x4, %r12
movq 0x8(%rsp), %rax
addq 0x8(%rax), %rdx
xorl %ecx, %ecx
movq %rdx, %rbx
movq %rcx, %rbp
movb (%rdx), %cl
leal 0x17(%rcx), %eax
xorl %r14d, %r14d
cmpb $0x11, %al
ja 0x62c8
movl (%r12), %r14d
addq $0x4, %r12
leaq 0x1(%rbx), %rax
movzbl %cl, %edx
addl $0xffffff17, %edx       # imm = 0xFFFFFF17
cmpl $0x16, %edx
ja 0x65fa
movslq (%r11,%rdx,4), %rsi
addq %r11, %rsi
movq %r15, %rcx
movq %rax, %rdx
jmpq *%rsi
movq %rbp, %rcx
jmp 0x6707
movzbl 0x1(%rbx), %eax
addq $0x2, %rbx
movq %rbp, %rcx
movq %rbx, %rdx
cmpq $0xa, %rax
jb 0x62ae
cmpb $-0xe, (%rbx)
jne 0x6312
movl (%r12), %r14d
movslq %r14d, %rcx
addq %r8, %rcx
movq 0x8(%rsp), %rdx
movq 0x30(%rdx), %rdx
addl $-0xa, %eax
movq %rcx, (%rdx,%rax,8)
jmp 0x675a
addq $0x2, %rbx
testl %r14d, %r14d
js 0x66b0
movq %rbx, %rdx
jmp 0x63ba
movq %rax, %rbx
jmp 0x636d
addq $0x2, %rbx
testl %r14d, %r14d
jns 0x6473
addq $0x4, %r12
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rax
movl $0xfffffff6, %ecx       # imm = 0xFFFFFFF6
subl %r14d, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,8), %r14d
movq %r12, %rdx
jmp 0x661b
movzbl 0x1(%rbx), %r13d
movl %r13d, %eax
andl $0x7, %eax
movq %r15, %rdi
subq %rax, %rdi
testb $0x8, %r14b
je 0x663a
cmpb $-0x61, %r13b
ja 0x663a
movb (%rdi), %al
movl %r13d, %ecx
shrb $0x6, %cl
testb %al, %al
js 0x671d
movb $0x1, %dl
shlb %cl, %dl
xorb %dl, %al
movb %al, (%rdi)
jmp 0x6724
movq %rax, %rdx
movslq %r14d, %rcx
sarl $0x18, %r14d
movslq %r14d, %rax
leaq (%rax,%rax,4), %rax
movq (%r10,%rax,8), %rsi
movslq (%rsi,%rcx,4), %rax
testq %rax, %rax
js 0x6602
addq %r8, %rax
jmp 0x6607
movsbl %r14b, %ecx
cmpl %r14d, %ecx
je 0x65de
xorl %ebp, %ebp
movw %r14w, (%r15)
addq $0x2, %r15
jmp 0x662f
testq %rbp, %rbp
cmoveq %r15, %rbp
movb (%rax), %cl
andb $-0x2, %cl
cmpb $-0x12, %cl
movl $0x0, %ecx
cmoveq %rbp, %rcx
testl %r14d, %r14d
je 0x66d4
movsbl %r14b, %edx
cmpl %r14d, %edx
jne 0x6715
movb -0x1(%rbp), %dl
jmp 0x66f1
movzbl 0x1(%rbx), %eax
addq $0x2, %rbx
movl %r15d, %esi
subl %r8d, %esi
movq %rbp, %rcx
movq %rbx, %rdx
testl %eax, %esi
je 0x62ae
movq 0x38(%rsp), %rcx
addq %r15, %rcx
movq %rcx, %rdx
movb $-0x70, (%r15)
incq %r15
incq %rdx
testl %eax, %ecx
movq %rdx, %rcx
jne 0x645a
jmp 0x675a
movq %rax, %rbx
leaq 0x4(%r12), %rdx
movslq %r14d, %rax
sarl $0x18, %r14d
movslq %r14d, %rcx
leaq (%rcx,%rcx,4), %rcx
movq (%r10,%rcx,8), %rsi
movl (%rsi,%rax,4), %ecx
testl %ecx, %ecx
js 0x6616
movl (%r12), %eax
movl %r8d, %esi
subl %r15d, %esi
addl %ecx, %esi
leal (%rax,%rsi), %r14d
addl $-0x4, %r14d
testl %eax, %eax
je 0x6622
cmpl $0x4, %eax
jne 0x66f9
movb -0x1(%r15), %al
addb $-0x10, %al
movb %al, -0x2(%r15)
decq %r15
jmp 0x66fe
movl 0x44(%r9), %ecx
cmpl $0xc8, %ecx
jge 0x67bd
movzbl (%rax), %r14d
movzbl 0x2(%rbx), %r13d
leaq 0x10c34(%rip), %rax     # 0x17120
movl (%rax,%r13,4), %eax
testl %eax, %eax
jns 0x6556
movl 0x48(%r9), %eax
leaq 0x10c21(%rip), %rcx     # 0x17120
movl %eax, (%rcx,%r13,4)
leaq 0xfe76(%rip), %rax      # 0x16380
movq (%rax,%r13,8), %rdx
movl 0x8(%r9), %edi
leaq 0xbee6(%rip), %rsi      # 0x123ff
callq 0x73c4
leaq 0x5bb3(%rip), %r11      # 0xc0d8
movq 0x10(%rsp), %r10
movq 0x18(%rsp), %r9
movq 0x20(%rsp), %r8
movq 0x60(%r9), %rcx
movslq 0x48(%r9), %rdx
movq %rax, (%rcx,%rdx,8)
leal 0x1(%rdx), %eax
movl %eax, 0x48(%r9)
movl 0x44(%r9), %ecx
leaq 0x10bce(%rip), %rax     # 0x17120
movl (%rax,%r13,4), %eax
movl 0x28(%r9), %edx
movl %r15d, %esi
subl %edx, %esi
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rdx
movq 0x40(%rsp), %rdi
movl %esi, (%rdi,%rdx,4)
movl %eax, 0x4(%rdi,%rdx,4)
movl %r14d, 0x8(%rdi,%rdx,4)
incl %ecx
movl %ecx, 0x44(%r9)
addq $0x3, %rbx
xorl %r14d, %r14d
movq %rbx, %rax
jmp 0x6628
addq $0x2, %rbx
movq %rbp, %rcx
movq %rbx, %rdx
testl %r14d, %r14d
je 0x62ae
movl %r14d, %edx
movzbl (%rax), %esi
movq %r15, %rdi
callq 0x50c0
leaq 0x5b24(%rip), %r11      # 0xc0d8
movq 0x10(%rsp), %r10
movq 0x18(%rsp), %r9
movq 0x20(%rsp), %r8
decl %r14d
addq %r14, %r15
incq %r15
jmp 0x675a
movsbl %r14b, %ecx
cmpl %r14d, %ecx
jne 0x66a9
testq %rbp, %rbp
cmoveq %r15, %rbp
addb $0x2, -0x2(%rbp)
xorl %ecx, %ecx
jmp 0x6707
movb 0x1(%rbx), %cl
addq $0x2, %rbx
movq %rbx, %rax
movb %cl, (%r15)
incq %r15
jmp 0x662f
movslq 0x4(%rsi,%rcx,4), %rax
movq %rax, (%r15)
addq $0x8, %r15
movq %rbp, %rcx
jmp 0x62ae
movl 0x4(%rsi,%rax,4), %r14d
subl %r15d, %r14d
addl $-0x4, %r14d
movq %rbx, %rax
movq %rdx, %r12
movl %r14d, (%r15)
addq $0x4, %r15
movq %rbp, %rcx
movq %rax, %rdx
jmp 0x62ae
testb $0x10, %r14b
je 0x6696
cmpb $0x0, (%rdi)
jns 0x6657
movb $-0x3b, (%rdi)
movb 0x1(%rdi), %al
andb $-0x80, %al
orb 0x2(%rdi), %al
movb %al, 0x1(%rdi)
addq $0x2, %rdi
leaq 0x1(%rdi), %rsi
cmpq %r15, %rsi
jae 0x6684
movq %rdi, %rdx
notq %rdx
addq %r15, %rdx
callq 0x5180
leaq 0x5a63(%rip), %r11      # 0xc0d8
movq 0x10(%rsp), %r10
movq 0x18(%rsp), %r9
movq 0x20(%rsp), %r8
leaq -0x1(%rbp), %rax
testq %rbp, %rbp
cmovneq %rax, %rbp
decq %r15
andl $0x7, %r14d
cmpb $-0x40, %r13b
jb 0x6728
shll $0x4, %r14d
jmp 0x6752
xorl %ebp, %ebp
jmp 0x6628
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rax
movl $0xfffffff6, %ecx       # imm = 0xFFFFFFF6
subl %r14d, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, (%r15)
addq $0x8, %r15
jmp 0x675a
movb -0x1(%rbp), %dl
movl %edx, %esi
andb $0x7, %sil
cmpb $0x4, %sil
jne 0x66eb
movb (%rbp), %sil
andb $0x7, %sil
cmpb $0x5, %sil
jne 0x6765
addb $-0x40, %dl
movb %dl, -0x1(%rbp)
jmp 0x6707
movb $-0x15, -0x1(%r15)
movq %rbp, %rcx
movq %rbx, %rax
movq %rdx, %r12
movb %r14b, (%r15)
incq %r15
movq %rax, %rdx
jmp 0x62ae
movq %rcx, %rbp
jmp 0x6628
movb $0x20, %al
shlb %cl, %al
xorb %al, 0x1(%rdi)
andl $0x7, %r14d
cmpb $0x40, %r13b
jb 0x6734
shll $0x3, %r14d
jmp 0x6752
cmpl $0x4, %r14d
jne 0x6752
cmpb $0x1f, %r13b
ja 0x6752
xorb $0x4, -0x1(%r15)
movb $0x20, (%r15)
incq %r15
movl $0x4, %r14d
xorb %r14b, -0x1(%r15)
addq $0x2, %rbx
movq %rbp, %rcx
movq %rbx, %rdx
jmp 0x62ae
addb $-0x80, %dl
movb %dl, -0x1(%rbp)
movq %rax, %rdx
jmp 0x62ae
cmpq 0x30(%rsp), %r12
jne 0x629b
movq 0x8(%rsp), %rax
movl 0x48(%rax), %eax
movq 0x28(%rsp), %rdx
incq %rdx
movslq %eax, %rcx
cmpq %rcx, %rdx
jl 0x6272
movq 0x8(%rsp), %rax
addq 0x40(%rax), %r8
xorl %eax, %eax
cmpq %r15, %r8
setne %al
shll $0x19, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5210