// File: /workspace/github_c_makefile_star2_O2/Nico01[P]obj2asm/odisasm.c
// Function: mod2
int mod2( ref_mode, sib_offset, sib_text, text, r_m, type, size_known )
    int             ref_mode;
    int             sib_offset;
    char            *sib_text;
    char            *text;
    uchar   r_m;
    int             type;
    int             *size_known;
{
    dword   offset;
    int             result;
    char            temp[50];
    char            *sign;
    int             ref_seg;

    if ( r_m == 2 || r_m == 3 ) {
        ref_seg = SS;               /* SS relative addressing modes */
    } else {
        ref_seg = DS;
    }
    if ( over_seg != -1 ) {
        ref_seg = 17+over_seg;
    }

    switch( data_check(2+sib_offset) ) {
        case BAD:
            result = -1;
            break;
        case LABEL:
            result = -1;
            break;
        case FIXUP:
            if ( fix_rec->word_sized && fix_rec->extended == addr_large ) {
                get_fix( temp, 0, FALSE, addr_bytes,
                                            type, TRUE, size_known, ref_seg );
                if ( compatibility == 2 ) {
                    strcpy( text, temp );
                    strcat( text, addr_mode[r_m] );
                } else {
                    if ( addr_large ) {
                        strcpy( text, addr_386m[r_m] );
                    } else {
                        strcpy( text, addr_mode[r_m] );
                    }
                    if ( strlen(sib_text) ) {
                        strcat( text, "+" );
                        strcat( text, sib_text );
                    }
                    strcat( text, "+" );
                    strcat( text, temp );
                }
                strcat( text, "]" );
                result = addr_bytes+sib_offset;
            } else {
                result = -1;
            }
            break;
        case NORMAL:
            if ( check_getv( &offset, addr_large ) ) {
                result = -1;
            } else {
                if ( offset == 0x00000000L ) { 
                    return( -1 );       /* Assembler should have optimized */
                }
                if ( addr_large ) {
                    strcpy( text, addr_386m[r_m] );
                } else {
                    strcpy( text, addr_mode[r_m] );
                }
                if ( strlen(sib_text) ) {
                    strcat( text, "+" );
                    strcat( text, sib_text );
                }
                if ( offset > 0x80000000L ) {
                    offset = -offset;
                    sign = "-";
                } else {
                    sign = "+";
                }
                out_hexize( offset, temp, addr_bytes );
                if ( compatibility == 2 ) {
                    strcat( text, "]" );
                    strcat( text, sign );
                    strcat( text, temp );
                } else {
                    strcat( text, sign );
                    strcat( text, temp );
                    strcat( text, "]" );
                }
                result = addr_bytes+sib_offset;
                *size_known = TRUE;
            }
            break;
    }
    return( result );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, %r13d
movl %r8d, %ebp
movq %rcx, %r14
movq %rdx, (%rsp)
movl %esi, %ebx
movl %ebp, %eax
andb $-0x2, %al
xorl %ecx, %ecx
cmpb $0x2, %al
setne %cl
addl $0x13, %ecx
movl 0xe2cf(%rip), %eax      # 0x18a88
leal 0x11(%rax), %r15d
cmpl $-0x1, %eax
cmovel %ecx, %r15d
leal 0x2(%rbx), %edi
callq 0xc74e
pushq $-0x1
popq %r12
testl %eax, %eax
je 0xa85e
cmpl $0x2, %eax
jne 0xaa00
leaq 0x11930(%rip), %rax     # 0x1c118
movq (%rax), %rax
cmpl $0x0, 0x3c(%rax)
je 0xaa00
movl 0x38(%rax), %eax
cmpl 0x1168a(%rip), %eax     # 0x1be88
jne 0xaa00
movl 0xe286(%rip), %ecx      # 0x18a90
leaq 0x10(%rsp), %r12
pushq $0x1
popq %r9
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
movl %r13d, %r8d
pushq %r15
pushq 0x88(%rsp)
callq 0xfad9
popq %rcx
popq %rdx
leaq 0x116c4(%rip), %rax     # 0x1bef8
cmpl $0x2, (%rax)
jne 0xa981
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x9070
movzbl %bpl, %eax
leaq 0xdadb(%rip), %rcx      # 0x18330
movq (%rcx,%rax,8), %r12
jmp 0xa9dd
movl 0x11624(%rip), %esi     # 0x1be88
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x9461
testl %eax, %eax
setne %al
movq (%r13), %r13
testq %r13, %r13
sete %cl
orb %al, %cl
jne 0xaa00
cmpl $0x0, 0x115f9(%rip)     # 0x1be88
leaq 0xda9a(%rip), %rax      # 0x18330
leaq 0xdad3(%rip), %rcx      # 0x18370
cmoveq %rax, %rcx
movzbl %bpl, %eax
movq (%rcx,%rax,8), %rsi
movq %r14, %rdi
callq 0x9070
movq (%rsp), %r15
cmpb $0x0, (%r15)
je 0xa8d5
movq %r14, %rdi
callq 0x90b0
movw $0x2b, (%r14,%rax)
movq %r14, %rdi
movq %r15, %rsi
callq 0x91a0
movq %r13, %rdi
negq %rdi
movl $0x80000000, %eax       # imm = 0x80000000
cmpq %rax, %r13
cmovbeq %r13, %rdi
leaq 0x7a63(%rip), %rax      # 0x12351
leaq 0x7a5a(%rip), %r15      # 0x1234f
cmovaq %rax, %r15
movl 0xe191(%rip), %edx      # 0x18a90
leaq 0x10(%rsp), %rsi
callq 0xc5b5
leaq 0x115e8(%rip), %rax     # 0x1bef8
movl (%rax), %ebp
movq %r14, %rdi
callq 0x90b0
cmpl $0x2, %ebp
jne 0xa946
movw $0x5d, (%r14,%rax)
movq %r14, %rdi
callq 0x90b0
movzwl (%r15), %ecx
movw %cx, (%r14,%rax)
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x91a0
jmp 0xa96b
movzwl (%r15), %ecx
movw %cx, (%r14,%rax)
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x91a0
movq %r14, %rdi
callq 0x90b0
movw $0x5d, (%r14,%rax)
addl 0xe11f(%rip), %ebx      # 0x18a90
movq 0x80(%rsp), %rax
movl $0x1, (%rax)
jmp 0xa9fd
cmpl $0x0, 0x11500(%rip)     # 0x1be88
leaq 0xd9a1(%rip), %rax      # 0x18330
leaq 0xd9da(%rip), %rcx      # 0x18370
cmoveq %rax, %rcx
movzbl %bpl, %eax
movq (%rcx,%rax,8), %rsi
movq %r14, %rdi
callq 0x9070
movq (%rsp), %r15
cmpb $0x0, (%r15)
je 0xa9ce
movq %r14, %rdi
callq 0x90b0
movw $0x2b, (%r14,%rax)
movq %r14, %rdi
movq %r15, %rsi
callq 0x91a0
movq %r14, %rdi
callq 0x90b0
movw $0x2b, (%r14,%rax)
movq %r14, %rdi
movq %r12, %rsi
callq 0x91a0
movq %r14, %rdi
callq 0x90b0
movw $0x5d, (%r14,%rax)
addl 0xe093(%rip), %ebx      # 0x18a90
movl %ebx, %r12d
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq