// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/pngrtran.c
// Function: png_build_gamma_table
void /* PRIVATE */
png_build_gamma_table(png_structp png_ptr, png_byte bit_depth)
{
  png_debug(1, "in png_build_gamma_table");

  if (bit_depth <= 8)
  {
     int i;
     double g;

     if (png_ptr->screen_gamma > .000001)
        g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);

     else
        g = 1.0;

     png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
        (png_uint_32)256);

     for (i = 0; i < 256; i++)
     {
        png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
           g) * 255.0 + .5);
     }

#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
   defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
     if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
     {

        g = 1.0 / (png_ptr->gamma);

        png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
           (png_uint_32)256);

        for (i = 0; i < 256; i++)
        {
           png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
              g) * 255.0 + .5);
        }


        png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
           (png_uint_32)256);

        if (png_ptr->screen_gamma > 0.000001)
           g = 1.0 / png_ptr->screen_gamma;

        else
           g = png_ptr->gamma;   /* Probably doing rgb_to_gray */

        for (i = 0; i < 256; i++)
        {
           png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
              g) * 255.0 + .5);

        }
     }
#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  }
  else
  {
     double g;
     int i, j, shift, num;
     int sig_bit;
     png_uint_32 ig;

     if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
     {
        sig_bit = (int)png_ptr->sig_bit.red;

        if ((int)png_ptr->sig_bit.green > sig_bit)
           sig_bit = png_ptr->sig_bit.green;

        if ((int)png_ptr->sig_bit.blue > sig_bit)
           sig_bit = png_ptr->sig_bit.blue;
     }
     else
     {
        sig_bit = (int)png_ptr->sig_bit.gray;
     }

     if (sig_bit > 0)
        shift = 16 - sig_bit;

     else
        shift = 0;

     if (png_ptr->transformations & PNG_16_TO_8)
     {
        if (shift < (16 - PNG_MAX_GAMMA_8))
           shift = (16 - PNG_MAX_GAMMA_8);
     }

     if (shift > 8)
        shift = 8;

     if (shift < 0)
        shift = 0;

     png_ptr->gamma_shift = (png_byte)shift;

     num = (1 << (8 - shift));

     if (png_ptr->screen_gamma > .000001)
        g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
     else
        g = 1.0;

     png_ptr->gamma_16_table = (png_uint_16pp)png_calloc(png_ptr,
        (png_uint_32)(num * png_sizeof(png_uint_16p)));

     if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
     {
        double fin, fout;
        png_uint_32 last, max;

        for (i = 0; i < num; i++)
        {
           png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
              (png_uint_32)(256 * png_sizeof(png_uint_16)));
        }

        g = 1.0 / g;
        last = 0;
        for (i = 0; i < 256; i++)
        {
           fout = ((double)i + 0.5) / 256.0;
           fin = pow(fout, g);
           max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
           while (last <= max)
           {
              png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
                 [(int)(last >> (8 - shift))] = (png_uint_16)(
                 (png_uint_16)i | ((png_uint_16)i << 8));
              last++;
           }
        }
        while (last < ((png_uint_32)num << 8))
        {
           png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
              [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
           last++;
        }
     }
     else
     {
        for (i = 0; i < num; i++)
        {
           png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
              (png_uint_32)(256 * png_sizeof(png_uint_16)));

           ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);

           for (j = 0; j < 256; j++)
           {
              png_ptr->gamma_16_table[i][j] =
                 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
                    65535.0, g) * 65535.0 + .5);
           }
        }
     }

