// File: /workspace/github_cpp_makefile_star2_O1/ksherlock[P]wdc-utils/disassembler.cpp
// Function: disassembler::operator()(unsigned char)
void disassembler::operator()(uint8_t byte) {

	if (_st == 0 || !_code)
		check_labels();

	if (!_code) {
		_bytes[_st++] = byte;

		if (_inline_data && --_inline_data <= 0) {
			dump();
			_code = true;
			return;
		}

		if (_st == 4) dump();
		return;
	}

	_bytes[_st++] = byte;
	if (_st == 1) {
		_op = byte;
		_mode = modes[_op];

		// bit hack
		if (_traits & bit_hacks && _op == 0x2c) {
			if (_next_label == _pc + 1) {
				dump();
				return;
			}
		}

		if (_traits & pea_immediate && _op == 0xf4) _mode = 2 | mImmediate;
		_size = _mode & 0x0f;
		if (_mode & _flags & m_I) _size++;
		if (_mode & _flags & m_M) _size++;

		if (!_size) {
			print();

			if (branchlike(byte)) fputs("\n", stdout);
		}
		return;
	}
	unsigned shift = (_st - 2) * 8;
	_arg = _arg + (byte << shift);
	if (_st <= _size) return;

	uint8_t op = _op;
	uint32_t arg = _arg;

	if (_traits & track_rep_sep) {
		switch(_op) {
			case 0xc2: // REP
				_flags |= (_arg & 0x30);
				break;
			case 0xe2: // SEP
				_flags &= ~(_arg & 0x30);
				break;
		}
	}

	// all done... now print it.
	print();

	if (branchlike(op)) fputs("\n", stdout);

	// todo -- subscribe to before/after events...
	switch(op) {
		case 0xc2:
		case 0xe2:
		case 0x22:
		case 0x5c:
		case 0xdc:
			event(op, arg);
			break;
	}



}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebp
movq %rdi, %rbx
cmpl $0x0, 0x8(%rdi)
je 0x889d
cmpb $0x0, 0x28(%rbx)
jne 0x88a5
movq %rbx, %rdi
callq 0x82f0
movl 0x8(%rbx), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x8(%rbx)
cmpb $0x0, 0x28(%rbx)
movb %bpl, 0x18(%rbx,%rcx)
je 0x8916
testl %ecx, %ecx
je 0x8943
leal (,%rcx,8), %ecx
movzbl %bpl, %ebp
addb $-0x8, %cl
shll %cl, %ebp
addl 0x24(%rbx), %ebp
movl %ebp, 0x24(%rbx)
cmpl 0x10(%rbx), %eax
jbe 0x8a64
movzbl 0xc(%rbx), %r14d
testb $0x10, 0x34(%rbx)
je 0x89fd
cmpl $0xe2, %r14d
je 0x89f3
cmpl $0xc2, %r14d
jne 0x89fd
movl %ebp, %eax
andl $0x30, %eax
orl %eax, 0x1c(%rbx)
jmp 0x89fd
movl 0x2c(%rbx), %ecx
testl %ecx, %ecx
je 0x8939
leal -0x1(%rcx), %edx
movl %edx, 0x2c(%rbx)
cmpl $0x1, %ecx
jg 0x8939
movq %rbx, %rdi
callq 0x7e24
movb $0x1, 0x28(%rbx)
jmp 0x8a64
cmpl $0x4, %eax
je 0x8976
jmp 0x8a64
movb %bpl, 0xc(%rbx)
movzbl %bpl, %r14d
leaq 0x6bfe(%rip), %rax      # 0xf550
movl (%rax,%r14,4), %eax
movl %eax, 0x14(%rbx)
movl 0x34(%rbx), %eax
testb $0x20, %al
sete %cl
cmpb $0x2c, %bpl
setne %dl
orb %cl, %dl
jne 0x8982
movl 0x20(%rbx), %ecx
incl %ecx
cmpl %ecx, 0x30(%rbx)
jne 0x8982
movq %rbx, %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x7e24
testb $0x1, %al
sete %al
cmpb $-0xc, %bpl
setne %cl
orb %al, %cl
jne 0x8999
movl $0x1002, 0x14(%rbx)     # imm = 0x1002
movl 0x14(%rbx), %eax
movl %eax, %ecx
andl $0xf, %ecx
movl %ecx, 0x10(%rbx)
andl 0x1c(%rbx), %eax
testb $0x10, %al
je 0x89b0
incl %ecx
movl %ecx, 0x10(%rbx)
testb $0x20, %al
je 0x89b7
incl 0x10(%rbx)
cmpl $0x0, 0x10(%rbx)
jne 0x8a64
movq %rbx, %rdi
callq 0x8a6a
movl %r14d, %edi
callq 0x8fa1
testb %al, %al
je 0x8a64
movq 0xc5e8(%rip), %rax      # 0x14fc8
movq (%rax), %rsi
leaq 0x6959(%rip), %rdi      # 0xf343
popq %rbx
popq %r14
popq %rbp
jmp 0x21e0
movl %ebp, %eax
notl %eax
orl $-0x31, %eax
andl %eax, 0x1c(%rbx)
movq %rbx, %rdi
callq 0x8a6a
movl %r14d, %edi
callq 0x8fa1
testb %al, %al
je 0x8a27
movq 0xc5b0(%rip), %rax      # 0x14fc8
movq (%rax), %rsi
leaq 0x6921(%rip), %rdi      # 0xf343
callq 0x21e0
leal -0xc2(%r14), %eax
cmpl $0x20, %eax
ja 0x8a43
movabsq $0x104000001, %rcx      # imm = 0x104000001
btq %rax, %rcx
jb 0x8a4f
cmpl $0x5c, %r14d
je 0x8a4f
cmpl $0x22, %r14d
jne 0x8a64
movq (%rbx), %rax
movq 0x40(%rax), %rax
movq %rbx, %rdi
movl %r14d, %esi
movl %ebp, %edx
popq %rbx
popq %r14
popq %rbp
jmpq *%rax
popq %rbx
popq %r14
popq %rbp
retq
nop