// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xb0, %rsp
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movw 0x10(%rbp), %ax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x78(%rbp)
movl $0x0, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movw 0x10(%rbp), %ax
movq -0x18(%rbp), %rdx
subq $0x4, %rdx
movzwl %ax, %esi
callq 0x4610
addq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movw 0x10(%rbp), %ax
movq -0x40(%rbp), %rdx
movzwl %ax, %esi
callq 0x4480
movw %ax, -0x6a(%rbp)
movq -0x40(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x58(%rbp)
movq %rax, -0x50(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rsi
movl 0x20(%rbp), %edx
movl $0x4043333, %edi        # imm = 0x4043333
leaq 0x3accd(%rip), %rcx     # 0x640dc
callq 0x5ed0
leaq 0x4dd65(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x29461
cmpq $0x0, -0x28(%rbp)
je 0x29461
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rdx
subq -0x10(%rbp), %rdx
leaq 0x4186b(%rip), %rdi     # 0x6acaf
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %edi
callq 0x1ef50
movl %eax, -0x80(%rbp)
jmp 0x29556
leaq 0x4dd18(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x3003, %rax           # imm = 0x3003
cmpq $0x0, %rax
je 0x294b1
movq -0x28(%rbp), %rsi
leaq 0x3e6f7(%rip), %rdi     # 0x67b79
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
leaq 0x41c06(%rip), %rdi     # 0x6b09c
movl $0x17, %edx
leaq 0x41823(%rip), %rcx     # 0x6acc5
movl %edx, %esi
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
leaq 0x4dcc8(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x30, %rax
cmpq $0x0, %rax
je 0x2954b
leaq 0x4dcb0(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x300, %rax            # imm = 0x300
cmpq $0x300, %rax            # imm = 0x300
jne 0x294ff
movq -0x10(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq 0x3e3ec(%rip), %rdi     # 0x678dc
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x29549
leaq 0x4dc7a(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x100, %rax            # imm = 0x100
cmpq $0x0, %rax
je 0x2952f
movq -0x10(%rbp), %rsi
leaq 0x3e3c9(%rip), %rdi     # 0x678e9
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x29547
movq -0x10(%rbp), %rsi
leaq 0x4184e(%rip), %rdi     # 0x6ad88
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x29549
jmp 0x2954b
movl -0x80(%rbp), %edi
callq 0x1ef50
movl %eax, -0x80(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movzwl -0x6a(%rbp), %ecx
cmpl %ecx, %eax
jge 0x2964c
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movw 0x10(%rbp), %ax
movq -0x50(%rbp), %rcx
movzwl %ax, %edx
callq 0x29b00
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
callq 0x30a0
cmpl $0x0, %eax
je 0x295c1
movq 0x4da5b(%rip), %rax     # 0x76ff8
movq (%rax), %rdi
leaq 0x4eec1(%rip), %rax     # 0x78468
movq (%rax), %rdx
movq -0x50(%rbp), %rcx
leaq 0x4171b(%rip), %rsi     # 0x6acd0
movb $0x0, %al
callq 0x3170
jmp 0x2964c
cmpq $0x0, -0x38(%rbp)
jne 0x295ef
movq 0x4da29(%rip), %rax     # 0x76ff8
movq (%rax), %rdi
leaq 0x4ee8f(%rip), %rax     # 0x78468
movq (%rax), %rdx
movl -0x7c(%rbp), %ecx
leaq 0x41714(%rip), %rsi     # 0x6acfa
movb $0x0, %al
callq 0x3170
jmp 0x2964c
movq -0x8(%rbp), %rdi
callq 0x3180
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movw 0x10(%rbp), %dx
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %r8
movq -0x28(%rbp), %r9
movq -0x30(%rbp), %r11
movl 0x18(%rbp), %r10d
movl 0x20(%rbp), %eax
xorl %esi, %esi
movzwl %dx, %edx
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0x29bd0
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x2955d
leaq 0x4db2d(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x29779
cmpl $0x0, 0x18(%rbp)
jne 0x296ff
cmpq $0x0, -0x20(%rbp)
je 0x296ae
movq -0x20(%rbp), %rdi
leaq 0x4168b(%rip), %rsi     # 0x6ad0d
movl $0x4, %edx
callq 0x3080
cmpl $0x0, %eax
jne 0x296ae
movq -0x28(%rbp), %rdi
leaq 0x3b2c6(%rip), %rsi     # 0x64962
leaq 0x3d115(%rip), %rdx     # 0x667b8
callq 0x20960
movq %rax, -0x78(%rbp)
jmp 0x296c9
movq -0x28(%rbp), %rdi
leaq 0x3aabe(%rip), %rsi     # 0x64177
leaq 0x41652(%rip), %rdx     # 0x6ad12
callq 0x20960
movq %rax, -0x78(%rbp)
movq -0x40(%rbp), %rsi
movl 0x20(%rbp), %edx
movl $0x40000, %edi          # imm = 0x40000
leaq 0x3aa00(%rip), %rcx     # 0x640dc
callq 0x5ed0
movq -0x78(%rbp), %rsi
movzwl -0x6a(%rbp), %edx
leaq 0x4162f(%rip), %rdi     # 0x6ad1f
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x2976e
cmpq $0x0, -0x28(%rbp)
je 0x29713
movq -0x28(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x29723
leaq 0x3e040(%rip), %rax     # 0x6775a
movq %rax, -0x88(%rbp)
jmp 0x29723
movq -0x88(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x40(%rbp), %rsi
movl 0x20(%rbp), %edx
addl $0x4, %edx
movl $0x40000, %edi          # imm = 0x40000
leaq 0x3a998(%rip), %rcx     # 0x640dc
callq 0x5ed0
movq -0x28(%rbp), %rsi
movzwl -0x6a(%rbp), %edx
leaq 0x415d7(%rip), %rdi     # 0x6ad2f
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
movl 0x20(%rbp), %eax
addl $0x4, %eax
movl %eax, 0x20(%rbp)
movl -0x80(%rbp), %edi
callq 0x1ef50
movl %eax, -0x80(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movzwl -0x6a(%rbp), %ecx
cmpl %ecx, %eax
jge 0x2987c
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movw 0x10(%rbp), %ax
movq -0x50(%rbp), %rcx
movzwl %ax, %edx
callq 0x29b00
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
callq 0x3180
movq %rax, -0x60(%rbp)
leaq 0x4d9b1(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x29806
movq -0x50(%rbp), %rsi
movl 0x20(%rbp), %edx
addl $0x4, %edx
movl $0x4003333, %edi        # imm = 0x4003333
leaq 0x3a8e8(%rip), %rcx     # 0x640dc
callq 0x5ed0
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2d250
leaq 0x4d973(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x30, %rax
cmpq $0x0, %rax
je 0x29852
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movw 0x10(%rbp), %dx
movq -0x10(%rbp), %rcx
movq -0x50(%rbp), %r8
movq -0x28(%rbp), %r9
movq -0x30(%rbp), %r11
movl 0x18(%rbp), %r10d
movl 0x20(%rbp), %eax
movzwl %dx, %edx
movq %r11, (%rsp)
movl %r10d, 0x8(%rsp)
movl %eax, 0x10(%rsp)
callq 0x2d650
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jbe 0x2986c
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x2986e
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x29790
leaq 0x4d8fd(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x29a1a
cmpl $0x0, 0x18(%rbp)
jle 0x29977
movq -0x48(%rbp), %rsi
subq $0x1, %rsi
movl 0x20(%rbp), %edx
movl $0x4043333, %edi        # imm = 0x4043333
leaq 0x3a842(%rip), %rcx     # 0x640f9
callq 0x5ed0
cmpq $0x0, -0x28(%rbp)
je 0x298d0
movq -0x28(%rbp), %rax
movq %rax, -0x90(%rbp)
jmp 0x298e0
leaq 0x3de83(%rip), %rax     # 0x6775a
movq %rax, -0x90(%rbp)
jmp 0x298e0
movq -0x90(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rsi
leaq 0x41454(%rip), %rdi     # 0x6ad4a
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
movq -0x18(%rbp), %rsi
subq $0x4, %rsi
movl 0x20(%rbp), %edx
movl $0x4043333, %edi        # imm = 0x4043333
leaq 0x3a7df(%rip), %rcx     # 0x640f9
callq 0x5ed0
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq 0x4142d(%rip), %rdi     # 0x6ad5b
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
movq -0x18(%rbp), %rsi
subq $0x1, %rsi
movl 0x20(%rbp), %edx
subl $0x4, %edx
movl $0x4043333, %edi        # imm = 0x4043333
leaq 0x3a7a4(%rip), %rcx     # 0x640f9
callq 0x5ed0
movq -0x28(%rbp), %rsi
leaq 0x3b195(%rip), %rdi     # 0x64afa
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x29a15
movq -0x48(%rbp), %rsi
subq $0x1, %rsi
movl 0x20(%rbp), %edx
movl $0x4043333, %edi        # imm = 0x4043333
leaq 0x3a76b(%rip), %rcx     # 0x640f9
callq 0x5ed0
cmpq $0x0, -0x78(%rbp)
je 0x299a7
movq -0x78(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x299ba
leaq 0x3ddac(%rip), %rdi     # 0x6775a
callq 0x32a0
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rsi
leaq 0x413a6(%rip), %rdi     # 0x6ad76
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
movq -0x18(%rbp), %rsi
subq $0x4, %rsi
movl 0x20(%rbp), %edx
movl $0x4043333, %edi        # imm = 0x4043333
leaq 0x3a705(%rip), %rcx     # 0x640f9
callq 0x5ed0
movq -0x78(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq 0x41375(%rip), %rdi     # 0x6ad7d
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x29ac6
cmpl $0x0, 0x18(%rbp)
jne 0x29ac4
movq -0x18(%rbp), %rsi
subq $0x1, %rsi
movl 0x20(%rbp), %edx
movl $0x4043333, %edi        # imm = 0x4043333
leaq 0x3a6be(%rip), %rcx     # 0x640f9
callq 0x5ed0
leaq 0x4d739(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x3003, %rax           # imm = 0x3003
cmpq $0x0, %rax
je 0x29a96
leaq 0x4d723(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40, %rax
cmpq $0x0, %rax
je 0x29a82
movq -0x28(%rbp), %rsi
leaq 0x3e104(%rip), %rdi     # 0x67b79
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
leaq 0x41307(%rip), %rdi     # 0x6ad90
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
leaq 0x4d6e3(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x30, %rax
cmpq $0x0, %rax
je 0x29ac2
movq -0x40(%rbp), %rsi
leaq 0x412d3(%rip), %rdi     # 0x6ad88
movb $0x0, %al
callq 0x3110
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x29ac4
jmp 0x29ac6
movl -0x80(%rbp), %edi
callq 0x1ef50
movl %eax, -0x80(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x29ae1
movq -0x38(%rbp), %rdi
callq 0x3040
cmpq $0x0, -0x78(%rbp)
je 0x29af1
movq -0x78(%rbp), %rdi
callq 0x3040
movq -0x48(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nop