#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
   defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
     if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
     {

        g = 1.0 / (png_ptr->gamma);

        png_ptr->gamma_16_to_1 = (png_uint_16pp)png_calloc(png_ptr,
           (png_uint_32)(num * png_sizeof(png_uint_16p )));

        for (i = 0; i < num; i++)
        {
           png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
              (png_uint_32)(256 * png_sizeof(png_uint_16)));

           ig = (((png_uint_32)i *
              (png_uint_32)png_gamma_shift[shift]) >> 4);
           for (j = 0; j < 256; j++)
           {
              png_ptr->gamma_16_to_1[i][j] =
                 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
                    65535.0, g) * 65535.0 + .5);
           }
        }

        if (png_ptr->screen_gamma > 0.000001)
           g = 1.0 / png_ptr->screen_gamma;

        else
           g = png_ptr->gamma;   /* Probably doing rgb_to_gray */

        png_ptr->gamma_16_from_1 = (png_uint_16pp)png_calloc(png_ptr,
           (png_uint_32)(num * png_sizeof(png_uint_16p)));

        for (i = 0; i < num; i++)
        {
           png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
              (png_uint_32)(256 * png_sizeof(png_uint_16)));

           ig = (((png_uint_32)i *
              (png_uint_32)png_gamma_shift[shift]) >> 4);

           for (j = 0; j < 256; j++)
           {
              png_ptr->gamma_16_from_1[i][j] =
                 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
                    65535.0, g) * 65535.0 + .5);
           }
        }
     }
