// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %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 0x2564e
movq %r9, %r15
movq %rsi, %r13
testq %r8, %r8
je 0x25153
cmpl $0x0, 0x10(%r8)
je 0x25165
movq %r8, %rdi
xorl %esi, %esi
movl $0x4d524d, %edx         # imm = 0x4D524D
callq 0xfb61
movq %rax, %r8
testq %r8, %r8
je 0x251a2
cmpq $0x0, 0x98(%r8)
jne 0x2517b
movq %rbx, 0x98(%r8)
cmpq $0x0, 0x90(%r8)
jne 0x2518c
movq %r12, 0x90(%r8)
movq $0x4d524d, 0x80(%r8) # imm = 0x4D524D
movq $0x18023, 0x88(%r8) # imm = 0x18023
movq %r8, 0x20(%rsp)
movq %rbx, 0x38(%rsp)
movl 0x80(%rsp), %ebx
xorl %edi, %edi
callq 0x16b56
movl %eax, %r14d
cmpq %r12, %r13
jae 0x25572
movq %r15, 0x40(%rsp)
leal 0x4(%rbx), %eax
movq %rax, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq %r12, 0x10(%rsp)
movq 0x8(%rsp), %r15
movq %r15, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movq %r13, %rdx
callq 0x46cc
movq %rax, %r12
leaq 0x1(%r13), %rsi
movl $0x3, %edx
movq %r15, %rdi
callq 0x49e6
movq %rax, %rbp
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %r15, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x46cc
movq %rax, %rbx
movl $0x40000, %edi          # imm = 0x40000
movq %r13, %rsi
movl 0x80(%rsp), %edx
leaq 0x1bea4(%rip), %rcx     # 0x410dc
callq 0x5605
leaq 0x8(%r13), %r15
cmpq $0x504144, %r12         # imm = 0x504144
cmoveq %r13, %r15
leaq 0x32f2d(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
movq %rbp, 0x18(%rsp)
je 0x25289
leaq 0x24138(%rip), %rdi     # 0x4939d
movq %rbp, %rsi
movq %r12, %rdx
movq %rbx, %rcx
movq %r15, %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
movl %r14d, %edi
callq 0x16b56
movl %eax, %r14d
movq %rbx, %rbp
leaq 0x383dd(%rip), %rax     # 0x5d670
cmpl $0x0, (%rax)
je 0x252d7
movl %r14d, %edi
callq 0x16b56
subq $0x8, %rsp
movl $0x30, %edx
movl $0x30, %ecx
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movl $0x10, %r8d
xorl %r9d, %r9d
pushq $0x0
callq 0x7446
addq $0x10, %rsp
movl $0x1, %edi
callq 0x16b56
movl %eax, %r14d
cmpq $0x524945, %r12         # imm = 0x524945
jle 0x2531f
cmpq $0x524946, %r12         # imm = 0x524946
je 0x25366
cmpq $0x545457, %r12         # imm = 0x545457
je 0x25391
cmpq $0x574247, %r12         # imm = 0x574247
movq 0x18(%rsp), %rbx
jne 0x25454
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movl 0x80(%rsp), %r8d
callq 0x25f66
jmp 0x25358
cmpq $0x504144, %r12         # imm = 0x504144
movq 0x18(%rsp), %rbx
je 0x25449
cmpq $0x505244, %r12         # imm = 0x505244
jne 0x25454
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq 0x20(%rsp), %rcx
movl 0x80(%rsp), %r8d
callq 0x25663
movq %rax, %r14
addq %r15, %rbp
movq %rbp, %r13
jmp 0x25460
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %rbp, %rdx
movl 0x80(%rsp), %r8d
callq 0x269ef
movq %rax, %r14
addq %r15, %rbp
movq %rbp, %r13
movq 0x10(%rsp), %r12
jmp 0x25502
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x418c
testq %rax, %rax
je 0x2546a
movq %rax, %r12
cmpq $0x2a, 0x8(%rax)
jne 0x2546a
movzwl (%r12), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rdi
callq 0x46cc
movq %rax, %r13
leaq 0x32dad(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
movq 0x18(%rsp), %rbx
je 0x25488
movl $0x40000, %edi          # imm = 0x40000
movq %r15, %rsi
movq 0x30(%rsp), %rdx
leaq 0x1bce6(%rip), %rcx     # 0x410dc
callq 0x5605
movl $0x40000, %esi          # imm = 0x40000
movq %r12, %rdi
callq 0x5198
leaq 0x23fc1(%rip), %rdi     # 0x493d0
movq %r13, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3120
movq %r13, %rcx
movl %eax, %r13d
addl %r14d, %r13d
testq %r15, %r15
je 0x2547a
movq %rcx, %r14
addq %r15, %rcx
leaq 0x1fe4c(%rip), %rdi     # 0x45283
movq %r15, %rsi
movq %rcx, %rdx
xorl %eax, %eax
callq 0x3120
addl %eax, %r13d
jmp 0x2547d
addq %rbp, %r15
movq %r15, %r13
movq %r15, %r14
jmp 0x25460
leaq (%r15,%rbp), %r13
leaq (%r15,%rbp), %r14
addq $-0x8, %r14
movq 0x10(%rsp), %r12
jmp 0x25507
leaq 0x23f77(%rip), %rdi     # 0x493e8
xorl %eax, %eax
callq 0x3120
jmp 0x254f2
movq %rcx, %r14
movl %r13d, %edi
callq 0x16b56
movq %r14, %r13
movq 0x40(%rsp), %rdi
leaq 0x1c503(%rip), %rsi     # 0x41997
movq %rbx, %rdx
callq 0x17a47
movq %rax, %r14
movzwl (%r12), %esi
leaq (%r15,%rbp), %r8
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq %r13, %rdx
movq %r15, %rcx
movq %r8, 0x30(%rsp)
movq 0x28(%rsp), %r9
pushq 0x38(%rsp)
pushq $-0x1
xorl %eax, %eax
pushq %rax
pushq %rax
pushq %r14
callq 0xc93c
addq $0x30, %rsp
movq 0x32aeb(%rip), %rax     # 0x57fc8
movq (%rax), %rdi
callq 0x3200
testq %r14, %r14
je 0x254f2
movq %r14, %rdi
callq 0x3050
movq 0x10(%rsp), %r12
addq %rbp, %r15
movq %r15, %r13
movq 0x28(%rsp), %r14
movq 0x18(%rsp), %rbx
xorl %edi, %edi
callq 0x16b56
movl %eax, %ebp
leaq 0x32c69(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x2555a
leaq -0x1(%r14), %rsi
movl $0x40000, %edi          # imm = 0x40000
movl 0x80(%rsp), %edx
leaq 0x1bba8(%rip), %rcx     # 0x410dc
callq 0x5605
testq %rbx, %rbx
leaq 0x23ebe(%rip), %rax     # 0x49401
cmoveq %rax, %rbx
leaq 0x23ead(%rip), %rdi     # 0x493fb
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movq %r14, 0x28(%rsp)
movl %ebp, %edi
callq 0x16b56
movl %eax, %r14d
cmpq %r12, %r13
jb 0x251e1
leaq 0x32c07(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x25607
leaq 0x1bb52(%rip), %rbx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq %r12, %rsi
movl 0x80(%rsp), %r13d
movl %r13d, %edx
movq %rbx, %rcx
callq 0x5605
leaq 0x23e59(%rip), %rdi     # 0x49405
movq 0x38(%rsp), %r15
movq %r15, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
movl %r14d, %edi
callq 0x16b56
movl %eax, %ebp
leal 0x2(%r13), %ecx
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x9745
leaq (%r15,%r12), %rsi
decq %rsi
movl $0x40000, %edi          # imm = 0x40000
movl %r13d, %edx
movq %rbx, %rcx
callq 0x5605
leaq 0x23e25(%rip), %rdi     # 0x4941f
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
addl %ebp, %r14d
movl %r14d, %edi
callq 0x16b56
movq 0x20(%rsp), %r14
testq %r14, %r14
movq 0x38(%rsp), %rbx
je 0x2564e
movq %rbx, 0x98(%r14)
movq %r12, 0x90(%r14)
movq $0x4d524d, 0x80(%r14) # imm = 0x4D524D
movq $0x18023, 0x88(%r14) # imm = 0x18023
movq %r14, %rdi
callq 0xfdbf
movl %eax, 0x10(%r14)
addq %r12, %rbx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq