// File: /workspace/github_c_makefile_star2_O3/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 %rcx, %rbx
movq %rdx, %r12
movq %rdi, 0x8(%rsp)
testq %rdi, %rdi
sete %al
testq %rdx, %rdx
sete %cl
orb %al, %cl
jne 0x25d06
movq %rsi, %r13
movq %r9, 0x40(%rsp)
testq %r8, %r8
je 0x2581d
cmpl $0x0, 0x10(%r8)
je 0x25834
movq %r8, %rdi
xorl %esi, %esi
movl $0x4d524d, %edx         # imm = 0x4D524D
callq 0xfc85
movq %rax, %r8
testq %rax, %rax
je 0x25876
cmpq $0x0, 0x98(%r8)
jne 0x25845
movq %rbx, 0x98(%r8)
cmpq $0x0, 0x90(%r8)
jne 0x25856
movq %r12, 0x90(%r8)
movq $0x4d524d, 0x80(%r8) # imm = 0x4D524D
movq $0x18023, 0x88(%r8) # imm = 0x18023
movl $0x0, 0x18(%rsp)
jmp 0x2587f
movb $0x1, %al
movl %eax, 0x18(%rsp)
xorl %r8d, %r8d
movq %r8, 0x20(%rsp)
movq %rbx, 0x30(%rsp)
movl 0x90(%rsp), %ebp
xorl %edi, %edi
callq 0x1707a
movl %eax, %r14d
cmpq %r12, %r13
jae 0x25c32
leal 0x4(%rbp), %eax
movq %rax, 0x28(%rsp)
xorl %r15d, %r15d
movq %r12, 0x48(%rsp)
movq %r15, 0x50(%rsp)
movl %r14d, 0x1c(%rsp)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
movq %r13, %rdx
callq 0x4707
movq %rax, %r12
leaq 0x1(%r13), %rsi
movl $0x3, %edx
movq %rbx, %rdi
callq 0x4a17
movq %rax, %r14
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rbx, %rdi
movl $0x4d4d, %esi           # imm = 0x4D4D
callq 0x4707
movq %rax, %rbx
movl $0x40000, %edi          # imm = 0x40000
movq %r13, %rsi
movl %ebp, %edx
leaq 0x1b7cd(%rip), %rcx     # 0x410dc
callq 0x55eb
leaq 0x8(%r13), %rbp
cmpq $0x504144, %r12         # imm = 0x504144
movq %rbp, %r15
movq %r13, 0x38(%rsp)
cmoveq %r13, %rbp
leaq 0x3284e(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
movq %r14, 0x10(%rsp)
jne 0x25947
movq %rbx, %r13
movl 0x1c(%rsp), %r14d
jmp 0x25975
leaq 0x23a8f(%rip), %rdi     # 0x493dd
movq %r14, %rsi
movq %r12, %rdx
movq %rbx, %rcx
movq %rbp, %r8
movq %rbp, %r9
xorl %eax, %eax
callq 0x3120
movl 0x1c(%rsp), %edi
addl %eax, %edi
callq 0x1707a
movl %eax, %r14d
movq %rbx, %r13
leaq 0x37cf4(%rip), %rax     # 0x5d670
cmpl $0x0, (%rax)
movq %r15, %rbx
je 0x259c3
movl %r14d, %edi
callq 0x1707a
subq $0x8, %rsp
movl $0x30, %edx
movl $0x30, %ecx
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
movl $0x10, %r8d
xorl %r9d, %r9d
pushq $0x0
callq 0x7480
addq $0x10, %rsp
movl $0x1, %edi
callq 0x1707a
movl %eax, %r14d
movl 0x90(%rsp), %ebp
cmpq $0x524945, %r12         # imm = 0x524945
jle 0x25a0d
cmpq $0x524946, %r12         # imm = 0x524946
je 0x25a4c
cmpq $0x545457, %r12         # imm = 0x545457
je 0x25a6a
cmpq $0x574247, %r12         # imm = 0x574247
movq 0x10(%rsp), %r14
jne 0x25ba1
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %r8d
callq 0x2664a
jmp 0x25a41
cmpq $0x504144, %r12         # imm = 0x504144
movq 0x10(%rsp), %r14
je 0x25b91
cmpq $0x505244, %r12         # imm = 0x505244
jne 0x25ba1
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movq 0x20(%rsp), %rcx
movl %ebp, %r8d
callq 0x25d1b
movq %rax, %r15
addq %rbx, %r13
jmp 0x25bcc
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
movl %ebp, %r8d
callq 0x27153
movq %rax, %r15
addq %rbx, %r13
jmp 0x25b8a
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x41ac
testq %rax, %rax
je 0x25bb1
movq %rax, %r15
cmpq $0x2a, 0x8(%rax)
jne 0x25bb1
movzwl (%r15), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rdi
callq 0x4707
movq %rax, %r12
leaq 0x326d5(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x25b1f
movl $0x40000, %edi          # imm = 0x40000
movq %rbx, %rsi
movq 0x28(%rsp), %rdx
leaq 0x1b617(%rip), %rcx     # 0x410dc
callq 0x55eb
movl $0x40000, %esi          # imm = 0x40000
movq %r15, %rdi
callq 0x5158
leaq 0x23932(%rip), %rdi     # 0x49410
movq %r12, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3120
movl %eax, %ebp
addl %r14d, %ebp
testq %rbx, %rbx
je 0x25b11
movq %r12, %rcx
addq %rbx, %rcx
leaq 0x1f7c5(%rip), %rdi     # 0x452c7
movq %rbx, %rsi
movq %rcx, %rdx
xorl %eax, %eax
callq 0x3120
addl %eax, %ebp
movl %ebp, %edi
callq 0x1707a
movl 0x90(%rsp), %ebp
movq 0x40(%rsp), %rdi
leaq 0x1be6c(%rip), %rsi     # 0x41997
movq 0x10(%rsp), %rdx
callq 0x17f99
movq %rax, %r14
movzwl (%r15), %esi
addq %rbx, %r13
subq $0x8, %rsp
movq 0x10(%rsp), %rdi
movq %r12, %rdx
movq %rbx, %rcx
movq %r13, %r8
movq 0x28(%rsp), %r9
pushq 0x30(%rsp)
pushq $-0x1
xorl %eax, %eax
pushq %rax
pushq %rax
pushq %r14
callq 0xcabc
addq $0x30, %rsp
movq 0x32456(%rip), %rax     # 0x57fc8
movq (%rax), %rdi
callq 0x3200
testq %r14, %r14
je 0x25b87
movq %r14, %rdi
callq 0x3050
movq %r13, %r15
movq 0x10(%rsp), %r14
jmp 0x25bcc
movq 0x38(%rsp), %rax
addq %r13, %rax
movq %rax, %r13
movq %rax, %r15
jmp 0x25bcc
addq %r13, %rbx
movq 0x38(%rsp), %r15
addq %r13, %r15
movq %rbx, %r13
jmp 0x25bcc
leaq 0x23870(%rip), %rdi     # 0x49428
xorl %eax, %eax
callq 0x3120
addq %rbx, %r13
movq 0x10(%rsp), %r14
movq 0x50(%rsp), %r15
xorl %edi, %edi
callq 0x1707a
movl %eax, %ebx
leaq 0x325a4(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
movq 0x48(%rsp), %r12
je 0x25c1f
leaq -0x1(%r15), %rsi
movl $0x40000, %edi          # imm = 0x40000
movl %ebp, %edx
leaq 0x1b4e3(%rip), %rcx     # 0x410dc
callq 0x55eb
testq %r14, %r14
leaq 0x23839(%rip), %rax     # 0x49441
cmoveq %rax, %r14
leaq 0x23828(%rip), %rdi     # 0x4943b
movq %r14, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %ebx
movl %ebx, %edi
callq 0x1707a
movl %eax, %r14d
cmpq %r12, %r13
jb 0x258b3
leaq 0x32547(%rip), %rax     # 0x58180
testb $0x4, 0x2(%rax)
je 0x25cbd
leaq 0x1b496(%rip), %rbx     # 0x410dc
movl $0x40000, %edi          # imm = 0x40000
movq %r12, %rsi
movl %ebp, %edx
movq %rbx, %rcx
callq 0x55eb
leaq 0x237e6(%rip), %rdi     # 0x49445
movq 0x30(%rsp), %r15
movq %r15, %rsi
xorl %eax, %eax
callq 0x3120
addl %eax, %r14d
movl %r14d, %edi
callq 0x1707a
movq %rbp, %r14
movl %eax, %ebp
leal 0x2(%r14), %ecx
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x9870
leaq (%r15,%r12), %rsi
decq %rsi
movl $0x40000, %edi          # imm = 0x40000
movl %r14d, %edx
movq %rbx, %rcx
callq 0x55eb
leaq 0x237af(%rip), %rdi     # 0x4945f
xorl %eax, %eax
callq 0x3120
movl %eax, %r14d
addl %ebp, %r14d
movq 0x20(%rsp), %r15
movl %r14d, %edi
callq 0x1707a
cmpb $0x0, 0x18(%rsp)
movq 0x30(%rsp), %rbx
jne 0x25d06
movq %rbx, 0x98(%r15)
movq %r12, 0x90(%r15)
movq $0x4d524d, 0x80(%r15) # imm = 0x4D524D
movq $0x18023, 0x88(%r15) # imm = 0x18023
movq %r15, %rdi
callq 0xfee6
movl %eax, 0x10(%r15)
addq %r12, %rbx
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq