// File: /workspace/github_c_makefile_star2_O1/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 0x5037
testl %eax, %eax
je 0x81ff
movl $0x23, %edi
callq 0x4fa3
testl %eax, %eax
je 0x821e
leaq 0x4(%rsp), %rdi
callq 0x9e70
movl $0x1, %r14d
cmpl $0x11, %eax
je 0x8275
movl %eax, %ebp
movl $0xffffff00, %eax       # imm = 0xFFFFFF00
addl 0x4(%rsp), %eax
cmpl $0xfffffe7f, %eax       # imm = 0xFFFFFE7F
jbe 0x8261
cmpl $0x81, %ebx
jne 0x8287
leaq 0x4d9a(%rip), %rsi      # 0xcf92
movl $0x12, %edi
jmp 0x826d
leaq 0x4d8c(%rip), %rsi      # 0xcf92
movl $0x12, %edi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa2c8
callq 0x4f53
leaq 0xc5ae(%rip), %r15      # 0x147d8
movq (%r15), %rax
movl (%rax), %r12d
movl $0x28, %edi
callq 0x4fa3
testl %eax, %eax
je 0x832c
leaq 0x4(%rsp), %rdi
callq 0x9e70
movl $0x1, %r14d
cmpl $0x11, %eax
je 0x8275
cmpl $0x100, 0x4(%rsp)       # imm = 0x100
jb 0x82bc
leaq 0x4d2a(%rip), %rsi      # 0xcf92
movl $0x1a, %edi
callq 0xa2c8
movl %eax, %r14d
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
orb $0x8, %bl
movsbl %bl, %edi
callq 0x3348
leaq 0xc36f(%rip), %rax      # 0x14608
cmpl $0x0, 0x1bc(%rax)
movb 0x4(%rsp), %al
movsbl %al, %edi
je 0x843a
movl $0x2, %esi
callq 0x33a3
jmp 0x843f
movl %eax, %ebp
movl $0x2c, %edi
callq 0x4fa3
movl %eax, %r14d
testl %eax, %eax
je 0x82ec
movl $0x78, %edi
movl $0x58, %esi
callq 0x5083
testl %eax, %eax
je 0x81f1
movq (%r15), %rax
addl $0x6, (%rax)
movl $0x29, %edi
callq 0x4fa3
testl %eax, %eax
je 0x8479
movl %ebx, %r13d
testl %r14d, %r14d
je 0x8485
xorl %eax, %eax
callq 0x5037
leaq 0x14c18(%rip), %rax     # 0x1cf30
cmpl $0x0, (%rax)
je 0x84bc
callq 0x4f65
movq (%r15), %rax
movl %r12d, (%rax)
leaq 0x4(%rsp), %rdi
callq 0x9e70
movl $0x1, %r14d
cmpl $0x11, %eax
je 0x8275
movl %eax, %ebp
movl $0x2c, %edi
callq 0x4fa3
testl %eax, %eax
je 0x83a5
movq (%r15), %rax
addl $0x4, (%rax)
movl $0x58, %edi
movl $0x78, %esi
callq 0x5083
movl $0x14, %r14d
testl %eax, %eax
jne 0x83ab
movl $0x59, %edi
movl $0x79, %esi
callq 0x5083
testl %eax, %eax
je 0x81f1
orb $0x18, %bl
movsbl %bl, %edi
callq 0x3348
movswl 0x4(%rsp), %edi
callq 0x353c
jmp 0x84dd
movl $0x4, %r14d
cmpl $0x10000, 0x4(%rsp)     # imm = 0x10000
jb 0x83c6
leaq 0x4bd6(%rip), %rsi      # 0xcf92
movl $0x1b, %edi
callq 0xa2c8
orl %ebx, %r14d
movq (%r15), %rax
movl (%rax), %ecx
cmpl $0x2, %ebp
je 0x8407
cmpl $0xff, 0x4(%rsp)
jg 0x8407
leaq 0xc224(%rip), %rdx      # 0x14608
cmpl $0x0, 0xe4(%rdx)
jne 0x8407
addl $0x3, %ecx
movl %ecx, (%rax)
movsbl %r14b, %edi
callq 0x3348
movsbl 0x4(%rsp), %edi
callq 0x33fe
jmp 0x8423
addl $0x4, %ecx
movl %ecx, (%rax)
orl $0x8, %r14d
movsbl %r14b, %edi
callq 0x3348
movswl 0x4(%rsp), %edi
callq 0x353c
cmpl $0x9d, %r14d
jne 0x84dd
movq (%r15), %rax
incl (%rax)
jmp 0x84dd
callq 0x3348
cmpl $0x2, %ebp
jne 0x844b
xorl %eax, %eax
callq 0xa204
leaq 0xc386(%rip), %rax      # 0x147d8
movq (%rax), %rax
movl (%rax), %ecx
leal 0x2(%rcx), %edx
movl %edx, (%rax)
leaq 0xbf4d(%rip), %rdx      # 0x143b0
xorl %r14d, %r14d
cmpb $0x1, (%rdx)
jne 0x8275
addl $0x3, %ecx
movl %ecx, (%rax)
jmp 0x8275
leaq 0x4f77(%rip), %rsi      # 0xd3f7
jmp 0x81f8
movl $0x2c, %edi
callq 0x4fa3
testl %eax, %eax
je 0x84f5
movq (%r15), %rax
addl $0x5, (%rax)
movl $0x79, %edi
movl $0x59, %esi
callq 0x5083
testl %eax, %eax
je 0x81f1
movl %ebx, %r13d
orl $0x10, %r13d
jmp 0x830a
cmpl $0x91, %r13d
jne 0x84ca
movq (%r15), %rax
incl (%rax)
movsbl %r13b, %edi
callq 0x3348
movsbl 0x4(%rsp), %edi
callq 0x33fe
xorl %r14d, %r14d
cmpl $0x2, %ebp
jne 0x8275
xorl %eax, %eax
callq 0xa204
jmp 0x8275
movl %ebx, %r13d
orl $0x12, %r13d
decl %r13d
movq (%r15), %rax
incl (%rax)
jmp 0x830a