// File: /workspace/github_c_makefile_star2_O2/hfiguiere[P]exifprobe/mrw.c
// Function: process_mrw
unsigned long
process_mrw(FILE *inptr,unsigned long offset,unsigned long data_offset,
            unsigned long data_length,struct image_summary *summary_entry,
            char *parent_name,int indent)
{
    char *blockname;
    char *fulldirname = CNULL;
    struct fileheader *header;
    unsigned long blocklength,blockid;
    unsigned long ifd_offset;
    unsigned long max_offset = 0UL;
    int chpr = 0;
    int status = 0;

    if(inptr && data_offset)
    {
        if((summary_entry == NULL) || summary_entry->entry_lock)
            summary_entry = new_summary_entry(summary_entry,0,IMGFMT_MRW);
        if(summary_entry)
        {
            /* This isn't strictly necessary, because we're going to  */
            /* do it again at the end, but allows the TIFF processor  */
            /* to avoid changing this stuff if it notices they're     */
            /* already set.                                           */
            if(summary_entry->length <= 0)
                summary_entry->length = data_length;
            if(summary_entry->offset <= 0)
                summary_entry->offset = data_offset;
            summary_entry->imageformat = IMGFMT_MRW;
            summary_entry->imagesubformat = IMGSUBFMT_CFA;
            /* Don't lock it here; the TIFF processor should use it   */
            /* (and lock it)                                          */
        }
        chpr = newline(chpr);
        while(offset < data_offset)
        {
            blockid = read_ulong(inptr,TIFF_MOTOROLA,offset);
            blockname = read_string(inptr,offset+1,3);
            blocklength = read_ulong(inptr,TIFF_MOTOROLA,HERE);
            print_tag_address(SECTION,offset,indent,"@");
            if(blockid != MRM_PAD)
                offset += 8;
            if((PRINT_SECTION))
            {
                chpr += printf("{%s} (%#lx) length %lu starting at offset %#lx/%lu",blockname,
                                                        blockid,blocklength,offset,offset);
                chpr = newline(chpr);
            }

            if(Debug)
            {
                chpr = newline(chpr);
                hexdump(inptr,offset,48,48,16,0,0);
                chpr = newline(1);
            }
            switch(blockid)
            {
                case MRM_PRD:
                    max_offset = process_prd(inptr,offset,blocklength,summary_entry,indent);
                    offset += blocklength;
                    break;
                case MRM_TTW:
                    header = read_imageheader(inptr,offset);
                    if(header && (header->probe_magic == PROBE_TIFFMAGIC))
                    {
                        ifd_offset = read_ulong(inptr,header->file_marker,HERE); 
                        if(PRINT_SECTION)
                        {
                            print_tag_address(SECTION,offset,indent + 4,"@");
                            status = print_header(header,SECTION);
                            chpr += printf(" ifd offset = %#lx/%lu)",ifd_offset,ifd_offset);
                            if(offset)
                            {
                                chpr += printf(" (+ %lu = %#lx/%lu)",offset,offset + ifd_offset,
                                                                            offset + ifd_offset);
                            }
                            chpr = newline(chpr);
                        }
                        fulldirname = splice(parent_name,".",blockname);
                        max_offset = process_tiff_ifd(inptr,header->file_marker,
                                            ifd_offset,offset,offset + blocklength,summary_entry,
                                            fulldirname,TIFF_IFD,0,-1,indent + 4);
                        if(max_offset > 0L)
                            status = 0;
                        max_offset = offset + blocklength;
                        fflush(stdout);
                        if(fulldirname)
                            free(fulldirname);
                        fulldirname = CNULL;
                    }
                    else
                        chpr += printf(" NOT A TIFF HEADER");
                    offset += blocklength;
                    break;
                case MRM_WBG:
                    max_offset = process_wbg(inptr,offset,blocklength,summary_entry,indent);
                    offset += blocklength;
                    break;
                case MRM_RIF:
                    max_offset = process_rif(inptr,offset,blocklength,summary_entry,indent);
                    offset += blocklength;
                    break;
                case MRM_PAD:
                    offset += blocklength;
                    max_offset = offset;
                    break;
                default:
                    offset += blocklength;
                    max_offset = offset - 8;
                    break;
            }
            chpr = newline(0);
            if((PRINT_SECTION))
            {
                print_tag_address(SECTION,max_offset - 1,indent,"@");
                chpr += printf("{/%s}",blockname ? blockname : "UNK");
            }
            chpr = newline(chpr);
        }
        if((PRINT_SECTION))
        {
            print_tag_address(SECTION,data_offset,indent,"@");
            chpr += printf("MRW (CFA) data length %lu",data_length);
            chpr = newline(chpr);
            dumpsection(inptr,data_offset,data_length,indent + SMALLINDENT);
            print_tag_address(SECTION,data_offset + data_length - 1,indent,"@");
            chpr += printf("End of MRW data");
        }
        chpr = newline(chpr);
        /* Fix up any damage done by the TIFF IFD...                  */
        /* This information supercedes anything the TIFF processor    */
        /* may have done...image processing software can trash the    */
        /* TIFF structure (and some do), but this is basic            */
        /* information from the MRW header.                           */
        if(summary_entry)
        {
            summary_entry->length = data_length;
            summary_entry->offset = data_offset;
            summary_entry->imageformat = IMGFMT_MRW;
            summary_entry->imagesubformat = IMGSUBFMT_CFA;
            /* The TIFF processor should have locked it, but make     */
            /* sure                                                   */
            summary_entry->entry_lock = lock_number(summary_entry);
        }
    }
    return(data_offset + data_length);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x50(%rsp)
movq %rcx, %rbx
movq %rdx, %r12
movq %rdi, 0x8(%rsp)
testq %rdi, %rdi
sete %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
jne 0x24889
movq %rsi, %rbp
movl 0x90(%rsp), %r13d
testq %r8, %r8
movq %rbx, 0x30(%rsp)
je 0x243ca
cmpl $0x0, 0x10(%r8)
je 0x243e1
movq %r8, %rdi
xorl %esi, %esi
movl $0x4d524d, %edx         # imm = 0x4D524D
callq 0xef13
movq %rax, %r8
testq %rax, %rax
je 0x24428
cmpq $0x0, 0x98(%r8)
jne 0x243f2
movq %rbx, 0x98(%r8)
cmpq $0x0, 0x90(%r8)
jne 0x24403
movq %r12, 0x90(%r8)
movq $0x4d524d, 0x80(%r8) # imm = 0x4D524D
movq %r8, 0x20(%rsp)
movq $0x18023, 0x88(%r8) # imm = 0x18023
movl $0x0, 0x18(%rsp)
jmp 0x24437
movb $0x1, %al
movl %eax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
xorl %edi, %edi
callq 0x160f7
movl %eax, %edi
leal 0x4(%r13), %eax
movq %rax, 0x38(%rsp)
movq $0x0, 0x10(%rsp)
movq %r12, 0x28(%rsp)
cmpq %r12, %rbp
jae 0x247ac
movl %edi, 0x1c(%rsp)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movq %rbp, %rdx
callq 0x42ba
movq %rax, %r12
leaq 0x1(%rbp), %rsi
movq %rbx, %rdi
pushq $0x3
popq %rdx
callq 0x45bd
movq %rax, %r15
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x42ba
movq %rax, %rbx
movl $0x40000, %edi          # imm = 0x40000
movq %rbp, %rsi
movl %r13d, %edx
leaq 0x1ac27(%rip), %rcx     # 0x3f0dc
callq 0x5100
leaq 0x8(%rbp), %r13
cmpq $0x504144, %r12         # imm = 0x504144
movq %r13, %r14
movq %rbp, 0x40(%rsp)
cmoveq %rbp, %r13
leaq 0x32ca8(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
movq %r15, 0x48(%rsp)
jne 0x244ec
movq %rbx, %rbp
movl 0x1c(%rsp), %edi
jmp 0x24519
leaq 0x22e9a(%rip), %rdi     # 0x4738d
movq %r15, %rsi
movq %r12, %rdx
movq %rbx, %rcx
movq %r13, %r8
movq %r13, %r9
xorl %eax, %eax
callq 0x3120
movl 0x1c(%rsp), %edi
addl %eax, %edi
callq 0x160f7
movl %eax, %edi
movq %rbx, %rbp
leaq 0x38150(%rip), %rax     # 0x5c670
cmpl $0x0, (%rax)
movq %r14, %rbx
je 0x24559
callq 0x160f7
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq %r13, %rsi
pushq $0x30
popq %rcx
movq %rcx, %rdx
pushq $0x10
popq %r8
xorl %r9d, %r9d
pushq $0x0
callq 0x6e93
popq %rax
popq %rcx
pushq $0x1
popq %rdi
callq 0x160f7
movl %eax, %edi
movl 0x90(%rsp), %r13d
cmpq $0x504144, %r12         # imm = 0x504144
je 0x24720
cmpq $0x574247, %r12         # imm = 0x574247
je 0x245b4
cmpq $0x524946, %r12         # imm = 0x524946
je 0x246ee
cmpq $0x545457, %r12         # imm = 0x545457
je 0x245c9
cmpq $0x505244, %r12         # imm = 0x505244
jne 0x2470b
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movq 0x20(%rsp), %rcx
movl %r13d, %r8d
callq 0x2489e
jmp 0x24701
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movl %r13d, %r8d
callq 0x2517e
jmp 0x24701
movl %edi, %r14d
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x3d98
testq %rax, %rax
je 0x24799
movq %rax, %r15
cmpq $0x2a, 0x8(%rax)
jne 0x24799
movzwl (%r15), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rdi
callq 0x42ba
movq %rax, %r12
leaq 0x32b73(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
je 0x24685
movl $0x40000, %edi          # imm = 0x40000
movq %rbx, %rsi
movq 0x38(%rsp), %rdx
leaq 0x1aab5(%rip), %rcx     # 0x3f0dc
callq 0x5100
movl $0x40000, %esi          # imm = 0x40000
movq %r15, %rdi
callq 0x4cd0
leaq 0x22d80(%rip), %rdi     # 0x473c0
movq %r12, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3120
movl %eax, %r13d
addl %r14d, %r13d
testq %rbx, %rbx
je 0x24675
movq %r12, %rcx
addq %rbx, %rcx
leaq 0x1ec1e(%rip), %rdi     # 0x43283
movq %rbx, %rsi
movq %rcx, %rdx
xorl %eax, %eax
callq 0x3120
addl %eax, %r13d
movl %r13d, %edi
callq 0x160f7
movl 0x90(%rsp), %r13d
movq 0x50(%rsp), %rdi
leaq 0x1b306(%rip), %rsi     # 0x3f997
movq 0x48(%rsp), %rdx
callq 0x16f1d
movq %rax, %r14
movzwl (%r15), %esi
addq %rbx, %rbp
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq %r12, %rdx
movq %rbx, %rcx
movq %rbp, %r8
movq 0x28(%rsp), %r9
pushq 0x40(%rsp)
pushq $-0x1
pushq $0x0
pushq $0x0
pushq %rax
callq 0xc004
addq $0x30, %rsp
movq 0x328f1(%rip), %rax     # 0x56fc8
movq (%rax), %rdi
callq 0x3200
movq %r14, %rdi
callq 0x3050
movq %rbp, 0x10(%rsp)
jmp 0x24730
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movl %r13d, %r8d
callq 0x25c11
movq %rax, 0x10(%rsp)
addq %rbx, %rbp
jmp 0x24730
addq %rbp, %rbx
movq 0x40(%rsp), %r15
addq %rbp, %r15
movq %r15, 0x10(%rsp)
movq %rbx, %rbp
jmp 0x24730
movq 0x40(%rsp), %rax
addq %rbp, %rax
movq %rax, %rbp
movq %rax, 0x10(%rsp)
xorl %edi, %edi
callq 0x160f7
movl %eax, %ebx
leaq 0x32a40(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
movq 0x28(%rsp), %r12
je 0x2478b
movq 0x10(%rsp), %rax
leaq -0x1(%rax), %rsi
movl $0x40000, %edi          # imm = 0x40000
movl %r13d, %edx
leaq 0x1a979(%rip), %rcx     # 0x3f0dc
callq 0x5100
movq 0x48(%rsp), %rsi
testq %rsi, %rsi
leaq 0x22c7a(%rip), %rax     # 0x473f1
cmoveq %rax, %rsi
leaq 0x22c69(%rip), %rdi     # 0x473eb
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl %ebx, %edi
callq 0x160f7
movl %eax, %edi
jmp 0x24457
leaq 0x22c38(%rip), %rdi     # 0x473d8
xorl %eax, %eax
callq 0x3120
jmp 0x24706
leaq 0x329cd(%rip), %rax     # 0x57180
testb $0x4, 0x2(%rax)
je 0x24843
leaq 0x1a918(%rip), %rbx     # 0x3f0dc
movl %edi, %ebp
movl $0x40000, %edi          # imm = 0x40000
movq %r12, %rsi
movl %r13d, %edx
movq %rbx, %rcx
callq 0x5100
leaq 0x22c15(%rip), %rdi     # 0x473f5
movq 0x30(%rsp), %r15
movq %r15, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x160f7
movl %eax, %ebp
leal 0x2(%r13), %ecx
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq %r15, %rdx
callq 0x90de
movq 0x28(%rsp), %rax
leaq (%r15,%rax), %rsi
decq %rsi
movl $0x40000, %edi          # imm = 0x40000
movl %r13d, %edx
movq %rbx, %rcx
callq 0x5100
leaq 0x22bdc(%rip), %rdi     # 0x4740f
xorl %eax, %eax
callq 0x3120
movl %eax, %edi
addl %ebp, %edi
movq 0x28(%rsp), %r12
callq 0x160f7
cmpb $0x0, 0x18(%rsp)
movq 0x30(%rsp), %rbx
movq 0x20(%rsp), %r14
jne 0x24889
movq %rbx, 0x98(%r14)
movq %r12, 0x90(%r14)
movq $0x4d524d, 0x80(%r14) # imm = 0x4D524D
movq $0x18023, 0x88(%r14) # imm = 0x18023
movq %r14, %rdi
callq 0xf126
movl %eax, 0x10(%r14)
addq %r12, %rbx
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq