// File: /workspace/github_c_makefile_star2_O0/hfiguiere[P]exifprobe/maker_nikon.c
// Function: nikon_colorbalance
void
nikon_colorbalance(FILE *inptr,struct ifd_entry *entry_ptr,unsigned short byteorder,
                                            unsigned long fileoffset_base,int indent)
{
    unsigned long offset;
    unsigned short numerator,denominator;
    double value;
    int chpr = 0;
    int unknown = 0;
    char *id;

    if(entry_ptr && (PRINT_VALUE))
    {
        offset = entry_ptr->value + fileoffset_base;
#if 1
        id = read_string(inptr,offset,4);
        chpr += printf("'ID:");
        show_string(id,4,1);
        if(strncmp(id,"0100",4) == 0)
            offset += 72;
        else if(strncmp(id,"0102",4) == 0)
            offset += 10;
        else if(strncmp(id,"0103",4) == 0)
            offset += 20;
        else
            ++unknown;
        if(!unknown)
        {
            if((PRINT_SECTION))
            {
                indent += MAKERTAGWIDTH + 3;
                chpr += printf("' = {");
                chpr = newline(chpr);
                print_tag_address(ENTRY,offset,indent + MEDIUMINDENT,"?");
                chpr += printf("RedBalance**  = ");
                numerator = read_ushort(inptr,byteorder,offset);
                offset += 2;
                if(strncmp(id,"0100",4))
                {
                    denominator = read_ushort(inptr,byteorder,offset);
                    offset += 2;
                }
                else
                    denominator = 256;
                value = (double)numerator / (double)denominator;
                chpr += printf("%.6f (%u/%u)",value,numerator,denominator);
                chpr = newline(chpr);

                print_tag_address(ENTRY,offset,indent + MEDIUMINDENT,"?");
                chpr += printf("BlueBalance** = ");
                numerator = read_ushort(inptr,byteorder,offset);
                offset += 2;
                if(strncmp(id,"0100",4))
                {
                    denominator = read_ushort(inptr,byteorder,offset);
                    offset += 2;
                }
                else
                    denominator = 256;
                value = (double)numerator / (double)denominator;
                chpr += printf("%.6f (%u/%u)",value,numerator,denominator);
                chpr = newline(chpr);
                print_tag_address(ENTRY,offset + entry_ptr->count - 1,indent,"?");
                chpr += printf("} = {");
                indent -= MAKERTAGWIDTH + 3;
            }
            chpr = newline(chpr);
        }
        else
        {
            chpr += printf(" = unknown = {");
            chpr = newline(chpr);
        }
        offset = entry_ptr->value + fileoffset_base;
        PUSHCOLOR(RED);
        dumpsection(inptr,offset,entry_ptr->count,indent);
        POPCOLOR();
        print_tag_address(ENTRY,offset + entry_ptr->count - 1,indent,"?");
        chpr += printf("}");
    }
#else
/* This just prints everything after the idstring as short rationals, */
/* in the same fashion as print_ushort();                             */
        count = entry_ptr->count / 4;   /* two unsigned shorts        */
        print_ascii(inptr,4,offset);
        count--;
        offset += 4;
        chpr = newline(chpr);
        for(i = 0; i < count; ++i)
        {
            int rowlength;
            if((count -i) >= 4)
                rowlength = 4;
            else
                rowlength = count - i;
            print_tag_address(ENTRY,offset,indent,"?");
            for(j = 0; j < rowlength; ++j,++i)
            {
                numerator = read_ushort(inptr,byteorder,offset);
                denominator = read_ushort(inptr,byteorder,HERE);
                offset += 4;
                if(j)
                    chpr += printf(", ");
                if(j == 2)
                    chpr += printf("    ");
                if(numerator == 0)
                    chpr += printf("0     ");
                else if(denominator == 0)
                    chpr += printf("Inf   ");
                else
                {
                    value = (double)numerator / (double)denominator;
                    chpr += printf("%.4f",value);
                }
            }
            chpr = newline(chpr);
        }
    }
    if(Max_undefined > 0)
    {
        unsigned long dumplength;

        offset = entry_ptr->value + fileoffset_base;
        if((Max_undefined == DUMPALL) || (Max_undefined > entry_ptr->count))
            dumplength = entry_ptr->count;
        else 
            dumplength = Max_undefined;
        chpr = newline(chpr);
        hexdump(inptr,offset,entry_ptr->count,dumplength,16,
                    4,SUBINDENT);
        chpr = newline(1);
    }
#endif
    setcharsprinted(chpr);
}

/* Mark items (usually LONG) which should be treated as offsets.      */

int
maker_nikon_value_is_offset(struct ifd_entry *entry_ptr,int model)
{
    int is_offset = 0;

    /* There is currently no need for a switch on noteversion         */
    if(entry_ptr)
    {
        switch(entry_ptr->tag)
        {
            case 0x0011: is_offset = 1; break; 
            case 0x0097: is_offset = 1; break; 
            case 0x0100: is_offset = 1; break; 
            default: break;
        }
    }
    return(is_offset);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movw %dx, %ax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movw %ax, -0x12(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x40c37
leaq 0x36901(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x30, %rax
cmpq $0x0, %rax
je 0x40c37
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl $0x4, %edx
callq 0x4a00
movq %rax, -0x50(%rbp)
leaq 0x2c434(%rip), %rdi     # 0x6ccf1
movb $0x0, %al
callq 0x3110
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x50(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0xb600
movq -0x50(%rbp), %rdi
leaq 0x2c40e(%rip), %rsi     # 0x6ccf6
movl $0x4, %edx
callq 0x3080
cmpl $0x0, %eax
jne 0x40905
movq -0x30(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x30(%rbp)
jmp 0x40962
movq -0x50(%rbp), %rdi
leaq 0x2c3eb(%rip), %rsi     # 0x6ccfb
movl $0x4, %edx
callq 0x3080
cmpl $0x0, %eax
jne 0x4092d
movq -0x30(%rbp), %rax
addq $0xa, %rax
movq %rax, -0x30(%rbp)
jmp 0x40960
movq -0x50(%rbp), %rdi
leaq 0x2c3c8(%rip), %rsi     # 0x6cd00
movl $0x4, %edx
callq 0x3080
cmpl $0x0, %eax
jne 0x40955
movq -0x30(%rbp), %rax
addq $0x14, %rax
movq %rax, -0x30(%rbp)
jmp 0x4095e
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x40960
jmp 0x40962
cmpl $0x0, -0x48(%rbp)
jne 0x40bb8
leaq 0x3680d(%rip), %rax     # 0x77180
movq (%rax), %rax
andq $0x40000, %rax          # imm = 0x40000
cmpq $0x0, %rax
je 0x40bab
movl -0x24(%rbp), %eax
addl $0x1c, %eax
movl %eax, -0x24(%rbp)
leaq 0x2c36f(%rip), %rdi     # 0x6cd05
movb $0x0, %al
callq 0x3110
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %edi
callq 0x1ef50
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rsi
movl -0x24(%rbp), %edx
addl $0x4, %edx
movl $0x4003333, %edi        # imm = 0x4003333
leaq 0x2c1ee(%rip), %rcx     # 0x6cbb2
callq 0x5ed0
leaq 0x2c33b(%rip), %rdi     # 0x6cd0b
movb $0x0, %al
callq 0x3110
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movw -0x12(%rbp), %ax
movq -0x30(%rbp), %rdx
movzwl %ax, %esi
callq 0x4480
movw %ax, -0x32(%rbp)
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rdi
leaq 0x2c2ea(%rip), %rsi     # 0x6ccf6
movl $0x4, %edx
callq 0x3080
cmpl $0x0, %eax
je 0x40a41
movq -0x8(%rbp), %rdi
movw -0x12(%rbp), %ax
movq -0x30(%rbp), %rdx
movzwl %ax, %esi
callq 0x4480
movw %ax, -0x34(%rbp)
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
jmp 0x40a47
movw $0x100, -0x34(%rbp)     # imm = 0x100
movzwl -0x32(%rbp), %eax
cvtsi2sd %eax, %xmm0
movzwl -0x34(%rbp), %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movzwl -0x32(%rbp), %esi
movzwl -0x34(%rbp), %edx
leaq 0x2c2a8(%rip), %rdi     # 0x6cd1c
movb $0x1, %al
callq 0x3110
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %edi
callq 0x1ef50
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rsi
movl -0x24(%rbp), %edx
addl $0x4, %edx
movl $0x4003333, %edi        # imm = 0x4003333
leaq 0x2c110(%rip), %rcx     # 0x6cbb2
callq 0x5ed0
leaq 0x2c27b(%rip), %rdi     # 0x6cd29
movb $0x0, %al
callq 0x3110
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movw -0x12(%rbp), %ax
movq -0x30(%rbp), %rdx
movzwl %ax, %esi
callq 0x4480
movw %ax, -0x32(%rbp)
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rdi
leaq 0x2c20c(%rip), %rsi     # 0x6ccf6
movl $0x4, %edx
callq 0x3080
cmpl $0x0, %eax
je 0x40b1f
movq -0x8(%rbp), %rdi
movw -0x12(%rbp), %ax
movq -0x30(%rbp), %rdx
movzwl %ax, %esi
callq 0x4480
movw %ax, -0x34(%rbp)
movq -0x30(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x30(%rbp)
jmp 0x40b25
movw $0x100, -0x34(%rbp)     # imm = 0x100
movzwl -0x32(%rbp), %eax
cvtsi2sd %eax, %xmm0
movzwl -0x34(%rbp), %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
movzwl -0x32(%rbp), %esi
movzwl -0x34(%rbp), %edx
leaq 0x2c1ca(%rip), %rdi     # 0x6cd1c
movb $0x1, %al
callq 0x3110
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %edi
callq 0x1ef50
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rsi
subq $0x1, %rsi
movl -0x24(%rbp), %edx
movl $0x4003333, %edi        # imm = 0x4003333
leaq 0x2c029(%rip), %rcx     # 0x6cbb2
callq 0x5ed0
leaq 0x2c1a5(%rip), %rdi     # 0x6cd3a
movb $0x0, %al
callq 0x3110
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x24(%rbp), %eax
subl $0x1c, %eax
movl %eax, -0x24(%rbp)
movl -0x44(%rbp), %edi
callq 0x1ef50
movl %eax, -0x44(%rbp)
jmp 0x40bd7
leaq 0x2c181(%rip), %rdi     # 0x6cd40
movb $0x0, %al
callq 0x3110
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %edi
callq 0x1ef50
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movl -0x24(%rbp), %ecx
callq 0xbc60
movq -0x30(%rbp), %rsi
movq -0x10(%rbp), %rax
addq 0x8(%rax), %rsi
subq $0x1, %rsi
movl -0x24(%rbp), %edx
movl $0x4003333, %edi        # imm = 0x4003333
leaq 0x2bf94(%rip), %rcx     # 0x6cbb2
callq 0x5ed0
leaq 0x2aff5(%rip), %rdi     # 0x6bc1f
movb $0x0, %al
callq 0x3110
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %edi
callq 0x1ff00
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)