// File: /workspace/github_c_makefile_star2_O1/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 0x46cc
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 0x4574
movl %eax, %r15d
leaq 0x245e3(%rip), %rcx     # 0x410dc
movl $0x4043333, %edi        # imm = 0x4043333
movq %rbx, %rsi
movl %r12d, %edx
callq 0x5605
leaq 0x3b670(%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 0x1cb60
subq %rbx, %r14
leaq 0x2bbc9(%rip), %rdi     # 0x48710
movq %rbp, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
movq 0x8(%rsp), %r14
jmp 0x1cbfd
testl $0x3003, %eax           # imm = 0x3003
je 0x1cb9f
leaq 0x28939(%rip), %rdi     # 0x454a7
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %ebx
leaq 0x2bf70(%rip), %rdi     # 0x48af1
leaq 0x2bb9e(%rip), %rcx     # 0x48726
movl $0x17, %esi
movl $0x17, %edx
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
addl %ebx, %ebp
jmp 0x1cba1
xorl %ebp, %ebp
movq 0x20(%rsp), %rbx
movq 0x8(%rsp), %r14
leaq 0x3b5ce(%rip), %rax     # 0x58180
movq (%rax), %rax
testb $0x30, %al
je 0x1cbfd
movl %eax, %ecx
notl %ecx
testl $0x300, %ecx            # imm = 0x300
jne 0x1cbdb
leaq 0x2863e(%rip), %rdi     # 0x4520a
movq %rbx, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3120
jmp 0x1cbfb
btl $0x8, %eax
jb 0x1cbea
leaq 0x2bc01(%rip), %rdi     # 0x487e9
jmp 0x1cbf1
leaq 0x28626(%rip), %rdi     # 0x45217
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
leaq (%r14,%rbx), %r12
addq $0x2, %r12
movl %ebp, %edi
callq 0x16b56
movl %eax, 0x8(%rsp)
movw %r15w, 0x10(%rsp)
movzwl %r15w, %r13d
xorl %ebx, %ebx
testw %r13w, %r13w
movq %r12, 0x60(%rsp)
je 0x1ccbd
xorl %r14d, %r14d
movl 0x4(%rsp), %r15d
movq 0x28(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movl %r15d, %edx
movq %r12, %rcx
callq 0x1d0cf
movq %rax, %r14
movq %rbp, %rdi
callq 0x30b0
testl %eax, %eax
jne 0x1ccac
testq %r14, %r14
je 0x1ccb6
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 0x1d157
addq $0x20, %rsp
incl %ebx
cmpl %ebx, %r13d
jne 0x1cc38
jmp 0x1ccc0
movq %r12, %rdi
callq 0x34c1
jmp 0x1ccc0
movl %ebx, %edi
callq 0x34e6
xorl %r14d, %r14d
movq %r14, %rbp
leaq 0x3b4b6(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
jne 0x1cce8
xorl %r14d, %r14d
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r15
movzwl 0x10(%rsp), %r12d
jmp 0x1cdf6
movl 0xa8(%rsp), %eax
testl %eax, %eax
je 0x1cd5c
movq 0x18(%rsp), %rbx
testq %rbx, %rbx
leaq 0x28386(%rip), %rax     # 0x45088
cmoveq %rax, %rbx
movl 0xb0(%rsp), %edx
addl $0x4, %edx
leaq 0x243c5(%rip), %rcx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq 0x30(%rsp), %rsi
movq %rdx, 0x38(%rsp)
callq 0x5605
leaq 0x2ba5e(%rip), %rdi     # 0x48790
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 0x1cde7
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x1cd7b
leaq 0x2ba01(%rip), %rsi     # 0x4876e
movl $0x4, %edx
callq 0x3090
testl %eax, %eax
je 0x1cd8b
leaq 0x24414(%rip), %rsi     # 0x41196
leaq 0x2b9ea(%rip), %rdx     # 0x48773
jmp 0x1cd99
leaq 0x24c05(%rip), %rsi     # 0x41997
leaq 0x27217(%rip), %rdx     # 0x43fb0
movq 0x18(%rsp), %rdi
callq 0x17a47
movq %rax, %r14
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r15
movzwl 0x10(%rsp), %r12d
leaq 0x2431f(%rip), %rcx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq 0x30(%rsp), %rsi
movl 0xb0(%rsp), %edx
callq 0x5605
leaq 0x2b9a6(%rip), %rdi     # 0x48780
movq %r14, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x3120
addl 0x8(%rsp), %eax
movl %eax, %edi
callq 0x16b56
movl %eax, 0x8(%rsp)
movq %r14, 0x10(%rsp)
testw %r12w, %r12w
je 0x1ceba
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 0x1d0cf
movq %rax, %rbp
movq %r15, %rdi
callq 0x3190
movq %rax, %r12
leaq 0x3b343(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x1ce63
movl $0x4003333, %edi        # imm = 0x4003333
movq %r14, %rsi
movl 0x28(%rsp), %edx
leaq 0x24286(%rip), %rcx     # 0x410dc
callq 0x5605
movq %rbp, %rdi
callq 0x1f5ee
leaq 0x3b316(%rip), %rax     # 0x58180
testb $0x30, (%rax)
je 0x1cea3
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 0x1f75d
addq $0x20, %rsp
cmpq %rbx, %r12
cmovaq %r12, %rbx
movq %r12, %r14
decl %r13d
movl 0x4(%rsp), %edx
jne 0x1ce1a
leaq 0x3b2bf(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
jne 0x1ceea
movl 0xa8(%rsp), %eax
testl %eax, %eax
movq 0x38(%rsp), %rdx
movq 0x10(%rsp), %r15
je 0x1cfb6
movl 0x8(%rsp), %r14d
jmp 0x1d09b
leaq -0x1(%rbx), %rsi
leaq 0x24204(%rip), %rcx     # 0x410f9
movl $0x4043333, %edi        # imm = 0x4043333
movq 0x38(%rsp), %r13
movl %r13d, %edx
callq 0x5605
movl 0xa8(%rsp), %eax
testl %eax, %eax
jle 0x1d034
movq 0x18(%rsp), %rax
testq %rax, %rax
leaq 0x28163(%rip), %r14     # 0x45088
cmovneq %rax, %r14
leaq 0x2b87b(%rip), %rdi     # 0x487ab
movq %r14, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r15d
addl 0x8(%rsp), %r15d
leaq 0x241b0(%rip), %r12     # 0x410f9
movl $0x4043333, %edi        # imm = 0x4043333
movq 0x40(%rsp), %rsi
movl %r13d, %edx
movq %r12, %rcx
callq 0x5605
leaq 0x2b857(%rip), %rdi     # 0x487bc
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 0x5605
leaq 0x24b96(%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 0x1d09b
movq 0x48(%rsp), %rsi
decq %rsi
leaq 0x24134(%rip), %rcx     # 0x410f9
movl $0x4043333, %edi        # imm = 0x4043333
callq 0x5605
leaq 0x3b1aa(%rip), %rax     # 0x58180
movq (%rax), %rax
testl $0x3003, %eax           # imm = 0x3003
movl 0x8(%rsp), %r14d
je 0x1d010
testb $0x40, %al
je 0x1cfff
leaq 0x284b7(%rip), %rdi     # 0x454a7
movq 0x18(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
leaq 0x2b7eb(%rip), %rdi     # 0x487f1
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
leaq 0x3b169(%rip), %rax     # 0x58180
testb $0x30, (%rax)
je 0x1d09b
leaq 0x2b7c6(%rip), %rdi     # 0x487e9
movq 0x30(%rsp), %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
jmp 0x1d09b
movq 0x10(%rsp), %r15
testq %r15, %r15
jne 0x1d04d
leaq 0x28043(%rip), %rdi     # 0x45088
callq 0x32b0
movq %rax, %r15
leaq 0x2b783(%rip), %rdi     # 0x487d7
movq %r15, %rsi
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
addl 0x8(%rsp), %r14d
leaq 0x2408c(%rip), %rcx     # 0x410f9
movl $0x4043333, %edi        # imm = 0x4043333
movq 0x40(%rsp), %rsi
movl %r13d, %edx
callq 0x5605
leaq 0x2b758(%rip), %rdi     # 0x487de
movq %r15, %rsi
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x3120
addl %r14d, %eax
movl %eax, %r14d
movl %r14d, %edi
callq 0x16b56
testq %rbp, %rbp
je 0x1d0b0
movq %rbp, %rdi
callq 0x3050
testq %r15, %r15
je 0x1d0bd
movq %r15, %rdi
callq 0x3050
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq