// File: /workspace/github_c_makefile_star2_O1/katlogic[P]ljx/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;
	}
	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;
	case DASM_IMM_D: wd: dasmd(n); break;
	case DASM_IMM_WB: if (((n+128)&-256) == 0) goto db; else mark = NULL;
	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];
	case DASM_REL_A: rel_a: n -= (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) { n = (int)(ptrdiff_t)D->globals[-n]; goto wd; }
	case DASM_IMM_PC: {
	  int *pb = DASM_POS2PTR(D, n);
	  n = *pb < 0 ? pb[1] : (*pb + (int)(ptrdiff_t)base);
	  goto wd;
	}
	case DASM_LABEL_LG: {
	  int idx = *p++;
	  if (idx >= 10)
	    D->globals[idx] = (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++;
	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)
cmpl $0x0, 0x48(%rax)
movq %rsi, %r15
jle 0x67e2
movq %rdi, %r9
movq 0x8(%rsp), %rax
leaq 0x50(%rax), %r10
leaq 0x98(%rdi), %rax
movq %rax, 0x40(%rsp)
movl $0x1, %eax
subq %r8, %rax
movq %rax, 0x30(%rsp)
xorl %ecx, %ecx
leaq 0x5dfa(%rip), %r11      # 0xc0d8
leaq 0x10e3b(%rip), %rdi     # 0x17120
movq %r8, %r15
movq %r8, 0x20(%rsp)
movq %r9, 0x18(%rsp)
movq %r10, 0x10(%rsp)
movq %rcx, 0x28(%rsp)
leaq (%rcx,%rcx,4), %rax
movq 0x8(%r10,%rax,8), %r12
movslq 0x18(%r10,%rax,8), %rcx
shlq $0x2, %rcx
addq (%r10,%rax,8), %rcx
movq %rcx, 0x38(%rsp)
cmpq %rcx, %r12
je 0x67c8
movslq (%r12), %r14
addq $0x4, %r12
movq 0x8(%rsp), %rax
addq 0x8(%rax), %r14
xorl %ebp, %ebp
movb (%r14), %cl
leal 0x17(%rcx), %eax
xorl %ebx, %ebx
cmpb $0x11, %al
ja 0x6347
movl (%r12), %ebx
addq $0x4, %r12
leaq 0x1(%r14), %rax
movzbl %cl, %edx
addl $0xffffff17, %edx       # imm = 0xFFFFFF17
cmpl $0x16, %edx
ja 0x662e
movslq (%r11,%rdx,4), %rcx
addq %r11, %rcx
jmpq *%rcx
movl $0x1d, %edx
jmp 0x67ac
movsbl %bl, %ecx
cmpl %ebx, %ecx
je 0x65d0
xorl %ebp, %ebp
jmp 0x674e
addq $0x2, %r14
testl %ebx, %ebx
js 0x66f1
movq %r14, %rax
movslq %ebx, %rcx
sarl $0x18, %ebx
movslq %ebx, %rdx
leaq (%rdx,%rdx,4), %rdx
movq (%r10,%rdx,8), %rdx
movl (%rdx,%rcx,4), %ebx
testl %ebx, %ebx
js 0x667c
addl %r8d, %ebx
jmp 0x674e
addq $0x2, %r14
testl %ebx, %ebx
je 0x67a7
movl %ebx, %edx
movzbl (%rax), %esi
movq %r15, %rdi
callq 0x50c0
leaq 0x10d4b(%rip), %rdi     # 0x17120
leaq 0x5cfc(%rip), %r11      # 0xc0d8
movq 0x10(%rsp), %r10
movq 0x18(%rsp), %r9
movq 0x20(%rsp), %r8
decl %ebx
addq %rbx, %r15
incq %r15
jmp 0x67a7
testq %rbp, %rbp
cmoveq %r15, %rbp
movb (%rax), %cl
andb $-0x2, %cl
cmpb $-0x12, %cl
movl $0x0, %ecx
cmoveq %rbp, %rcx
testl %ebx, %ebx
jne 0x644e
movb -0x1(%rbp), %dil
movl %edi, %esi
andb $0x7, %sil
cmpb $0x4, %sil
jne 0x642c
movb (%rbp), %sil
andb $0x7, %sil
xorl %edx, %edx
cmpb $0x5, %sil
je 0x6441
addb $-0x80, %dil
movb %dil, -0x1(%rbp)
movl $0x9, %edx
cmpb $0x5, %sil
leaq 0x10cd4(%rip), %rdi     # 0x17120
jne 0x6460
movsbl %bl, %esi
movl $0xa, %edx
cmpl %ebx, %esi
jne 0x6460
addb $-0x40, -0x1(%rbp)
xorl %edx, %edx
cmpl $0xa, %edx
je 0x6757
cmpl $0x9, %edx
je 0x673d
testl %edx, %edx
je 0x6737
jmp 0x67af
addq $0x2, %r14
testl %ebx, %ebx
js 0x6701
movq %r14, %rax
movslq %ebx, %rcx
sarl $0x18, %ebx
movslq %ebx, %rdx
leaq (%rdx,%rdx,4), %rdx
movq (%r10,%rdx,8), %rsi
movl (%rsi,%rcx,4), %edx
testl %edx, %edx
js 0x666e
movl (%r12), %ecx
movl %r8d, %esi
subl %r15d, %esi
addl %edx, %esi
leal (%rcx,%rsi), %ebx
addl $-0x4, %ebx
testl %ecx, %ecx
je 0x6715
cmpl $0x4, %ecx
jne 0x671c
movb -0x1(%r15), %cl
addb $-0x10, %cl
movb %cl, -0x2(%r15)
decq %r15
jmp 0x6721
movzbl 0x1(%r14), %eax
addq $0x2, %r14
movl %r15d, %ecx
subl %r8d, %ecx
testl %eax, %ecx
je 0x67a7
movq 0x30(%rsp), %rcx
addq %r15, %rcx
movq %rcx, %rdx
movb $-0x70, (%r15)
incq %r15
incq %rdx
testl %eax, %ecx
movq %rdx, %rcx
jne 0x6502
jmp 0x67a7
movq %r15, %rbp
jmp 0x67aa
cmpl $0xc8, 0x44(%r9)
jge 0x6805
movzbl (%rax), %ebx
movzbl 0x2(%r14), %r13d
cmpl $0x0, (%rdi,%r13,4)
jns 0x658f
movl 0x48(%r9), %eax
movl %eax, (%rdi,%r13,4)
leaq 0xfe54(%rip), %rax      # 0x163a0
movq (%rax,%r13,8), %rdx
movq %r9, %rdi
leaq 0xb6b5(%rip), %rsi      # 0x11c0f
callq 0x7409
leaq 0x10bba(%rip), %rdi     # 0x17120
leaq 0x5b6b(%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 0x28(%r9), %eax
movl %r15d, %ecx
subl %eax, %ecx
movslq 0x44(%r9), %rax
leaq (%rax,%rax,2), %rdx
movq 0x40(%rsp), %rsi
movl %ecx, (%rsi,%rdx,4)
movl (%rdi,%r13,4), %ecx
movl %ecx, 0x4(%rsi,%rdx,4)
movl %ebx, 0x8(%rsi,%rdx,4)
incl %eax
movl %eax, 0x44(%r9)
addq $0x3, %r14
xorl %ebx, %ebx
jmp 0x674b
movsbl %bl, %ecx
cmpl %ebx, %ecx
jne 0x6685
testq %rbp, %rbp
cmoveq %r15, %rbp
addb $0x2, -0x2(%rbp)
xorl %ecx, %ecx
jmp 0x6737
movzbl 0x1(%r14), %r13d
movl %r13d, %eax
andl $0x7, %eax
movq %r15, %rdi
subq %rax, %rdi
testb $0x8, %bl
je 0x6694
cmpb $-0x61, %r13b
ja 0x6694
movb (%rdi), %al
movl %r13d, %ecx
shrb $0x6, %cl
testb %al, %al
js 0x675c
movb $0x1, %dl
shlb %cl, %dl
xorb %dl, %al
movb %al, (%rdi)
jmp 0x6763
movb 0x1(%r14), %cl
addq $0x2, %r14
movq %r14, %rax
movb %cl, (%r15)
incq %r15
jmp 0x67aa
movzbl 0x1(%r14), %eax
addq $0x2, %r14
cmpq $0xa, %rax
jb 0x67a7
cmpb $-0xe, (%r14)
jne 0x6656
movl (%r12), %ebx
movslq %ebx, %rcx
addq %r8, %rcx
movq 0x8(%rsp), %rdx
movq 0x30(%rdx), %rdx
movq %rcx, (%rdx,%rax,8)
jmp 0x67a7
movl 0x4(%rsi,%rcx,4), %ebx
movl $0x18, %ecx
jmp 0x6726
movl 0x4(%rdx,%rcx,4), %ebx
jmp 0x674e
xorl %ebp, %ebp
movw %bx, (%r15)
addq $0x2, %r15
jmp 0x67aa
testb $0x10, %bl
je 0x6766
cmpb $0x0, (%rdi)
jns 0x66b4
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 0x66e1
movq %rdi, %rdx
notq %rdx
addq %r15, %rdx
callq 0x5170
leaq 0x5a06(%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
jmp 0x6763
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rax
negl %ebx
movl (%rax,%rbx,8), %ebx
jmp 0x674b
addq $0x4, %r12
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rax
negl %ebx
movl (%rax,%rbx,8), %ebx
jmp 0x6745
movl $0xa, %ecx
jmp 0x6726
movb $-0x15, -0x1(%r15)
movl $0xb, %ecx
addq $0x4, %r12
cmpl $0xa, %ecx
je 0x674e
cmpl $0xb, %ecx
jne 0x6742
movq %rbp, %rcx
movb %bl, (%r15)
incq %r15
movq %rcx, %rbp
jmp 0x67aa
movq %rax, %r14
subl %r15d, %ebx
addl $-0x4, %ebx
movq %r14, %rax
movl %ebx, (%r15)
addq $0x4, %r15
jmp 0x67aa
movq %rcx, %rbp
jmp 0x674e
movb $0x20, %al
shlb %cl, %al
xorb %al, 0x1(%rdi)
andl $0x7, %ebx
leaq 0x109b3(%rip), %rdi     # 0x17120
cmpb $-0x40, %r13b
jb 0x6778
shll $0x4, %ebx
jmp 0x679f
cmpb $0x40, %r13b
jb 0x6783
shll $0x3, %ebx
jmp 0x679f
cmpl $0x4, %ebx
jne 0x679f
cmpb $0x1f, %r13b
ja 0x679f
xorb $0x4, -0x1(%r15)
movb $0x20, (%r15)
incq %r15
movl $0x4, %ebx
addq $0x2, %r14
xorb %bl, -0x1(%r15)
movq %r14, %rax
xorl %edx, %edx
movq %rbp, %rcx
movq %rcx, %rbp
movq %rax, %r14
testl %edx, %edx
je 0x6333
cmpq 0x38(%rsp), %r12
jne 0x6320
movq 0x28(%rsp), %rcx
incq %rcx
movq 0x8(%rsp), %rax
movslq 0x48(%rax), %rax
cmpq %rax, %rcx
jl 0x62f7
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 0x5200