// File: /workspace/github_cpp_makefile_star2_O1/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 0x8eef0
movss 0x290(%rbx), %xmm0
cvtss2sd %xmm0, %xmm1
ucomisd 0x13312(%rip), %xmm1    # 0xa21e0
jbe 0x8ef08
mulss 0x28c(%rbx), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x13154(%rip), %xmm1    # 0xa2038
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x8ef16
testb $0x2, 0x24e(%rbx)
jne 0x8f04f
movb 0x2cb(%rbx), %al
jmp 0x8f06d
movsd 0x13128(%rip), %xmm0    # 0xa2038
movsd %xmm0, 0x8(%rsp)
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdi
callq 0x92cb5
movq %rax, 0x298(%rbx)
xorl %r14d, %r14d
movsd 0x132e3(%rip), %xmm1    # 0xa2218
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xe7d0
movsd 0x130dc(%rip), %xmm2    # 0xa2030
movsd 0x132bc(%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 0x8ef35
testl $0x600080, 0x124(%rbx)  # imm = 0x600080
je 0x8f52d
xorps %xmm0, %xmm0
cvtss2sd 0x28c(%rbx), %xmm0
movsd 0x13096(%rip), %xmm1    # 0xa2038
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdi
callq 0x92cb5
movsd 0x13257(%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 0x1322e(%rip), %xmm1    # 0xa2218
mulsd %xmm1, %xmm0
addsd 0x1303a(%rip), %xmm0    # 0xa2030
cvttsd2si %xmm0, %eax
movq 0x2a8(%rbx), %rcx
movb %al, (%rcx,%r14)
incq %r14
cmpq $0x100, %r14            # imm = 0x100
jne 0x8efcb
movl $0x100, %esi            # imm = 0x100
movq %rbx, %rdi
callq 0x92cb5
movq %rax, 0x2a0(%rbx)
xorps %xmm0, %xmm0
cvtss2sd 0x290(%rbx), %xmm0
ucomisd 0x131a8(%rip), %xmm0    # 0xa21e0
jbe 0x8f40c
movsd 0x12ff2(%rip), %xmm2    # 0xa2038
divsd %xmm0, %xmm2
jmp 0x8f417
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, %r13d
cmovgel %ecx, %r13d
btl $0xa, 0x124(%rbx)
cmovael %ecx, %r13d
movl $0x8, %esi
cmpl %esi, %r13d
cmovgel %esi, %r13d
testl %r13d, %r13d
cmovlel %edx, %r13d
movzbl %r13b, %eax
movl %eax, 0x288(%rbx)
movl $0x8, %ebp
subl %r13d, %ebp
movl $0x1, %r14d
movl %ebp, %ecx
shll %cl, %r14d
movss 0x290(%rbx), %xmm0
cvtss2sd %xmm0, %xmm1
ucomisd 0x13105(%rip), %xmm1    # 0xa21e0
jbe 0x8f0fd
mulss 0x28c(%rbx), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x12f47(%rip), %xmm1    # 0xa2038
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x8f10b
movsd 0x12f33(%rip), %xmm0    # 0xa2038
movsd %xmm0, 0x8(%rsp)
movl %ebp, %ecx
shll %cl, %esi
movq %rbx, %rdi
movq %rsi, 0x10(%rsp)
callq 0x92c97
movq %rax, 0x2b0(%rbx)
movzwl 0x124(%rbx), %eax
movl %r14d, %r12d
movl %r13d, %ecx
movq %rcx, 0x18(%rsp)
xorl %r14d, %r14d
testl $0x480, %eax            # imm = 0x480
je 0x8f26f
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
callq 0x92cb5
movq 0x2b0(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
incq %r14
cmpq %r14, %r12
jne 0x8f143
movsd 0x12ecd(%rip), %xmm0    # 0xa2038
divsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movl $0x100, %eax            # imm = 0x100
movl %ebp, %ecx
shll %cl, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x30(%rsp)
movl $0xff, %r15d
movl %r13d, 0x2c(%rsp)
movl %r13d, %ecx
shrl %cl, %r15d
xorpd %xmm0, %xmm0
xorl %r14d, %r14d
xorl %r13d, %r13d
movsd %xmm0, 0x8(%rsp)
addsd 0x12e7a(%rip), %xmm0    # 0xa2030
mulsd 0x1dc5a(%rip), %xmm0    # 0xace18
movsd 0x20(%rsp), %xmm1
callq 0xe7d0
mulsd 0x30(%rsp), %xmm0
cvttsd2si %xmm0, %rax
cmpl %eax, %r14d
ja 0x8f20a
movl %r13d, %edx
shll $0x8, %edx
addl %r13d, %edx
movq 0x2b0(%rbx), %rsi
movl %r14d, %ecx
andl %r15d, %ecx
movq (%rsi,%rcx,8), %rdi
movl %r14d, %r8d
movl %ebp, %ecx
shrl %cl, %r8d
movslq %r8d, %rcx
movw %dx, (%rdi,%rcx,2)
incl %r14d
cmpl %eax, %r14d
jbe 0x8f1e9
movsd 0x8(%rsp), %xmm0
addsd 0x12e20(%rip), %xmm0    # 0xa2038
incl %r13d
cmpl $0x100, %r13d           # imm = 0x100
jne 0x8f1a8
movl $0x100, %eax            # imm = 0x100
movl %ebp, %ecx
shll %cl, %eax
cmpl %eax, %r14d
jae 0x8f305
movq 0x2b0(%rbx), %rdx
movl $0xff, %esi
movl 0x2c(%rsp), %ecx
shrl %cl, %esi
movl %r14d, %ecx
andl %esi, %ecx
movq (%rdx,%rcx,8), %rdi
movl %r14d, %r8d
movl %ebp, %ecx
shrl %cl, %r8d
movslq %r8d, %rcx
movw $0xffff, (%rdi,%rcx,2)  # imm = 0xFFFF
incl %r14d
cmpl %r14d, %eax
jne 0x8f248
jmp 0x8f305
leaq 0x1dcca(%rip), %r15     # 0xacf40
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
callq 0x92cb5
movsd 0x1a09d(%rip), %xmm1    # 0xa9328
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 %r13d, %r13d
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xe7d0
movsd 0x1a061(%rip), %xmm1    # 0xa9328
mulsd %xmm1, %xmm0
addsd 0x12d5d(%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 0x8f2a9
incq %r14
cmpq %r12, %r14
jne 0x8f276
testl $0x600080, 0x124(%rbx)  # imm = 0x600080
je 0x8f52d
xorps %xmm0, %xmm0
cvtss2sd 0x28c(%rbx), %xmm0
movsd 0x12d10(%rip), %xmm1    # 0xa2038
movsd %xmm1, 0x8(%rsp)
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x92c97
movq %rax, 0x2c0(%rbx)
xorl %r14d, %r14d
leaq 0x1dbea(%rip), %r15     # 0xacf40
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
callq 0x92cb5
movsd 0x19fbd(%rip), %xmm1    # 0xa9328
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 %r13d, %r13d
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
divsd %xmm1, %xmm0
movsd 0x20(%rsp), %xmm1
callq 0xe7d0
movsd 0x19f81(%rip), %xmm1    # 0xa9328
mulsd %xmm1, %xmm0
addsd 0x12c7d(%rip), %xmm0    # 0xa2030
cvttsd2si %xmm0, %eax
movq 0x2c0(%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 0x8f389
incq %r14
cmpq %r12, %r14
jne 0x8f356
xorps %xmm0, %xmm0
cvtss2sd 0x290(%rbx), %xmm0
ucomisd 0x12de8(%rip), %xmm0    # 0xa21e0
jbe 0x8f476
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
jmp 0x8f487
xorps %xmm2, %xmm2
cvtss2sd 0x28c(%rbx), %xmm2
xorl %r14d, %r14d
movsd 0x12df6(%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 0x12dce(%rip), %xmm1    # 0xa2218
mulsd %xmm1, %xmm0
addsd 0x12bda(%rip), %xmm0    # 0xa2030
cvttsd2si %xmm0, %eax
movq 0x2a0(%rbx), %rcx
movb %al, (%rcx,%r14)
incq %r14
cmpq $0x100, %r14            # imm = 0x100
jne 0x8f428
jmp 0x8f52d
xorps %xmm0, %xmm0
cvtss2sd 0x28c(%rbx), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x92c97
movq %rax, 0x2b8(%rbx)
xorl %r14d, %r14d
movl $0x200, %esi            # imm = 0x200
movq %rbx, %rdi
callq 0x92cb5
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 %r13d, %r13d
movsd 0x19e57(%rip), %xmm1    # 0xa9328
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0xe7d0
movsd 0x19e39(%rip), %xmm1    # 0xa9328
mulsd %xmm1, %xmm0
addsd 0x12b35(%rip), %xmm0    # 0xa2030
cvttsd2si %xmm0, %eax
movq 0x2b8(%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 0x8f4d1
incq %r14
cmpq %r12, %r14
jne 0x8f49e
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq