// File: /workspace/github_c_makefile_star2_O2/hfiguiere[P]exifprobe/ciff.c
// Function: process_ciff_dir
unsigned long
process_ciff_dir(FILE *inptr,unsigned long start_offset,unsigned long end_offset,
                char *subtype,char *dirname,struct image_summary * summary_entry,
                unsigned short byteorder,int level,int indent)
{
    struct ciff_direntry *entry;
    unsigned long dircount_loc;
    unsigned long max_dir_offset = 0L;
    unsigned long entry_offset,entry_offset_start;
    unsigned long next_entry_offset,dir_offset;
    unsigned short num_entries;
    char *tablename = CNULL;
    int i;
    int chpr = 0;

    dircount_loc = read_ulong(inptr,byteorder,end_offset - 4) + start_offset;
    num_entries = read_ushort(inptr,byteorder,dircount_loc);
    entry_offset = entry_offset_start = dircount_loc + 2;
    entry = NULL;

    max_dir_offset = start_offset;

    /* Show where this directory is in the heap                       */
    print_tag_address(SECTION|ENTRY,start_offset,indent,"@");
    if((PRINT_SECTION && dirname))
    {
        chpr += printf("<%s> HEAP, length %lu",dirname,end_offset - start_offset);
        chpr = newline(chpr);
    }
    else
    {
        if((PRINT_TAGINFO))
        {
            /* Always want to know WHICH heap offset                  */
            chpr += printf("%s.",dirname);
            chpr += printf("%-*.*s",CIFFTAGWIDTH,CIFFTAGWIDTH,"HeapOffset");
        }
        if((PRINT_VALUE))
        {
            if(PRINT_BOTH_OFFSET)
                chpr += printf(" = @%#lx=%lu",start_offset,start_offset);
            else if(PRINT_HEX_OFFSET)
                chpr += printf(" = @%#lx",start_offset);
            else 
                chpr += printf(" = @%lu",start_offset);
        }
        chpr = newline(chpr);
    }

    /* Now burrow down to the bottom, recursively. This will show the */
    /* lower level directories and entries first.                     */
    for(i = 0; i < num_entries; ++i)
    {
        entry = read_ciff_direntry(inptr,entry,byteorder,entry_offset);
        if(ferror(inptr))
        {
            fprintf(stderr,"%s: error reading directory entry at %lu\n",
                                                Progname,entry_offset);
            break;
        }
        if(entry == NULL)
        {
            fprintf(stderr,"%s: null entry %d\n",Progname,i);
            break;
        }
        next_entry_offset = ftell(inptr);
        dir_offset =
            process_ciff_direntry(inptr,CIFF_INHEAP,byteorder,entry,start_offset,
                                            dirname,summary_entry,level,indent);
        entry_offset = next_entry_offset;
    }

    /* Next show the directory info; this will display higher level   */
    /* directories and their direct entry values as the recursive     */
    /* calls unwind back to the top.                                  */
    if(PRINT_SECTION)
    {
        if(level == 0)
        {
            if(subtype && (strncmp(subtype,"JPGM",4) == 0))
                tablename = splice(dirname,".","ImageProperties");
            else
                tablename = splice(dirname," ","offset table");
            print_tag_address(SECTION,dircount_loc,indent,"@");
            chpr += printf("<%s> %u entries",tablename,num_entries);
        }
        else
        {
            dirname = dirname ? dirname : QSTRING;
            print_tag_address(SECTION,dircount_loc,indent+MEDIUMINDENT,"@");
            chpr += printf("<%s DIRECTORY>, %u entries",dirname,num_entries);
            indent += MEDIUMINDENT;
        }
        chpr = newline(chpr);
    }
 
    entry_offset = entry_offset_start;
    max_dir_offset = start_offset;
    for(i = 0; i < num_entries; ++i)
    {
        entry = read_ciff_direntry(inptr,entry,byteorder,entry_offset);
        next_entry_offset = ftell(inptr);

        if((PRINT_SECTION)) 
        {
            print_tag_address(ENTRY,entry_offset,indent + MEDIUMINDENT,"@");
            print_ciff_taginfo(entry,start_offset);
        }
        if(PRINT_VALUE)
        {
            print_ciff_value(inptr,entry,byteorder,start_offset,entry_offset,
                                                    dirname,summary_entry
                                                    ,level,indent);
        }
        entry_offset = next_entry_offset;
        if(entry_offset > max_dir_offset)
            max_dir_offset = entry_offset;
    }
    /* Close off the directory; at the top, report the location of    */
    /* the offset table (or top level directory if JPGM) and loction  */
    /* where its location was found (at the end of the file).         */
    if(PRINT_SECTION)
    {
        if(level > 0)
        {
            print_tag_address(SECTION|ENTRY,max_dir_offset - 1,indent,"-");
            dirname = dirname ? dirname : QSTRING;
            chpr += printf("</%s DIRECTORY>\n",dirname);
            print_tag_address(SECTION|ENTRY,end_offset - 4,indent,"-");
            chpr += printf("%s DIRECTORY offset = %lu\n",dirname,dircount_loc);
            print_tag_address(SECTION|ENTRY,end_offset - 1,indent-MEDIUMINDENT,"-");
            chpr += printf("</%s>",dirname);
        }
        else
        {
            print_tag_address(SECTION|ENTRY,max_dir_offset - 1,indent,"-");
            /* tablename is dynamically allocated */
            tablename = tablename ? tablename : strdup(QSTRING);
            chpr += printf("</%s>\n",tablename);
            print_tag_address(SECTION|ENTRY,end_offset - 4,indent,"-");
            chpr += printf("%s location = @%lu",tablename,dircount_loc);
        }
    }
    else if(level == 0)
    {
        print_tag_address(SECTION|ENTRY,end_offset - 1,indent,"-");
        if((PRINT_TAGINFO))
        {
            if((PRINT_LONGNAMES)) 
                chpr += printf("%s.",dirname);
            chpr += printf("OffsetTableOffset");
        }
        if((PRINT_VALUE))
            chpr += printf(" = @%lu",dircount_loc);
    }
    chpr = newline(chpr);
    if(entry)
        free(entry);
    if(tablename)
        free(tablename);
    return(max_dir_offset);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x50(%rsp)
movq %r8, %r13
movq %rcx, 0x30(%rsp)
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
movl 0xa0(%rsp), %ebp
addq $-0x4, %rdx
movzwl 0x90(%rsp), %r12d
movl %r12d, %esi
movq %rdx, 0x40(%rsp)
callq 0x42ba
movq %rax, 0x18(%rsp)
leaq (%rax,%rbx), %rdx
movq %r15, %rdi
movl %r12d, 0xc(%rsp)
movl %r12d, %esi
movq %rdx, 0x28(%rsp)
callq 0x416a
movl %eax, %r12d
leaq 0x232de(%rip), %rcx     # 0x3f0dc
movl $0x4043333, %edi        # imm = 0x4043333
movq %rbx, %rsi
movl %ebp, %edx
callq 0x5100
leaq 0x3b36c(%rip), %rax     # 0x57180
movq (%rax), %rax
btl $0x12, %eax
setae %cl
testq %r13, %r13
sete %dl
orb %cl, %dl
movq %r14, 0x48(%rsp)
movq %r13, 0x10(%rsp)
jne 0x1be51
subq %rbx, %r14
leaq 0x2a8c4(%rip), %rdi     # 0x46700
movq %r13, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3120
movl %eax, %r13d
jmp 0x1bee7
movq %rbx, %rbp
testw $0x3003, %ax            # imm = 0x3003
je 0x1be99
leaq 0x27646(%rip), %rdi     # 0x434a7
movq %r13, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
leaq 0x2ac6d(%rip), %rdi     # 0x46ae1
leaq 0x2a89b(%rip), %rcx     # 0x46716
pushq $0x17
popq %rdx
movl %edx, %esi
xorl %eax, %eax
callq 0x3120
movl %eax, %r13d
addl %ebx, %r13d
leaq 0x3b2ec(%rip), %rax     # 0x57180
movq (%rax), %rax
jmp 0x1be9c
xorl %r13d, %r13d
movq %rbp, %rbx
testb $0x30, %al
je 0x1bee7
movl %eax, %ecx
notl %ecx
testw $0x300, %cx             # imm = 0x300
jne 0x1bec4
leaq 0x27355(%rip), %rdi     # 0x4320a
movq %rbx, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3120
jmp 0x1bee4
btl $0x8, %eax
jb 0x1bed3
leaq 0x2a908(%rip), %rdi     # 0x467d9
jmp 0x1beda
leaq 0x2733d(%rip), %rdi     # 0x43217
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %r13d
movq %rbx, 0x38(%rsp)
movq 0x18(%rsp), %rax
leaq (%rax,%rbx), %r14
addq $0x2, %r14
movl %r13d, %edi
callq 0x160f7
movl %eax, 0x8(%rsp)
movzwl %r12w, %r13d
xorl %ebp, %ebp
movq %r14, %r12
xorl %ebx, %ebx
cmpl %ebx, %r13d
je 0x1bfd2
movq %r15, %rdi
movq %rbp, %rsi
movl 0xc(%rsp), %edx
movq %r12, %rcx
callq 0x1c3ac
movq %rax, %rbp
movq %r15, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x1bf85
testq %rbp, %rbp
je 0x1bfac
movq %r15, %rdi
callq 0x3190
movq %rax, %r12
subq $0x8, %rsp
movq %r15, %rdi
xorl %esi, %esi
movl 0x14(%rsp), %edx
movq %rbp, %rcx
movq 0x40(%rsp), %r8
movq 0x18(%rsp), %r9
movl 0xa8(%rsp), %eax
pushq %rax
movl 0xa8(%rsp), %eax
pushq %rax
pushq 0x68(%rsp)
callq 0x1c42f
addq $0x20, %rsp
incl %ebx
jmp 0x1bf10
movq 0x3b06c(%rip), %rax     # 0x56ff8
movq (%rax), %rdi
leaq 0x3c4d2(%rip), %rax     # 0x58468
movq (%rax), %rdx
leaq 0x2a781(%rip), %rsi     # 0x46721
movq %r12, %rcx
xorl %eax, %eax
callq 0x3180
jmp 0x1bfd2
movq 0x3b045(%rip), %rax     # 0x56ff8
movq (%rax), %rdi
leaq 0x3c4ab(%rip), %rax     # 0x58468
movq (%rax), %rdx
leaq 0x2a784(%rip), %rsi     # 0x4674b
xorl %ebp, %ebp
movl %ebx, %ecx
xorl %eax, %eax
callq 0x3180
leaq 0x3b1a7(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
movl 0xa0(%rsp), %ebx
jne 0x1bff4
movq $0x0, 0x20(%rsp)
jmp 0x1c0cc
movl 0x98(%rsp), %eax
testl %eax, %eax
je 0x1c044
movq 0x10(%rsp), %r12
testq %r12, %r12
leaq 0x2707a(%rip), %rax     # 0x43088
cmoveq %rax, %r12
addl $0x4, %ebx
leaq 0x230c0(%rip), %rcx     # 0x3f0dc
movl $0x40000, %edi          # imm = 0x40000
movq 0x28(%rsp), %rsi
movl %ebx, %edx
callq 0x5100
leaq 0x2a74c(%rip), %rdi     # 0x46780
movq $0x0, 0x20(%rsp)
movq %r12, 0x10(%rsp)
jmp 0x1c0b0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x1c061
leaq 0x2a709(%rip), %rsi     # 0x4675e
pushq $0x4
popq %rdx
callq 0x3090
testl %eax, %eax
je 0x1c071
leaq 0x2312e(%rip), %rsi     # 0x3f196
leaq 0x2a6f4(%rip), %rdx     # 0x46763
jmp 0x1c07f
leaq 0x2391f(%rip), %rsi     # 0x3f997
leaq 0x25f31(%rip), %rdx     # 0x41fb0
movq 0x10(%rsp), %rdi
callq 0x16f1d
movq %rax, %r12
leaq 0x23049(%rip), %rcx     # 0x3f0dc
movl $0x40000, %edi          # imm = 0x40000
movq 0x28(%rsp), %rsi
movl %ebx, %edx
callq 0x5100
leaq 0x2a6c5(%rip), %rdi     # 0x46770
movq %r12, 0x20(%rsp)
movq %r12, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x3120
addl 0x8(%rsp), %eax
movl %eax, %edi
callq 0x160f7
movl %eax, 0x8(%rsp)
movq %rbx, 0x18(%rsp)
leal 0x4(%rbx), %eax
movl %eax, 0x30(%rsp)
movq 0x38(%rsp), %rbx
subl $0x1, %r13d
jb 0x1c188
movq %r15, %rdi
movq %rbp, %rsi
movl 0xc(%rsp), %edx
movq %r14, %rcx
callq 0x1c3ac
movq %rax, %rbp
movq %r15, %rdi
callq 0x3190
movq %rax, %r12
leaq 0x3b072(%rip), %rax     # 0x57180
movq (%rax), %rax
btl $0x12, %eax
jae 0x1c141
movl $0x4003333, %edi        # imm = 0x4003333
movq %r14, %rsi
movl 0x30(%rsp), %edx
leaq 0x22fb2(%rip), %rcx     # 0x3f0dc
callq 0x5100
movq %rbp, %rdi
callq 0x1e908
leaq 0x3b042(%rip), %rax     # 0x57180
movq (%rax), %rax
testb $0x30, %al
je 0x1c179
subq $0x8, %rsp
movq %r15, %rdi
movq %rbp, %rsi
movl 0x14(%rsp), %edx
movq 0x40(%rsp), %rcx
movq %r14, %r8
movq 0x18(%rsp), %r9
pushq 0x20(%rsp)
movl 0xa8(%rsp), %eax
pushq %rax
pushq 0x68(%rsp)
callq 0x1ea6e
addq $0x20, %rsp
cmpq %rbx, %r12
cmovaq %r12, %rbx
movq %r12, %r14
jmp 0x1c0dd
leaq 0x3aff1(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
jne 0x1c1b8
movl 0x98(%rsp), %eax
testl %eax, %eax
movq 0x10(%rsp), %r14
movq 0x20(%rsp), %r15
je 0x1c286
movl 0x8(%rsp), %r14d
jmp 0x1c382
leaq -0x1(%rbx), %rsi
leaq 0x22f36(%rip), %rcx     # 0x3f0f9
movl $0x4043333, %edi        # imm = 0x4043333
movq 0x18(%rsp), %r12
movl %r12d, %edx
callq 0x5100
movl 0x98(%rsp), %eax
testl %eax, %eax
movq 0x10(%rsp), %rax
jle 0x1c2c2
testq %rax, %rax
leaq 0x26e95(%rip), %r14     # 0x43088
cmovneq %rax, %r14
leaq 0x2a59d(%rip), %rdi     # 0x4679b
movq %r14, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
addl 0x8(%rsp), %r15d
leaq 0x22ee2(%rip), %rcx     # 0x3f0f9
movl $0x4043333, %edi        # imm = 0x4043333
movq 0x40(%rsp), %rsi
movl %r12d, %edx
callq 0x5100
leaq 0x2a57c(%rip), %rdi     # 0x467ac
movq %r14, %rsi
movq 0x28(%rsp), %rdx
xorl %eax, %eax
callq 0x3120
movl %eax, %r13d
movq 0x48(%rsp), %rsi
decq %rsi
addl $-0x4, %r12d
movl $0x4043333, %edi        # imm = 0x4043333
movl %r12d, %edx
leaq 0x22e9c(%rip), %rcx     # 0x3f0f9
callq 0x5100
leaq 0x238c6(%rip), %rdi     # 0x3fb2f
movq %r14, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
addl %r13d, %r14d
addl %r15d, %r14d
movq 0x20(%rsp), %r15
jmp 0x1c382
movq 0x48(%rsp), %rsi
decq %rsi
leaq 0x22e64(%rip), %rcx     # 0x3f0f9
movl $0x4043333, %edi        # imm = 0x4043333
movq 0x18(%rsp), %rdx
callq 0x5100
leaq 0x3aed5(%rip), %rax     # 0x57180
movq (%rax), %rax
testw $0x3003, %ax            # imm = 0x3003
je 0x1c32d
testb $0x40, %al
jne 0x1c334
movl 0x8(%rsp), %r14d
jmp 0x1c34d
movq 0x20(%rsp), %r15
testq %r15, %r15
jne 0x1c2db
leaq 0x26db5(%rip), %rdi     # 0x43088
callq 0x32b0
movq %rax, %r15
leaq 0x2a4e5(%rip), %rdi     # 0x467c7
movq %r15, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
addl 0x8(%rsp), %r14d
leaq 0x22dfe(%rip), %rcx     # 0x3f0f9
movl $0x4043333, %edi        # imm = 0x4043333
movq 0x40(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x5100
leaq 0x2a4b8(%rip), %rdi     # 0x467ce
movq %r15, %rsi
movq 0x28(%rsp), %rdx
xorl %eax, %eax
callq 0x3120
addl %r14d, %eax
movl %eax, %r14d
jmp 0x1c382
movl 0x8(%rsp), %r14d
jmp 0x1c368
leaq 0x2716c(%rip), %rdi     # 0x434a7
movq %r14, %rsi
xorl %eax, %eax
callq 0x3120
movl 0x8(%rsp), %r14d
addl %eax, %r14d
leaq 0x2a48d(%rip), %rdi     # 0x467e1
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
leaq 0x3ae1b(%rip), %rax     # 0x57180
movq (%rax), %rax
testb $0x30, %al
je 0x1c382
leaq 0x2a466(%rip), %rdi     # 0x467d9
movq 0x28(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
movl %r14d, %edi
callq 0x160f7
movq %rbp, %rdi
callq 0x3050
movq %r15, %rdi
callq 0x3050
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq