// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq (%rdi), %rax
movq %rax, (%rsp)
addq $0x50, %rax
movq %rax, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
leaq 0x98(%rdi), %rax
movq %rax, 0x30(%rsp)
movq %rsi, %rax
negq %rax
movq %rax, 0x40(%rsp)
xorl %ecx, %ecx
leaq 0x53bf(%rip), %r9       # 0xb0d8
movq %rsi, %r12
movq %rsi, 0x38(%rsp)
movq (%rsp), %rax
movslq 0x48(%rax), %rax
cmpq %rax, %rcx
jge 0x61d3
movq %rcx, 0x20(%rsp)
imulq $0x28, %rcx, %rax
movq 0x10(%rsp), %rcx
movq 0x8(%rcx,%rax), %rbx
movslq 0x18(%rcx,%rax), %rdx
shlq $0x2, %rdx
addq (%rcx,%rax), %rdx
movq %rdx, 0x28(%rsp)
cmpq 0x28(%rsp), %rbx
je 0x61c6
movslq (%rbx), %r14
addq $0x4, %rbx
movq (%rsp), %rax
addq 0x8(%rax), %r14
xorl %ecx, %ecx
movq %r14, %rbp
movq %rcx, %r15
movb (%r14), %cl
leal 0x17(%rcx), %edx
xorl %eax, %eax
cmpb $0x11, %dl
ja 0x5d8c
movl (%rbx), %eax
addq $0x4, %rbx
leaq 0x1(%rbp), %r14
movzbl %cl, %edx
addl $0xffffff17, %edx       # imm = 0xFFFFFF17
cmpl $0x16, %edx
ja 0x6066
movslq (%r9,%rdx,4), %rdx
addq %r9, %rdx
movslq %eax, %rdi
movq %r12, %rcx
jmpq *%rdx
movq %r15, %rcx
jmp 0x6160
movzbl 0x1(%rbp), %edx
addq $0x2, %rbp
movq %r15, %rcx
movq %rbp, %r14
cmpq $0xa, %rdx
jb 0x5d73
cmpb $-0xe, (%rbp)
jne 0x5dd5
movl (%rbx), %eax
cltq
addq %r13, %rax
movq (%rsp), %rcx
movq 0x30(%rcx), %rcx
addl $-0xa, %edx
movq %rax, (%rcx,%rdx,8)
jmp 0x61af
movq %r14, %rbp
jmp 0x5e16
addq $0x2, %rbp
testl %eax, %eax
jns 0x5f0b
addq $0x4, %rbx
movq (%rsp), %rcx
movq 0x30(%rcx), %rcx
pushq $-0xa
popq %rdx
subl %eax, %edx
movslq %edx, %rax
movl (%rcx,%rax,8), %eax
movq %rbx, %rdx
jmp 0x6092
movzbl 0x1(%rbp), %edx
movl %edx, %ecx
andl $0x7, %ecx
movq %r12, %rsi
subq %rcx, %rsi
testb $0x8, %al
je 0x60ae
cmpb $-0x61, %dl
ja 0x60ae
movb (%rsi), %dil
movl %edx, %ecx
shrb $0x6, %cl
testb %dil, %dil
js 0x6174
movb $0x1, %r8b
shlb %cl, %r8b
xorb %r8b, %dil
movb %dil, (%rsi)
jmp 0x617e
addq $0x2, %rbp
testl %eax, %eax
js 0x6100
movq %rbp, %r14
sarl $0x18, %eax
cltq
imulq $0x28, %rax, %rax
movq 0x10(%rsp), %rcx
movq (%rcx,%rax), %rax
movslq (%rax,%rdi,4), %rsi
testq %rsi, %rsi
js 0x606f
addq %r13, %rsi
jmp 0x6074
movsbl %al, %ecx
cmpl %eax, %ecx
je 0x6049
xorl %r15d, %r15d
movw %ax, (%r12)
addq $0x2, %r12
jmp 0x60a6
testq %r15, %r15
cmoveq %r12, %r15
movb (%r14), %cl
andb $-0x2, %cl
cmpb $-0x12, %cl
movl $0x0, %ecx
cmoveq %r15, %rcx
testl %eax, %eax
je 0x612b
movsbl %al, %edx
cmpl %eax, %edx
jne 0x616c
movb -0x1(%r15), %dl
jmp 0x6148
movzbl (%r14), %eax
movq 0x40(%rsp), %rcx
addq %r12, %rcx
testl %eax, %ecx
je 0x61ab
movb $-0x70, (%r12)
incq %r12
incq %rcx
jmp 0x5ef3
movq %r14, %rbp
leaq 0x4(%rbx), %rdx
sarl $0x18, %eax
cltq
imulq $0x28, %rax, %rax
movq 0x10(%rsp), %rcx
movq (%rcx,%rax), %rcx
movl (%rcx,%rdi,4), %eax
testl %eax, %eax
js 0x608e
movl (%rbx), %ecx
movl %r13d, %esi
subl %r12d, %esi
addl %eax, %esi
leal (%rcx,%rsi), %eax
addl $-0x4, %eax
testl %ecx, %ecx
je 0x6098
cmpl $0x4, %ecx
jne 0x6151
movb -0x1(%r12), %cl
addb $-0x10, %cl
movb %cl, -0x2(%r12)
decq %r12
jmp 0x6157
movq 0x8(%rsp), %rax
movl 0x44(%rax), %eax
cmpl $0xc8, %eax
jge 0x61f5
movzbl (%r14), %r10d
movzbl 0x2(%rbp), %r13d
leaq 0x1119b(%rip), %rcx     # 0x17120
movl (%rcx,%r13,4), %ecx
testl %ecx, %ecx
jns 0x5fee
movq 0x8(%rsp), %r14
movl 0x48(%r14), %eax
leaq 0x11183(%rip), %rcx     # 0x17120
movl %eax, (%rcx,%r13,4)
leaq 0x103d8(%rip), %rax     # 0x16380
movq (%rax,%r13,8), %rdx
movq %r14, %rdi
leaq 0xb449(%rip), %rsi      # 0x113ff
movl %r10d, 0x1c(%rsp)
callq 0x6d95
movl 0x1c(%rsp), %r10d
leaq 0x510c(%rip), %r9       # 0xb0d8
movq 0x60(%r14), %rcx
movslq 0x48(%r14), %rdx
movq %rax, (%rcx,%rdx,8)
leal 0x1(%rdx), %eax
movl %eax, 0x48(%r14)
movl 0x44(%r14), %eax
leaq 0x11136(%rip), %rcx     # 0x17120
movl (%rcx,%r13,4), %ecx
movq 0x8(%rsp), %rdi
movl 0x28(%rdi), %edx
movl %r12d, %esi
subl %edx, %esi
cltq
imulq $0xc, %rax, %rdx
movq 0x30(%rsp), %r8
movl %esi, (%r8,%rdx)
movl %ecx, 0x4(%r8,%rdx)
movl %r10d, 0x8(%r8,%rdx)
incl %eax
movl %eax, 0x44(%rdi)
addq $0x3, %rbp
xorl %eax, %eax
movq %rbp, %r14
movq 0x38(%rsp), %r13
jmp 0x609e
movb (%r14), %cl
subl $0x1, %eax
jb 0x61ab
movb %cl, (%r12)
incq %r12
jmp 0x602c
movsbl %al, %ecx
cmpl %eax, %ecx
jne 0x60fb
testq %r15, %r15
cmoveq %r12, %r15
addb $0x2, -0x2(%r15)
xorl %ecx, %ecx
jmp 0x6160
movb 0x1(%rbp), %cl
addq $0x2, %rbp
movq %rbp, %r14
movb %cl, (%r12)
incq %r12
jmp 0x60a6
movslq 0x4(%rax,%rdi,4), %rsi
movq %r12, %rdi
callq 0x6219
movq %rax, %r12
movq %r15, %rcx
leaq 0x504f(%rip), %r9       # 0xb0d8
jmp 0x5d73
movl 0x4(%rcx,%rdi,4), %eax
subl %r12d, %eax
addl $-0x4, %eax
movq %rbp, %r14
movq %rdx, %rbx
movl %eax, (%r12)
addq $0x4, %r12
movq %r15, %rcx
jmp 0x5d73
testb $0x10, %al
je 0x60ea
cmpb $0x0, (%rsi)
jns 0x60d1
movb $-0x3b, (%rsi)
movb 0x1(%rsi), %cl
andb $-0x80, %cl
orb 0x2(%rsi), %cl
movb %cl, 0x1(%rsi)
addq $0x2, %rsi
jmp 0x60d1
movb (%rsi), %cl
movb %cl, -0x1(%rsi)
incq %rsi
cmpq %r12, %rsi
jb 0x60cc
leaq -0x1(%r15), %rcx
testq %r15, %r15
cmovneq %rcx, %r15
decq %r12
andl $0x7, %eax
cmpb $-0x40, %dl
jb 0x6181
shll $0x4, %eax
jmp 0x61a6
xorl %r15d, %r15d
jmp 0x609e
movq (%rsp), %rcx
movq 0x30(%rcx), %rcx
pushq $-0xa
popq %rdx
subl %eax, %edx
movslq %edx, %rax
movq (%rcx,%rax,8), %rsi
movq %r12, %rdi
callq 0x6219
leaq 0x4fb5(%rip), %r9       # 0xb0d8
movq %rax, %r12
jmp 0x61af
movb -0x1(%r15), %dl
movl %edx, %esi
andb $0x7, %sil
cmpb $0x4, %sil
jne 0x6142
movb (%r15), %sil
andb $0x7, %sil
cmpb $0x5, %sil
jne 0x61ba
addb $-0x40, %dl
movb %dl, -0x1(%r15)
jmp 0x6160
movb $-0x15, -0x1(%r12)
movq %r15, %rcx
movq %rbp, %r14
movq %rdx, %rbx
movb %al, (%r12)
incq %r12
jmp 0x5d73
movq %rcx, %r15
jmp 0x609e
movb $0x20, %dil
shlb %cl, %dil
xorb %dil, 0x1(%rsi)
andl $0x7, %eax
cmpb $0x40, %dl
jb 0x618b
shll $0x3, %eax
jmp 0x61a6
cmpl $0x4, %eax
jne 0x61a6
cmpb $0x1f, %dl
ja 0x61a6
xorb $0x4, -0x1(%r12)
movb $0x20, (%r12)
incq %r12
pushq $0x4
popq %rax
xorb %al, -0x1(%r12)
addq $0x2, %rbp
movq %r15, %rcx
movq %rbp, %r14
jmp 0x5d73
addb $-0x80, %dl
movb %dl, -0x1(%r15)
jmp 0x5d73
movq 0x20(%rsp), %rcx
incq %rcx
jmp 0x5d21
movq (%rsp), %rax
addq 0x40(%rax), %r13
xorl %eax, %eax
cmpq %r12, %r13
setne %al
shll $0x19, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10dfc(%rip), %rax     # 0x16ff8
movq (%rax), %rcx
leaq 0x9b45(%rip), %rdi      # 0xfd4b
pushq $0x37
popq %rsi
pushq $0x1
popq %rdx
callq 0x51d0
pushq $0x1
popq %rdi
callq 0x51c0