#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
cmpb $0x8, %sil
ja 0x80e0f
movss 0x290(%rbx), %xmm0
cvtss2sd %xmm0, %xmm1
ucomisd 0x123f3(%rip), %xmm1    # 0x931e0
jbe 0x80e27
mulss 0x28c(%rbx), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x12205(%rip), %xmm1    # 0x93008
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x80e35
testb $0x2, 0x24e(%rbx)
jne 0x80f64
movb 0x2cb(%rbx), %al
jmp 0x80f82
movsd 0x121d9(%rip), %xmm0    # 0x93008
movsd %xmm0, 0x8(%rsp)
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdi
callq 0x848bb
movq %rax, 0x298(%rbx)
xorl %r14d, %r14d
cmpq $0x100, %r14            # imm = 0x100
je 0x80e95
cvtsi2sd %r14d, %xmm0
movsd 0x123b6(%rip), %xmm1    # 0x93218
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xe800
mulsd 0x1239f(%rip), %xmm0    # 0x93218
addsd 0x1218f(%rip), %xmm0    # 0x93010
cvttsd2si %xmm0, %eax
movq 0x298(%rbx), %rcx
movb %al, (%rcx,%r14)
incq %r14
jmp 0x80e4c
testl $0x600080, 0x124(%rbx)  # imm = 0x600080
je 0x81418
cvtss2sd 0x28c(%rbx), %xmm0
movsd 0x12153(%rip), %xmm1    # 0x93008
movsd %xmm1, 0x8(%rsp)
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdi
callq 0x848bb
movq %rax, 0x2a8(%rbx)
xorl %r14d, %r14d
cmpq $0x100, %r14            # imm = 0x100
je 0x80f25
cvtsi2sd %r14d, %xmm0
movsd 0x12326(%rip), %xmm1    # 0x93218
divsd %xmm1, %xmm0
movsd 0x10(%rsp), %xmm1
callq 0xe800
mulsd 0x1230f(%rip), %xmm0    # 0x93218
addsd 0x120ff(%rip), %xmm0    # 0x93010
cvttsd2si %xmm0, %eax
movq 0x2a8(%rbx), %rcx
movb %al, (%rcx,%r14)
incq %r14
jmp 0x80edc
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdi
callq 0x848bb
movq %rax, 0x2a0(%rbx)
cvtss2sd 0x290(%rbx), %xmm0
ucomisd 0x12297(%rip), %xmm0    # 0x931e0
jbe 0x81306
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x81314
movl 0x2c8(%rbx), %eax
movzbl 0x2c9(%rbx), %ecx
cmpb %al, %cl
cmoval %ecx, %eax
movzbl 0x2ca(%rbx), %ecx
cmpb %al, %cl
cmoval %ecx, %eax
movzbl %al, %eax
pushq $0x10
popq %rcx
subl %eax, %ecx
xorl %edx, %edx
testb %al, %al
cmovel %edx, %ecx
cmpl $0x6, %ecx
pushq $0x5
popq %r13
cmovgel %ecx, %r13d
btl $0xa, 0x124(%rbx)
cmovael %ecx, %r13d
pushq $0x8
popq %r15
cmpl %r15d, %r13d
cmovgel %r15d, %r13d
testl %r13d, %r13d
cmovlel %edx, %r13d
movl %r13d, 0x288(%rbx)
movl %r15d, %ebp
subl %r13d, %ebp
pushq $0x1
popq %r14
movl %ebp, %ecx
shll %cl, %r14d
movss 0x290(%rbx), %xmm0
cvtss2sd %xmm0, %xmm1
ucomisd 0x121fc(%rip), %xmm1    # 0x931e0
jbe 0x81006
mulss 0x28c(%rbx), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x1200e(%rip), %xmm1    # 0x93008
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x81014
movsd 0x11ffa(%rip), %xmm0    # 0x93008
movsd %xmm0, 0x8(%rsp)
movl %ebp, %ecx
shll %cl, %r15d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8489d
movq %rax, 0x2b0(%rbx)
movzwl 0x124(%rbx), %eax
movl %r14d, %r12d
movl %r13d, %ecx
movq %rcx, 0x18(%rsp)
testw $0x480, %ax             # imm = 0x480
movq %r12, 0x28(%rsp)
movq %r15, 0x20(%rsp)
je 0x81268
xorl %r14d, %r14d
cmpq %r14, %r12
je 0x81076
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
callq 0x848bb
movq 0x2b0(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
jmp 0x81054
movsd 0x11f8a(%rip), %xmm0    # 0x93008
divsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movl $0x100, %r14d           # imm = 0x100
movl %ebp, %ecx
shll %cl, %r14d
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x30(%rsp)
movl $0xff, %r15d
movl %r13d, %ecx
shrl %cl, %r15d
xorl %r12d, %r12d
xorpd %xmm0, %xmm0
xorl %r13d, %r13d
cmpl $0x100, %r12d           # imm = 0x100
je 0x81156
movsd %xmm0, 0x8(%rsp)
addsd 0x11f3f(%rip), %xmm0    # 0x93010
mulsd 0x1ca7f(%rip), %xmm0    # 0x9db58
movsd 0x10(%rsp), %xmm1
callq 0xe800
mulsd 0x30(%rsp), %xmm0
cvttsd2si %xmm0, %rax
imull $0x101, %r12d, %edx     # imm = 0x101
cmpl %eax, %r13d
ja 0x81120
movq 0x2b0(%rbx), %rsi
movl %r13d, %edi
andl %r15d, %edi
movl %r13d, %r8d
movl %ebp, %ecx
shrl %cl, %r8d
movq (%rsi,%rdi,8), %rcx
movslq %r8d, %rsi
movw %dx, (%rcx,%rsi,2)
incl %r13d
jmp 0x810f6
movsd 0x8(%rsp), %xmm0
addsd 0x11eda(%rip), %xmm0    # 0x93008
incl %r12d
jmp 0x810b6
movq 0x2b0(%rbx), %rax
movl %r13d, %ecx
andl %r15d, %ecx
movq (%rax,%rcx,8), %rax
movl %r13d, %edx
movl %ebp, %ecx
shrl %cl, %edx
movslq %edx, %rcx
orw $-0x1, (%rax,%rcx,2)
incl %r13d
cmpl %r14d, %r13d
jb 0x81133
testl $0x600080, 0x124(%rbx)  # imm = 0x600080
movq 0x28(%rsp), %r13
je 0x81418
cvtss2sd 0x28c(%rbx), %xmm0
movsd 0x11e88(%rip), %xmm1    # 0x93008
movsd %xmm1, 0x8(%rsp)
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
callq 0x8489d
movq %rax, 0x2c0(%rbx)
xorl %r14d, %r14d
leaq 0x1cac2(%rip), %r15     # 0x9dc70
cmpq %r13, %r14
je 0x8123d
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
callq 0x848bb
movq 0x2c0(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
movq 0x18(%rsp), %rax
movl (%r15,%rax,4), %ebp
imull %r14d, %ebp
shrl $0x4, %ebp
xorl %r12d, %r12d
cmpq $0x100, %r12            # imm = 0x100
je 0x81235
cvtsi2sd %ebp, %xmm0
movsd 0x190e1(%rip), %xmm1    # 0x9a2d8
divsd %xmm1, %xmm0
movsd 0x10(%rsp), %xmm1
callq 0xe800
mulsd 0x190ca(%rip), %xmm0    # 0x9a2d8
addsd 0x11dfa(%rip), %xmm0    # 0x93010
cvttsd2si %xmm0, %eax
movq 0x2c0(%rbx), %rcx
movq (%rcx,%r14,8), %rcx
movw %ax, (%rcx,%r12,2)
incq %r12
addl $0x100, %ebp            # imm = 0x100
jmp 0x811e2
incq %r14
jmp 0x811ae
cvtss2sd 0x290(%rbx), %xmm0
ucomisd 0x11f93(%rip), %xmm0    # 0x931e0
jbe 0x81364
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x81372
xorl %r14d, %r14d
leaq 0x1c9fe(%rip), %r15     # 0x9dc70
cmpq %r12, %r14
je 0x8115b
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
callq 0x848bb
movq 0x2b0(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
movq 0x18(%rsp), %rax
movl (%r15,%rax,4), %ebp
imull %r14d, %ebp
shrl $0x4, %ebp
xorl %r12d, %r12d
cmpq $0x100, %r12            # imm = 0x100
je 0x812f9
cvtsi2sd %ebp, %xmm0
movsd 0x1901d(%rip), %xmm1    # 0x9a2d8
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xe800
mulsd 0x19006(%rip), %xmm0    # 0x9a2d8
addsd 0x11d36(%rip), %xmm0    # 0x93010
cvttsd2si %xmm0, %eax
movq 0x2b0(%rbx), %rcx
movq (%rcx,%r14,8), %rcx
movw %ax, (%rcx,%r12,2)
incq %r12
addl $0x100, %ebp            # imm = 0x100
jmp 0x812a6
incq %r14
movq 0x28(%rsp), %r12
jmp 0x81272
cvtss2sd 0x28c(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %r14d, %r14d
cmpq $0x100, %r14            # imm = 0x100
je 0x81418
cvtsi2sd %r14d, %xmm0
movsd 0x11ee7(%rip), %xmm1    # 0x93218
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xe800
mulsd 0x11ed0(%rip), %xmm0    # 0x93218
addsd 0x11cc0(%rip), %xmm0    # 0x93010
cvttsd2si %xmm0, %eax
movq 0x2a0(%rbx), %rcx
movb %al, (%rcx,%r14)
incq %r14
jmp 0x81317
cvtss2sd 0x28c(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
callq 0x8489d
movq %rax, 0x2b8(%rbx)
xorl %r14d, %r14d
cmpq %r13, %r14
je 0x81418
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
callq 0x848bb
movq 0x2b8(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
movq 0x18(%rsp), %rax
movl (%r15,%rax,4), %ebp
imull %r14d, %ebp
shrl $0x4, %ebp
xorl %r12d, %r12d
cmpq $0x100, %r12            # imm = 0x100
je 0x81410
cvtsi2sd %ebp, %xmm0
movsd 0x18f06(%rip), %xmm1    # 0x9a2d8
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xe800
mulsd 0x18eef(%rip), %xmm0    # 0x9a2d8
addsd 0x11c1f(%rip), %xmm0    # 0x93010
cvttsd2si %xmm0, %eax
movq 0x2b8(%rbx), %rcx
movq (%rcx,%r14,8), %rcx
movw %ax, (%rcx,%r12,2)
incq %r12
addl $0x100, %ebp            # imm = 0x100
jmp 0x813bd
incq %r14
jmp 0x81389
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq