// File: /workspace/github_c_makefile_star2_O3/42Bastian[P]lyxass/mnemonics.c
// Function: op3
int op3(int op)
{
  int err;
  int32_t l;
  int komma = 0;
  int saveCYCLES;
  int saveOp;

  if ( ! KillSpace() ){
    return Error(SYNTAX_ERR,"");
  }

  // immediate

  if ( TestAtom('#') ){

    if ( (err = Expression(&l)) == EXPR_ERR) return 1;

    if ( l < -128 || l > 255 ) return Error(BYTE_ERR,"");
    if ( op == 0x81 ) return Error(SYNTAX_ERR,""); // STA #0 not possible
    writeConstByte(op | 0x08);
    if ( Current.needsReloc ){
      writeRelocByte((char)l,RELOC_LOBY);
    } else {
      writeConstByte((char)l);
    }
    if ( err == EXPR_UNSOLVED ) saveCurrentLine();

    CYCLES += 2;

    if ( (Global.pc & 255) == 1) ++CYCLES;

    return 0;
  }

  // indirect

  SavePosition();
  saveCYCLES = CYCLES;
  saveOp = op;
  if ( TestAtom('(') ){

    if ( (err = Expression(&l)) == EXPR_ERR) return 1;
    if ( l < 0 || l > 255 ) return Error(BYTE_ERR,"");

    if ( TestAtom(',') ){
      if ( !TestAtomOR('x','X') ) return Error(SYNTAX_ERR,"");
      komma = 1;
      CYCLES += 6;
    }
    if ( !TestAtom(')') ) return Error(SYNTAX_ERR,"Missing ')'");

    if ( !komma ) {
      if ( TestAtom(',') ){
	CYCLES += 5;
	if ( !TestAtomOR('y','Y') ) return Error(SYNTAX_ERR,"");
	op |= 0x10;
      } else {
	op |= 0x12;
	--op;
	CYCLES++;
      }
    }
    KillSpace();
    if ( atom == 0 ){
      if ( op == 0x91 ) ++CYCLES;
      writeConstByte(op);
      writeByte((char)l);
      if ( err == EXPR_UNSOLVED ) saveCurrentLine();
      return 0;
    } else {
      // Possible not indirect but expression with braces
      RestorePosition();
      op = saveOp;
      CYCLES = saveCYCLES;
    }
  }

  // absolute

  if ( (err = Expression(&l)) == EXPR_ERR) return 1;

  if ( TestAtom(',') ){
    CYCLES += 4;

    if ( TestAtomOR('X','x') ){
      op |= 0x14;
    } else if ( TestAtomOR('Y','y') ) {
      op |= 0x18;
      writeConstByte(op);
      writeWordLittle((short)l);
      if ( err == EXPR_UNSOLVED ) saveCurrentLine();
      return 0;
    } else return Error(SYNTAX_ERR,"");
  } else {
    op |= 0x04;
  }

  if ( l < 0 || l > 65535 ) Error(WORD_ERR,"");

  if ( l > 255 || err == EXPR_UNSOLVED || Current.pass2) {
    CYCLES+=4;
    op |= 0x08;
    writeConstByte(op);
    writeWordLittle((short)l);
  } else {
    CYCLES+=3;
    writeConstByte(op);
    writeByte((char)l);
  }
  if ( op == 0x99 || op == 0x9d ) ++CYCLES;

  if ( err == EXPR_UNSOLVED ) saveCurrentLine();
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %edi, %ebx
xorl %eax, %eax
callq 0x4ff7
testl %eax, %eax
je 0x818c
movl $0x23, %edi
callq 0x4fa8
testl %eax, %eax
je 0x81a9
leaq 0xc(%rsp), %rdi
callq 0x9d6c
movl $0x1, %r14d
cmpl $0x11, %eax
je 0x8200
movl %eax, %ebp
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
addl 0xc(%rsp), %eax
cmpl $0xfffffe7f, %eax       # imm = 0xFFFFFE7F
jbe 0x81ec
cmpl $0x81, %ebx
jne 0x8210
leaq 0x4e0d(%rip), %rsi      # 0xcf92
movl $0x12, %edi
jmp 0x81f8
leaq 0x4dff(%rip), %rsi      # 0xcf92
movl $0x12, %edi
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xa1d8
callq 0x4f58
leaq 0xc623(%rip), %r15      # 0x147d8
movq (%r15), %rax
movl (%rax), %r12d
movl $0x28, %edi
callq 0x4fa8
testl %eax, %eax
je 0x8343
leaq 0xc(%rsp), %rdi
callq 0x9d6c
movl $0x1, %r14d
cmpl $0x11, %eax
je 0x8200
cmpl $0x100, 0xc(%rsp)       # imm = 0x100
jb 0x823e
leaq 0x4d9f(%rip), %rsi      # 0xcf92
movl $0x1a, %edi
callq 0xa1d8
movl %eax, %r14d
movl %r14d, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
orb $0x8, %bl
movsbl %bl, %edi
callq 0x3355
leaq 0xc3e6(%rip), %rax      # 0x14608
cmpl $0x0, 0x1bc(%rax)
movb 0xc(%rsp), %al
movsbl %al, %edi
je 0x8285
movl $0x2, %esi
callq 0x33b0
jmp 0x828a
movl %eax, %ebp
movl $0x2c, %edi
callq 0x4fa8
testl %eax, %eax
je 0x82c4
movl $0x78, %edi
movl $0x58, %esi
callq 0x504d
testl %eax, %eax
je 0x817e
movq (%r15), %rax
addl $0x6, (%rax)
movl $0x29, %edi
callq 0x4fa8
movl %ebx, %r14d
testl %eax, %eax
jne 0x8321
jmp 0x8306
callq 0x3355
cmpl $0x2, %ebp
jne 0x8296
xorl %eax, %eax
callq 0xa118
leaq 0xc53b(%rip), %rax      # 0x147d8
movq (%rax), %rax
movl (%rax), %ecx
leal 0x2(%rcx), %edx
movl %edx, (%rax)
leaq 0xc102(%rip), %rdx      # 0x143b0
xorl %r14d, %r14d
cmpb $0x1, (%rdx)
jne 0x8200
addl $0x3, %ecx
movl %ecx, (%rax)
jmp 0x8200
movl $0x29, %edi
callq 0x4fa8
testl %eax, %eax
je 0x8306
movl $0x2c, %edi
callq 0x4fa8
testl %eax, %eax
je 0x8312
movq (%r15), %rax
addl $0x5, (%rax)
movl $0x79, %edi
movl $0x59, %esi
callq 0x504d
testl %eax, %eax
je 0x817e
movl %ebx, %r14d
orl $0x10, %r14d
jmp 0x8321
leaq 0x5153(%rip), %rsi      # 0xd460
jmp 0x8185
movl %ebx, %r14d
orl $0x12, %r14d
decl %r14d
movq (%r15), %rax
incl (%rax)
xorl %eax, %eax
callq 0x4ff7
leaq 0x14c01(%rip), %rax     # 0x1cf30
cmpl $0x0, (%rax)
je 0x844e
callq 0x4f6a
movq (%r15), %rax
movl %r12d, (%rax)
leaq 0xc(%rsp), %rdi
callq 0x9d6c
movl $0x1, %r14d
cmpl $0x11, %eax
je 0x8200
movl %eax, %ebp
movl $0x2c, %edi
callq 0x4fa8
testl %eax, %eax
je 0x83bc
movq (%r15), %rax
addl $0x4, (%rax)
movl $0x58, %edi
movl $0x78, %esi
callq 0x504d
movl $0x14, %r14d
testl %eax, %eax
jne 0x83c2
movl $0x59, %edi
movl $0x79, %esi
callq 0x504d
testl %eax, %eax
je 0x817e
orb $0x18, %bl
movsbl %bl, %edi
callq 0x3355
movswl 0xc(%rsp), %edi
callq 0x355d
jmp 0x846f
movl $0x4, %r14d
movl 0xc(%rsp), %edx
cmpl $0x10000, %edx          # imm = 0x10000
jb 0x83e3
leaq 0x4bbd(%rip), %rsi      # 0xcf92
movl $0x1b, %edi
callq 0xa1d8
movl 0xc(%rsp), %edx
orl %ebx, %r14d
movq (%r15), %rax
movl (%rax), %ecx
cmpl $0x2, %ebp
je 0x8422
cmpl $0xff, %edx
jg 0x8422
leaq 0xc209(%rip), %rdx      # 0x14608
cmpl $0x0, 0xe4(%rdx)
jne 0x8422
addl $0x3, %ecx
movl %ecx, (%rax)
movsbl %r14b, %edi
callq 0x3355
movsbl 0xc(%rsp), %edi
callq 0x340b
jmp 0x843e
addl $0x4, %ecx
movl %ecx, (%rax)
orl $0x8, %r14d
movsbl %r14b, %edi
callq 0x3355
movswl 0xc(%rsp), %edi
callq 0x355d
cmpl $0x9d, %r14d
jne 0x846f
movq (%r15), %rax
incl (%rax)
jmp 0x846f
cmpl $0x91, %r14d
jne 0x845c
movq (%r15), %rax
incl (%rax)
movsbl %r14b, %edi
callq 0x3355
movsbl 0xc(%rsp), %edi
callq 0x340b
xorl %r14d, %r14d
cmpl $0x2, %ebp
jne 0x8200
xorl %eax, %eax
callq 0xa118
jmp 0x8200