// File: /workspace/github_c_makefile_star2_O1/Nico01[P]obj2asm/oprocess.c
// Function: proc_idb
int proc_idb( depth, mult, dup_only, extended, length_used, repeat_cnt )
    int             depth;
    dword   mult;
    int             *dup_only;
    int             extended;
    word    *length_used;
    dword   *repeat_cnt;
{
    dword   repeat;
    word    num_blocks;
    word    blocks;
    word    length;
    int             data;
    word    data_size;
    word    result;
    int             fix_size;
    char            operand[80];
    uchar   rev_buff[10];
    word    out_count;
    int             dcheck;
    int             dummy;

    result = 512;

    repeat = (dword)buff_regetc();
    repeat += (dword)buff_regetc() << 8;
    *length_used += 2;

    if ( extended ) {
        repeat += (dword)buff_regetc() << 16;
        repeat += (dword)buff_regetc() << 24;
        *length_used += 2;
    }
    num_blocks = buff_regetc();
    num_blocks += buff_regetc() << 8;
    *length_used += 2;

    if ( repeat_cnt ) {             /* Return repeat count if needed */
        *repeat_cnt = repeat;
    }

    if ( repeat != 1 || num_blocks != 0 ) {
        sprintf( idb_buff, "%ld dup(", repeat );
        strcat( dup_buff, idb_buff );
    }

    mult *= repeat;

    if ( num_blocks ) {
        blocks = num_blocks;
        while ( blocks ) {
            if ( depth == 2 ) {
                *dup_only = TRUE;
            }
            data_size = proc_idb( depth+1, mult, dup_only, extended,
                                                       length_used, NULL );
            if ( data_size < result ) {
                result = data_size;
            }
            --blocks;
            if ( blocks != 0 ) {
                strcat( dup_buff, "," );
                strcat( struc_buff, "," );
            }
        }
    } else {
        length = buff_regetc();
        result = length;
        *length_used += length + 1;         /* one extra for the length byte */
        data_size = 0;
        while ( length ) {
            do {
                data = buff_getc();
                if ( data == EOF ) {
                    break;
                }
                if ( data < ' ' || data > '~' ) {
                    break;
                }
                data_size++;
                inst_offset += mult;
                dcheck = data_check( 0 );
            } while ( *dup_only && (dcheck == NORMAL || dcheck == BAD) );
            if ( *dup_only && data_size >= data_string ) {
                buff_reseek();
                length -= data_size;
                idb_buff[0] = '\'';
                out_count = 1;
                while ( data_size ) {
                    data = buff_regetc();
                    idb_buff[out_count++] = (char)data;
                    --data_size;
                }
                idb_buff[out_count++] = '\'';
                idb_buff[out_count] = '\0';
                if ( depth != 1 ) {
                    *dup_only = TRUE;
                }
                strcat( dup_buff, idb_buff );
                strcat( struc_buff, idb_buff );
            } else {
                /*
                ** Was it a fixup?
                */
                inst_offset -= data_size * mult;
                buff_reseek();      /* Back to start, string look */
                                    /* may have moved ptr         */
                if ( data_check( 0 ) == FIXUP ) {
                    if ( depth != 1 ) {
                        *dup_only = TRUE;
                    }
                    if ( fix_rec->form == POINTER ) {
                        fix_size = get_fix( operand, 2, FALSE, segment_bytes,
                                                    FAR, FALSE, &dummy, DS );
                    } else {
                        fix_size = get_fix( operand, 2, FALSE, segment_bytes,
                                                    NEAR, FALSE, &dummy, DS );
                    }
                    inst_offset += fix_size * mult;
                    length -= fix_size;
                    if ( pass == 3 ) {
                        strcat( dup_buff, operand );
                        strcat( struc_buff, operand );
                    }
                    buff_empty();
                } else {
                    /*
                    ** Nope, not a string.  Leave one or multiple bytes
                    */
                    data_size = length;
                    if ( data_size != 2 && data_size != 4 && data_size != 6
                                        && data_size != 8 && data_size != 10 ) {
                        data_size = 1;
                    }
                    strcat( dup_buff, "0" );
                    if ( depth == 1 ) {
                        strcat( struc_buff, "0" );
                    }
                    out_count = 0;
                    while ( out_count < data_size ) {
                        rev_buff[ out_count ] = (uchar)buff_regetc();
                        out_count++;
                    }
                    out_count = data_size;
                    while ( out_count ) {
                        --out_count;
                        if ( depth != 1 ) {
                            if ( rev_buff[out_count] != 0 ) {
                                *dup_only = TRUE;
                            }
                        }
                        sprintf( idb_buff, "%02X", rev_buff[out_count] );
                        strcat( dup_buff, idb_buff );
                        if ( depth == 1 ) {
                            strcat( struc_buff, idb_buff );
                        }
                    }
                    strcat( dup_buff, "h" );
                    if ( depth == 1 ) {
                        strcat( struc_buff, "h" );
                    }

                    length -= data_size;
                    inst_offset += mult * data_size;
                }
            }
            if ( length ) {
                strcat( dup_buff, "," );
            }
        }
    }

    if ( repeat != 1 || num_blocks != 0 ) {
        strcat( dup_buff, ")" );
    }

    return( result );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %r9, 0x30(%rsp)
movq %r8, %r13
movl %ecx, %ebp
movq %rdx, %r14
movq %rsi, 0x28(%rsp)
movq %rdi, 0x10(%rsp)
callq 0xf36c
movslq %eax, %rbx
callq 0xf36c
movslq %eax, %r15
shlq $0x8, %r15
addq %rbx, %r15
addl $0x2, (%r13)
movl %ebp, 0x18(%rsp)
testl %ebp, %ebp
je 0xd1a5
callq 0xf36c
movslq %eax, %rbx
shlq $0x10, %rbx
callq 0xf36c
cltq
shlq $0x18, %rax
addq %rbx, %rax
addq %rax, %r15
addl $0x2, (%r13)
callq 0xf36c
movl %eax, %ebx
callq 0xf36c
movl %eax, %r12d
shll $0x8, %r12d
movq %rbx, 0x38(%rsp)
addl %r12d, %ebx
movq %r13, 0x20(%rsp)
addl $0x2, (%r13)
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0xd1d7
movq %r15, (%rax)
cmpq $0x1, %r15
setne %al
testl %ebx, %ebx
setne %bpl
orb %al, %bpl
cmpb $0x1, %bpl
jne 0xd21d
movq %r15, %r13
leaq 0xffc9(%rip), %r15      # 0x1d1c0
leaq 0x6a99(%rip), %rsi      # 0x13c97
movq %r15, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x91b0
leaq 0x100ae(%rip), %rdi     # 0x1d2c0
movq %r15, %rsi
movq %r13, %r15
callq 0x91a0
imulq 0x28(%rsp), %r15
testl %ebx, %ebx
movq %r15, 0x28(%rsp)
je 0xd2b9
movb %bpl, 0xf(%rsp)
movq 0x10(%rsp), %rax
incl %eax
movl %eax, 0x30(%rsp)
movq 0x38(%rsp), %rax
leal -0x1(%rax,%r12), %ebx
movl $0x200, %r12d           # imm = 0x200
leaq 0x10069(%rip), %r13     # 0x1d2c0
movw $0x2c, %bp
leaq 0x1015e(%rip), %r15     # 0x1d3c0
cmpl $0x2, 0x10(%rsp)
jne 0xd270
movl $0x1, (%r14)
movl 0x30(%rsp), %edi
movq 0x28(%rsp), %rsi
movq %r14, %rdx
movl 0x18(%rsp), %ecx
movq 0x20(%rsp), %r8
xorl %r9d, %r9d
callq 0xd137
cmpl %r12d, %eax
cmovbl %eax, %r12d
subl $0x1, %ebx
jb 0xd60a
movq %r13, %rdi
callq 0x90b0
movw %bp, (%rax,%r13)
movq %r15, %rdi
callq 0x90b0
movw %bp, (%rax,%r15)
jmp 0xd262
callq 0xf36c
movl %eax, %r12d
movq 0x20(%rsp), %rcx
movl (%rcx), %eax
addl %r12d, %eax
incl %eax
movl %eax, (%rcx)
testl %r12d, %r12d
je 0xd60f
movb %bpl, 0xf(%rsp)
leaq 0xfeb4(%rip), %rbx      # 0x1d198
leaq 0xfed5(%rip), %r13      # 0x1d1c0
xorl %ebp, %ebp
movl %r12d, 0x20(%rsp)
callq 0xf442
addl $-0x7f, %eax
cmpl $-0x5f, %eax
jb 0xd32e
incl %ebp
movl %ebp, %ecx
movl %ecx, %ebp
addq %r15, (%rbx)
xorl %edi, %edi
callq 0xcca8
cmpl $0x0, (%r14)
je 0xd32e
cmpl $0x3, %eax
je 0xd31e
testl %eax, %eax
jne 0xd32e
callq 0xf442
addl $-0x7f, %eax
leal 0x1(%rbp), %ecx
cmpl $-0x60, %eax
ja 0xd303
cmpl $0x0, (%r14)
je 0xd384
leaq 0xc7cd(%rip), %rax      # 0x19b08
cmpl (%rax), %ebp
jb 0xd384
callq 0xf35d
movb $0x27, 0xfe75(%rip)     # 0x1d1c0
testl %ebp, %ebp
je 0xd584
movq %r14, %r15
movl %ebp, %ebx
xorl %r14d, %r14d
callq 0xf36c
movb %al, 0x1(%r14,%r13)
incq %r14
cmpl %r14d, %ebx
jne 0xd35b
leal 0x1(%rbp), %eax
movq %r15, %r14
movq 0x28(%rsp), %r15
leaq 0xfe19(%rip), %rbx      # 0x1d198
jmp 0xd589
movl %ebp, %eax
imulq %r15, %rax
subq %rax, (%rbx)
callq 0xf35d
xorl %edi, %edi
callq 0xcca8
cmpl $0x2, %eax
jne 0xd435
cmpl $0x1, 0x10(%rsp)
je 0xd3b0
movl $0x1, (%r14)
leaq 0xfd61(%rip), %rax      # 0x1d118
movq (%rax), %rax
xorl %r8d, %r8d
cmpl $0x3, 0x18(%rax)
sete %r8b
leaq 0xfdd8(%rip), %rax      # 0x1d1a4
movl (%rax), %ecx
incl %r8d
leaq 0x50(%rsp), %rdi
movl $0x2, %esi
xorl %edx, %edx
xorl %r9d, %r9d
pushq $0x14
leaq 0x48(%rsp), %rax
pushq %rax
callq 0x10207
addq $0x10, %rsp
movl %eax, %r13d
cltq
imulq %r15, %rax
addq %rax, (%rbx)
leaq 0xfb64(%rip), %rax      # 0x1cf68
cmpl $0x3, (%rax)
jne 0xd42b
leaq 0xfeb0(%rip), %rdi      # 0x1d2c0
leaq 0x50(%rsp), %rsi
callq 0x91a0
leaq 0xff9f(%rip), %rdi      # 0x1d3c0
leaq 0x50(%rsp), %rsi
callq 0x91a0
callq 0xf467
jmp 0xd5c9
movl 0x20(%rsp), %edx
movl %edx, %eax
andl $-0x5, %eax
movl %edx, %ecx
andl $-0x3, %ecx
cmpl $0x2, %eax
movl %edx, %esi
movl $0x1, %eax
cmovnel %eax, %esi
cmpl $0x4, %edx
cmovel %edx, %esi
cmpl $0x8, %ecx
cmovel %edx, %esi
movq %rsi, 0x18(%rsp)
leaq 0xfe58(%rip), %rbx      # 0x1d2c0
movq %rbx, %rdi
callq 0x90b0
movw $0x30, (%rax,%rbx)
cmpl $0x1, 0x10(%rsp)
jne 0xd492
leaq 0xff3c(%rip), %rbx      # 0x1d3c0
movq %rbx, %rdi
callq 0x90b0
movw $0x30, (%rax,%rbx)
movl 0x18(%rsp), %ebp
xorl %ebx, %ebx
callq 0xf36c
movb %al, 0x46(%rsp,%rbx)
incq %rbx
cmpq %rbx, %rbp
jne 0xd498
movq 0x18(%rsp), %rcx
leal -0x1(%rcx), %eax
leaq (%rsp,%rax), %r15
addq $0x46, %r15
movl %ecx, %ebx
movzbl (%r15), %edx
cmpl $0x1, 0x10(%rsp)
jne 0xd4e8
movq %r13, %rdi
leaq 0x73cb(%rip), %rsi      # 0x1489b
xorl %eax, %eax
callq 0x91b0
leaq 0xfde2(%rip), %rdi      # 0x1d2c0
movq %r13, %rsi
callq 0x91a0
jmp 0xd51e
testl %edx, %edx
je 0xd4f3
movl $0x1, (%r14)
movzbl (%r15), %edx
movq %r13, %rdi
leaq 0x739a(%rip), %rsi      # 0x1489b
xorl %eax, %eax
callq 0x91b0
leaq 0xfdb1(%rip), %rdi      # 0x1d2c0
movq %r13, %rsi
callq 0x91a0
cmpl $0x1, 0x10(%rsp)
jne 0xd52d
leaq 0xfe9b(%rip), %rdi      # 0x1d3c0
movq %r13, %rsi
callq 0x91a0
decl %ebx
decq %r15
testl %ebx, %ebx
jne 0xd4bb
leaq 0xfd83(%rip), %rbx      # 0x1d2c0
movq %rbx, %rdi
callq 0x90b0
movw $0x68, (%rax,%rbx)
cmpl $0x1, 0x10(%rsp)
jne 0xd567
leaq 0xfe67(%rip), %rbx      # 0x1d3c0
movq %rbx, %rdi
callq 0x90b0
movw $0x68, (%rax,%rbx)
movq 0x28(%rsp), %r15
imulq %r15, %rbp
leaq 0xfc21(%rip), %rbx      # 0x1d198
addq %rbp, (%rbx)
movq 0x18(%rsp), %r13
movl %r13d, %ebp
jmp 0xd5c9
movl $0x1, %eax
leal 0x1(%rax), %ecx
movl %eax, %eax
movb $0x27, (%rax,%r13)
movb $0x0, (%rcx,%r13)
cmpl $0x1, 0x10(%rsp)
je 0xd5a6
movl $0x1, (%r14)
leaq 0xfd13(%rip), %rdi      # 0x1d2c0
movq %r13, %rsi
callq 0x91a0
leaq 0xfe04(%rip), %rdi      # 0x1d3c0
movq %r13, %rsi
callq 0x91a0
movl %ebp, %r13d
xorl %ebp, %ebp
subl %r13d, 0x20(%rsp)
je 0xd60a
movq %r12, %r13
movq %rbx, %r12
movq %r15, %rbx
movq %r14, %r15
leaq 0xfcdd(%rip), %r14      # 0x1d2c0
movq %r14, %rdi
callq 0x90b0
movw $0x2c, (%rax,%r14)
movq %r15, %r14
movq %rbx, %r15
movq %r12, %rbx
movq %r13, %r12
leaq 0xfbbb(%rip), %r13      # 0x1d1c0
jmp 0xd2f2
movb 0xf(%rsp), %bpl
testb %bpl, %bpl
je 0xd629
leaq 0xfca5(%rip), %rbx      # 0x1d2c0
movq %rbx, %rdi
callq 0x90b0
movw $0x29, (%rax,%rbx)
movl %r12d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq