// File: /workspace/github_cpp_makefile_star2_O3/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 0x8e1e1
movss 0x290(%rbx), %xmm0
cvtss2sd %xmm0, %xmm1
ucomisd 0x14021(%rip), %xmm1    # 0xa21e0
jbe 0x8e1f9
mulss 0x28c(%rbx), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x13e63(%rip), %xmm1    # 0xa2038
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x8e207
testb $0x2, 0x24e(%rbx)
jne 0x8e340
movb 0x2cb(%rbx), %al
jmp 0x8e35e
movsd 0x13e37(%rip), %xmm0    # 0xa2038
movsd %xmm0, 0x8(%rsp)
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdi
callq 0x91fa8
movq %rax, 0x298(%rbx)
xorl %r14d, %r14d
movsd 0x13ff2(%rip), %xmm1    # 0xa2218
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xe7d0
movsd 0x13deb(%rip), %xmm2    # 0xa2030
movsd 0x13fcb(%rip), %xmm1    # 0xa2218
mulsd %xmm1, %xmm0
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
movq 0x298(%rbx), %rcx
movb %al, (%rcx,%r14)
incq %r14
cmpq $0x100, %r14            # imm = 0x100
jne 0x8e226
testl $0x600080, 0x124(%rbx)  # imm = 0x600080
je 0x8e819
xorps %xmm0, %xmm0
cvtss2sd 0x28c(%rbx), %xmm0
movsd 0x13da5(%rip), %xmm1    # 0xa2038
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdi
callq 0x91fa8
movsd 0x13f66(%rip), %xmm1    # 0xa2218
movq %rax, 0x2a8(%rbx)
xorl %r14d, %r14d
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xe7d0
movsd 0x13f3d(%rip), %xmm1    # 0xa2218
mulsd %xmm1, %xmm0
addsd 0x13d49(%rip), %xmm0    # 0xa2030
cvttsd2si %xmm0, %eax
movq 0x2a8(%rbx), %rcx
movb %al, (%rcx,%r14)
incq %r14
cmpq $0x100, %r14            # imm = 0x100
jne 0x8e2bc
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdi
callq 0x91fa8
movq %rax, 0x2a0(%rbx)
xorps %xmm0, %xmm0
cvtss2sd 0x290(%rbx), %xmm0
ucomisd 0x13eb7(%rip), %xmm0    # 0xa21e0
jbe 0x8e6f1
movsd 0x13d01(%rip), %xmm2    # 0xa2038
divsd %xmm0, %xmm2
jmp 0x8e6fc
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
movl $0x10, %ecx
subl %eax, %ecx
xorl %edx, %edx
testb %al, %al
cmovel %edx, %ecx
cmpl $0x6, %ecx
movl $0x5, %r15d
cmovgel %ecx, %r15d
btl $0xa, 0x124(%rbx)
cmovael %ecx, %r15d
movl $0x8, %esi
cmpl %esi, %r15d
cmovgel %esi, %r15d
testl %r15d, %r15d
cmovlel %edx, %r15d
movl %r15d, 0x288(%rbx)
movl $0x8, %ebp
subl %r15d, %ebp
movl $0x1, %r14d
movl %ebp, %ecx
shll %cl, %r14d
movss 0x290(%rbx), %xmm0
cvtss2sd %xmm0, %xmm1
ucomisd 0x13e17(%rip), %xmm1    # 0xa21e0
jbe 0x8e3eb
mulss 0x28c(%rbx), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x13c59(%rip), %xmm1    # 0xa2038
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x8e3f9
movsd 0x13c45(%rip), %xmm0    # 0xa2038
movsd %xmm0, 0x8(%rsp)
movl %ebp, %ecx
shll %cl, %esi
movq %rbx, %rdi
movq %rsi, 0x10(%rsp)
callq 0x91f8a
movq %rax, 0x2b0(%rbx)
movzwl 0x124(%rbx), %eax
movl %r14d, %r12d
movl %r15d, %ecx
movq %rcx, 0x30(%rsp)
xorl %r14d, %r14d
testl $0x480, %eax            # imm = 0x480
je 0x8e54c
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
callq 0x91fa8
movq 0x2b0(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
cmpq %r14, %r12
jne 0x8e431
movsd 0x13bdf(%rip), %xmm0    # 0xa2038
divsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movl $0x100, %eax            # imm = 0x100
movl %ebp, %ecx
shll %cl, %eax
movl %eax, 0x2c(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x18(%rsp)
movl $0xff, %r14d
movl %r15d, %ecx
shrl %cl, %r14d
xorpd %xmm0, %xmm0
xorl %r15d, %r15d
xorl %r13d, %r13d
movsd %xmm0, 0x8(%rsp)
addsd 0x13b8d(%rip), %xmm0    # 0xa2030
mulsd 0x1e9cd(%rip), %xmm0    # 0xace78
movsd 0x20(%rsp), %xmm1
callq 0xe7d0
mulsd 0x18(%rsp), %xmm0
cvttsd2si %xmm0, %rax
cmpl %eax, %r15d
ja 0x8e4f7
movl %r13d, %edx
shll $0x8, %edx
addl %r13d, %edx
movq 0x2b0(%rbx), %rsi
movl %r15d, %ecx
andl %r14d, %ecx
movq (%rsi,%rcx,8), %rdi
movl %r15d, %r8d
movl %ebp, %ecx
shrl %cl, %r8d
movslq %r8d, %rcx
movw %dx, (%rdi,%rcx,2)
incl %r15d
cmpl %eax, %r15d
jbe 0x8e4d6
movsd 0x8(%rsp), %xmm0
addsd 0x13b33(%rip), %xmm0    # 0xa2038
incl %r13d
cmpl $0x100, %r13d           # imm = 0x100
jne 0x8e495
movl 0x2c(%rsp), %edi
cmpl %edi, %r15d
jae 0x8e5e2
movq 0x2b0(%rbx), %rax
movl %r15d, %ecx
andl %r14d, %ecx
movq (%rax,%rcx,8), %rdx
movl %r15d, %esi
movl %ebp, %ecx
shrl %cl, %esi
movslq %esi, %rcx
movw $0xffff, (%rdx,%rcx,2)  # imm = 0xFFFF
incl %r15d
cmpl %r15d, %edi
jne 0x8e525
jmp 0x8e5e2
leaq 0x1ea3d(%rip), %r15     # 0xacf90
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
callq 0x91fa8
movsd 0x1adc0(%rip), %xmm1    # 0xa9328
movq 0x2b0(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
movq 0x30(%rsp), %rax
movl (%r15,%rax,4), %ebp
imull %r14d, %ebp
shrl $0x4, %ebp
xorl %r13d, %r13d
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xe7d0
movsd 0x1ad84(%rip), %xmm1    # 0xa9328
mulsd %xmm1, %xmm0
addsd 0x13a80(%rip), %xmm0    # 0xa2030
cvttsd2si %xmm0, %eax
movq 0x2b0(%rbx), %rcx
movq (%rcx,%r14,8), %rcx
movw %ax, (%rcx,%r13,2)
incq %r13
addl $0x100, %ebp            # imm = 0x100
cmpq $0x100, %r13            # imm = 0x100
jne 0x8e586
incq %r14
cmpq %r12, %r14
jne 0x8e553
testl $0x600080, 0x124(%rbx)  # imm = 0x600080
je 0x8e819
xorps %xmm0, %xmm0
cvtss2sd 0x28c(%rbx), %xmm0
movsd 0x13a33(%rip), %xmm1    # 0xa2038
movsd %xmm1, 0x8(%rsp)
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x91f8a
movq %rax, 0x2c0(%rbx)
xorl %r14d, %r14d
movq 0x30(%rsp), %rbp
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
callq 0x91fa8
movsd 0x1ace2(%rip), %xmm1    # 0xa9328
movq 0x2c0(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
leaq 0x1e938(%rip), %rax     # 0xacf90
movl (%rax,%rbp,4), %r13d
movl %r13d, 0x18(%rsp)
imull %r14d, %r13d
shrl $0x4, %r13d
xorl %r15d, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
divsd %xmm1, %xmm0
movsd 0x20(%rsp), %xmm1
callq 0xe7d0
movsd 0x1ac9d(%rip), %xmm1    # 0xa9328
mulsd %xmm1, %xmm0
addsd 0x13999(%rip), %xmm0    # 0xa2030
cvttsd2si %xmm0, %eax
movq 0x2c0(%rbx), %rcx
movq (%rcx,%r14,8), %rcx
movw %ax, (%rcx,%r15,2)
incq %r15
addl $0x100, %r13d           # imm = 0x100
cmpq $0x100, %r15            # imm = 0x100
jne 0x8e66c
incq %r14
cmpq %r12, %r14
jne 0x8e631
xorps %xmm0, %xmm0
cvtss2sd 0x290(%rbx), %xmm0
ucomisd 0x13b03(%rip), %xmm0    # 0xa21e0
jbe 0x8e75b
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x8e76c
xorps %xmm2, %xmm2
cvtss2sd 0x28c(%rbx), %xmm2
xorl %r14d, %r14d
movsd 0x13b11(%rip), %xmm1    # 0xa2218
movsd %xmm2, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
divsd %xmm1, %xmm0
movaps %xmm2, %xmm1
callq 0xe7d0
movsd 0x8(%rsp), %xmm2
movsd 0x13ae9(%rip), %xmm1    # 0xa2218
mulsd %xmm1, %xmm0
addsd 0x138f5(%rip), %xmm0    # 0xa2030
cvttsd2si %xmm0, %eax
movq 0x2a0(%rbx), %rcx
movb %al, (%rcx,%r14)
incq %r14
cmpq $0x100, %r14            # imm = 0x100
jne 0x8e70d
jmp 0x8e819
xorps %xmm0, %xmm0
cvtss2sd 0x28c(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x91f8a
movq %rax, 0x2b8(%rbx)
xorl %r14d, %r14d
xorl %r15d, %r15d
movq %r12, %rbp
movl %r14d, %r13d
shrl $0x4, %r13d
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
callq 0x91fa8
movq 0x2b8(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
xorl %r12d, %r12d
movsd 0x1ab75(%rip), %xmm1    # 0xa9328
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xe7d0
movsd 0x1ab56(%rip), %xmm1    # 0xa9328
mulsd %xmm1, %xmm0
addsd 0x13852(%rip), %xmm0    # 0xa2030
cvttsd2si %xmm0, %eax
movq 0x2b8(%rbx), %rcx
movq (%rcx,%r15,8), %rcx
movw %ax, (%rcx,%r12,2)
incq %r12
addl $0x100, %r13d           # imm = 0x100
cmpq $0x100, %r12            # imm = 0x100
jne 0x8e7b3
incq %r15
addl 0x18(%rsp), %r14d
movq %rbp, %r12
cmpq %rbp, %r15
jne 0x8e786
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq