// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebx
xorl %eax, %eax
callq 0x4dc3
testl %eax, %eax
je 0x7880
pushq $0x23
popq %rdi
callq 0x4da7
pushq $0x1
popq %rbp
testl %eax, %eax
je 0x789d
leaq 0x4(%rsp), %rdi
callq 0x929a
cmpl $0x11, %eax
je 0x78ea
movl %eax, %r14d
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
addl 0x4(%rsp), %eax
cmpl $0xfffffe7f, %eax       # imm = 0xFFFFFE7F
jbe 0x78d9
cmpl $0x81, %ebx
jne 0x78fb
leaq 0x4716(%rip), %rsi      # 0xbf92
pushq $0x12
jmp 0x78e2
leaq 0x470b(%rip), %rsi      # 0xbf92
pushq $0x12
popq %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x96cc
callq 0x4d82
leaq 0xcf2f(%rip), %r12      # 0x147d8
movq (%r12), %rax
movl (%rax), %r13d
pushq $0x28
popq %rdi
callq 0x4da7
testl %eax, %eax
je 0x799b
leaq 0x4(%rsp), %rdi
callq 0x929a
cmpl $0x11, %eax
je 0x78ea
cmpl $0x100, 0x4(%rsp)       # imm = 0x100
jb 0x792e
leaq 0x46b2(%rip), %rsi      # 0xbf92
pushq $0x1a
popq %rdi
callq 0x96cc
movl %eax, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
orb $0x8, %bl
movsbl %bl, %edi
callq 0x3323
leaq 0xccfb(%rip), %rax      # 0x14608
cmpl $0x0, 0x1bc(%rax)
movb 0x4(%rsp), %al
movsbl %al, %edi
je 0x7a6f
pushq $0x2
popq %rsi
callq 0x3379
jmp 0x7a74
movl %eax, %r14d
pushq $0x2c
popq %rdi
callq 0x4da7
movl %eax, %r15d
testl %eax, %eax
je 0x795a
pushq $0x78
popq %rdi
pushq $0x58
popq %rsi
callq 0x4dd8
testl %eax, %eax
je 0x7875
movq (%r12), %rax
addl $0x6, (%rax)
pushq $0x29
popq %rdi
callq 0x4da7
testl %eax, %eax
je 0x7ad8
movl %ebx, %ecx
testl %r15d, %r15d
je 0x7ae4
movl %ecx, %r15d
xorl %eax, %eax
callq 0x4dc3
leaq 0x155aa(%rip), %rax     # 0x1cf30
cmpl $0x0, (%rax)
je 0x7b14
callq 0x4d94
movq (%r12), %rax
movl %r13d, (%rax)
leaq 0x4(%rsp), %rdi
callq 0x929a
cmpl $0x11, %eax
je 0x78ea
movl %eax, %r14d
pushq $0x2c
popq %rdi
callq 0x4da7
testl %eax, %eax
je 0x79db
movq (%r12), %rax
addl $0x4, (%rax)
pushq $0x58
popq %rdi
pushq $0x78
popq %rsi
callq 0x4dd8
testl %eax, %eax
je 0x7aae
pushq $0x14
jmp 0x79dd
pushq $0x4
popq %rbp
movl 0x4(%rsp), %edx
cmpl $0x10000, %edx          # imm = 0x10000
jb 0x79fd
leaq 0x45a1(%rip), %rsi      # 0xbf92
pushq $0x1b
popq %rdi
callq 0x96cc
movl 0x4(%rsp), %edx
orl %ebx, %ebp
movq (%r12), %rax
movl (%rax), %ecx
cmpl $0x2, %r14d
je 0x7a3d
cmpl $0xff, %edx
jg 0x7a3d
leaq 0xcbee(%rip), %rdx      # 0x14608
cmpl $0x0, 0xe4(%rdx)
jne 0x7a3d
addl $0x3, %ecx
movl %ecx, (%rax)
movsbl %bpl, %edi
callq 0x3323
movsbl 0x4(%rsp), %edi
callq 0x33cf
jmp 0x7a58
addl $0x4, %ecx
movl %ecx, (%rax)
orl $0x8, %ebp
movsbl %bpl, %edi
callq 0x3323
movswl 0x4(%rsp), %edi
callq 0x34fb
cmpl $0x9d, %ebp
jne 0x7b36
movq (%r12), %rax
incl (%rax)
jmp 0x7b36
callq 0x3323
cmpl $0x2, %r14d
jne 0x7a81
xorl %eax, %eax
callq 0x960c
leaq 0xcd50(%rip), %rax      # 0x147d8
movq (%rax), %rax
movl (%rax), %ecx
leal 0x2(%rcx), %edx
movl %edx, (%rax)
leaq 0xc917(%rip), %rdx      # 0x143b0
xorl %ebp, %ebp
cmpb $0x1, (%rdx)
jne 0x78ea
addl $0x3, %ecx
movl %ecx, (%rax)
jmp 0x78ea
pushq $0x59
popq %rdi
pushq $0x79
popq %rsi
callq 0x4dd8
testl %eax, %eax
je 0x7875
orb $0x18, %bl
movsbl %bl, %edi
callq 0x3323
movswl 0x4(%rsp), %edi
callq 0x34fb
jmp 0x7b36
leaq 0x4918(%rip), %rsi      # 0xc3f7
jmp 0x787c
pushq $0x2c
popq %rdi
callq 0x4da7
testl %eax, %eax
je 0x7b4e
movq (%r12), %rax
addl $0x5, (%rax)
pushq $0x79
popq %rdi
pushq $0x59
popq %rsi
callq 0x4dd8
testl %eax, %eax
je 0x7875
movl %ebx, %ecx
orl $0x10, %ecx
jmp 0x7975
cmpl $0x91, %r15d
jne 0x7b23
movq (%r12), %rax
incl (%rax)
movsbl %r15b, %edi
callq 0x3323
movsbl 0x4(%rsp), %edi
callq 0x33cf
xorl %ebp, %ebp
cmpl $0x2, %r14d
jne 0x78ea
xorl %eax, %eax
callq 0x960c
jmp 0x78ea
movl %ebx, %ecx
orl $0x12, %ecx
decl %ecx
movq (%r12), %rax
incl (%rax)
jmp 0x7975