// File: /workspace/github_c_makefile_star2_O3/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 $0x68, %rsp
movq %r9, 0x50(%rsp)
movq %r8, %rbp
movq %rcx, 0x58(%rsp)
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r12
leaq -0x4(%rdx), %r13
movzwl 0xa0(%rsp), %r15d
movl %r15d, %esi
movq %r13, %rdx
callq 0x4707
movq %rax, 0x8(%rsp)
leaq (%rax,%rbx), %rdx
movq %r12, 0x28(%rsp)
movq %r12, %rdi
movl 0xb0(%rsp), %r12d
movl %r15d, 0x4(%rsp)
movl %r15d, %esi
movq %rdx, 0x30(%rsp)
callq 0x45af
movl %eax, %r15d
leaq 0x240d3(%rip), %rcx     # 0x410dc
movl $0x4043333, %edi        # imm = 0x4043333
movq %rbx, %rsi
movl %r12d, %edx
callq 0x55eb
leaq 0x3b160(%rip), %rax     # 0x58180
movq (%rax), %rax
btl $0x12, %eax
setae %cl
testq %rbp, %rbp
sete %dl
orb %cl, %dl
movq %rbx, 0x20(%rsp)
movq %r12, 0x38(%rsp)
movq %r14, 0x48(%rsp)
movq %r13, 0x40(%rsp)
movq %rbp, 0x18(%rsp)
jne 0x1d070
subq %rbx, %r14
leaq 0x2b6f9(%rip), %rdi     # 0x48750
movq %rbp, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
movq 0x8(%rsp), %r14
jmp 0x1d10d
testl $0x3003, %eax           # imm = 0x3003
je 0x1d0b9
leaq 0x2846d(%rip), %rdi     # 0x454eb
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
leaq 0x2baa0(%rip), %rdi     # 0x48b31
leaq 0x2b6ce(%rip), %rcx     # 0x48766
movl $0x17, %esi
movl $0x17, %edx
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
addl %ebx, %ebp
leaq 0x3b0cc(%rip), %rax     # 0x58180
movq (%rax), %rax
jmp 0x1d0bb
xorl %ebp, %ebp
movq 0x20(%rsp), %rbx
movq 0x8(%rsp), %r14
testb $0x30, %al
je 0x1d10d
movl %eax, %ecx
notl %ecx
testl $0x300, %ecx            # imm = 0x300
jne 0x1d0eb
leaq 0x28172(%rip), %rdi     # 0x4524e
movq %rbx, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3120
jmp 0x1d10b
btl $0x8, %eax
jb 0x1d0fa
leaq 0x2b731(%rip), %rdi     # 0x48829
jmp 0x1d101
leaq 0x2815a(%rip), %rdi     # 0x4525b
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
leaq (%r14,%rbx), %r12
addq $0x2, %r12
movl %ebp, %edi
callq 0x1707a
movl %eax, 0x8(%rsp)
movw %r15w, 0x10(%rsp)
movzwl %r15w, %r13d
xorl %ebx, %ebx
testw %r13w, %r13w
movq %r12, 0x60(%rsp)
je 0x1d1cd
xorl %r14d, %r14d
movl 0x4(%rsp), %r15d
movq 0x28(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movl %r15d, %edx
movq %r12, %rcx
callq 0x1d5e6
movq %rax, %r14
movq %rbp, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x1d1bc
testq %r14, %r14
je 0x1d1c6
movq %rbp, %rdi
callq 0x3190
movq %rax, %r12
subq $0x8, %rsp
movq %rbp, %rdi
xorl %esi, %esi
movl 0xc(%rsp), %r15d
movl %r15d, %edx
movq %r14, %rcx
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r9
movl 0xb8(%rsp), %eax
pushq %rax
movl 0xb8(%rsp), %eax
pushq %rax
pushq 0x68(%rsp)
callq 0x1d66e
addq $0x20, %rsp
incl %ebx
cmpl %ebx, %r13d
jne 0x1d148
jmp 0x1d1d0
movq %r12, %rdi
callq 0x34c1
jmp 0x1d1d0
movl %ebx, %edi
callq 0x34e6
xorl %r14d, %r14d
movq %r14, %rbp
leaq 0x3afa6(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
jne 0x1d1f8
xorl %r14d, %r14d
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r15
movzwl 0x10(%rsp), %r12d
jmp 0x1d306
movl 0xa8(%rsp), %eax
testl %eax, %eax
je 0x1d26c
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
leaq 0x27eba(%rip), %rax     # 0x450cc
cmoveq %rax, %rbx
movl 0xb0(%rsp), %edx
addl $0x4, %edx
leaq 0x23eb5(%rip), %rcx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq 0x30(%rsp), %rsi
movq %rdx, 0x38(%rsp)
callq 0x55eb
leaq 0x2b58e(%rip), %rdi     # 0x487d0
xorl %r14d, %r14d
movq %rbx, 0x18(%rsp)
movq %rbx, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x3120
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r15
movzwl 0x10(%rsp), %r12d
jmp 0x1d2f7
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x1d28b
leaq 0x2b531(%rip), %rsi     # 0x487ae
movl $0x4, %edx
callq 0x3090
testl %eax, %eax
je 0x1d29b
leaq 0x23f04(%rip), %rsi     # 0x41196
leaq 0x2b51a(%rip), %rdx     # 0x487b3
jmp 0x1d2a9
leaq 0x246f5(%rip), %rsi     # 0x41997
leaq 0x26d07(%rip), %rdx     # 0x43fb0
movq 0x18(%rsp), %rdi
callq 0x17f99
movq %rax, %r14
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r15
movzwl 0x10(%rsp), %r12d
leaq 0x23e0f(%rip), %rcx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq 0x30(%rsp), %rsi
movl 0xb0(%rsp), %edx
callq 0x55eb
leaq 0x2b4d6(%rip), %rdi     # 0x487c0
movq %r14, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x3120
addl 0x8(%rsp), %eax
movl %eax, %edi
callq 0x1707a
movl %eax, 0x8(%rsp)
movq %r14, 0x10(%rsp)
testw %r12w, %r12w
je 0x1d3cf
movq 0x38(%rsp), %rax
addl $0x4, %eax
movl %eax, 0x28(%rsp)
movl 0x4(%rsp), %edx
movq 0x60(%rsp), %r14
movq %r15, %rdi
movq %rbp, %rsi
movq %r14, %rcx
callq 0x1d5e6
movq %rax, %rbp
movq %r15, %rdi
callq 0x3190
movq %rax, %r12
leaq 0x3ae33(%rip), %rax     # 0x58180
movq (%rax), %rax
btl $0x12, %eax
jae 0x1d380
movl $0x4003333, %edi        # imm = 0x4003333
movq %r14, %rsi
movl 0x28(%rsp), %edx
leaq 0x23d73(%rip), %rcx     # 0x410dc
callq 0x55eb
movq %rbp, %rdi
callq 0x1fbc3
leaq 0x3ae03(%rip), %rax     # 0x58180
movq (%rax), %rax
testb $0x30, %al
je 0x1d3b8
subq $0x8, %rsp
movq %r15, %rdi
movq %rbp, %rsi
movl 0xc(%rsp), %edx
movq 0x28(%rsp), %rcx
movq %r14, %r8
movq 0x20(%rsp), %r9
pushq 0x40(%rsp)
movl 0xb8(%rsp), %eax
pushq %rax
pushq 0x68(%rsp)
callq 0x1fd35
addq $0x20, %rsp
cmpq %rbx, %r12
cmovaq %r12, %rbx
movq %r12, %r14
decl %r13d
movl 0x4(%rsp), %edx
jne 0x1d32a
leaq 0x3adaa(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
jne 0x1d3ff
movl 0xa8(%rsp), %eax
testl %eax, %eax
movq 0x38(%rsp), %rdx
movq 0x10(%rsp), %r15
je 0x1d4cb
movl 0x8(%rsp), %r14d
jmp 0x1d5b2
leaq -0x1(%rbx), %rsi
leaq 0x23cef(%rip), %rcx     # 0x410f9
movl $0x4043333, %edi        # imm = 0x4043333
movq 0x38(%rsp), %r13
movl %r13d, %edx
callq 0x55eb
movl 0xa8(%rsp), %eax
testl %eax, %eax
jle 0x1d54b
movq 0x18(%rsp), %rax
testq %rax, %rax
leaq 0x27c92(%rip), %r14     # 0x450cc
cmovneq %rax, %r14
leaq 0x2b3a6(%rip), %rdi     # 0x487eb
movq %r14, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
addl 0x8(%rsp), %r15d
leaq 0x23c9b(%rip), %r12     # 0x410f9
movl $0x4043333, %edi        # imm = 0x4043333
movq 0x40(%rsp), %rsi
movl %r13d, %edx
movq %r12, %rcx
callq 0x55eb
leaq 0x2b382(%rip), %rdi     # 0x487fc
movq %r14, %rsi
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x3120
movq %r13, %rdx
movl %eax, %r13d
movq 0x48(%rsp), %rsi
decq %rsi
addl $-0x4, %edx
movl $0x4043333, %edi        # imm = 0x4043333
movq %r12, %rcx
callq 0x55eb
leaq 0x24681(%rip), %rdi     # 0x41b2f
movq %r14, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
addl %r13d, %r14d
addl %r15d, %r14d
movq 0x10(%rsp), %r15
jmp 0x1d5b2
movq 0x48(%rsp), %rsi
decq %rsi
leaq 0x23c1f(%rip), %rcx     # 0x410f9
movl $0x4043333, %edi        # imm = 0x4043333
callq 0x55eb
leaq 0x3ac95(%rip), %rax     # 0x58180
movq (%rax), %rax
testl $0x3003, %eax           # imm = 0x3003
movl 0x8(%rsp), %r14d
je 0x1d52f
testb $0x40, %al
je 0x1d514
leaq 0x27fe6(%rip), %rdi     # 0x454eb
movq 0x18(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
leaq 0x2b316(%rip), %rdi     # 0x48831
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
leaq 0x3ac54(%rip), %rax     # 0x58180
movq (%rax), %rax
testb $0x30, %al
je 0x1d5b2
leaq 0x2b2ef(%rip), %rdi     # 0x48829
movq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
jmp 0x1d5b2
movq 0x10(%rsp), %r15
testq %r15, %r15
jne 0x1d564
leaq 0x27b70(%rip), %rdi     # 0x450cc
callq 0x32b0
movq %rax, %r15
leaq 0x2b2ac(%rip), %rdi     # 0x48817
movq %r15, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
addl 0x8(%rsp), %r14d
leaq 0x23b75(%rip), %rcx     # 0x410f9
movl $0x4043333, %edi        # imm = 0x4043333
movq 0x40(%rsp), %rsi
movl %r13d, %edx
callq 0x55eb
leaq 0x2b281(%rip), %rdi     # 0x4881e
movq %r15, %rsi
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x3120
addl %r14d, %eax
movl %eax, %r14d
movl %r14d, %edi
callq 0x1707a
testq %rbp, %rbp
je 0x1d5c7
movq %rbp, %rdi
callq 0x3050
testq %r15, %r15
je 0x1d5d4
movq %r15, %rdi
callq 0x3050
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq