// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/png/pngwrite.c
// Function: png_set_filter
void PNGAPI
png_set_filter(png_structp png_ptr, int method, int filters)
{
   png_debug(1, "in png_set_filter");

   if (png_ptr == NULL)
      return;
#ifdef PNG_MNG_FEATURES_SUPPORTED
   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
      (method == PNG_INTRAPIXEL_DIFFERENCING))
         method = PNG_FILTER_TYPE_BASE;
#endif
   if (method == PNG_FILTER_TYPE_BASE)
   {
      switch (filters & (PNG_ALL_FILTERS | 0x07))
      {
#ifdef PNG_WRITE_FILTER_SUPPORTED
         case 5:
         case 6:
         case 7: png_warning(png_ptr, "Unknown row filter for method 0");
#endif /* PNG_WRITE_FILTER_SUPPORTED */
         case PNG_FILTER_VALUE_NONE:
              png_ptr->do_filter = PNG_FILTER_NONE; break;
#ifdef PNG_WRITE_FILTER_SUPPORTED
         case PNG_FILTER_VALUE_SUB:
              png_ptr->do_filter = PNG_FILTER_SUB; break;
         case PNG_FILTER_VALUE_UP:
              png_ptr->do_filter = PNG_FILTER_UP; break;
         case PNG_FILTER_VALUE_AVG:
              png_ptr->do_filter = PNG_FILTER_AVG; break;
         case PNG_FILTER_VALUE_PAETH:
              png_ptr->do_filter = PNG_FILTER_PAETH; break;
         default: png_ptr->do_filter = (png_byte)filters; break;
#else
         default: png_warning(png_ptr, "Unknown row filter for method 0");
#endif /* PNG_WRITE_FILTER_SUPPORTED */
      }

      /* If we have allocated the row_buf, this means we have already started
       * with the image and we should have allocated all of the filter buffers
       * that have been selected.  If prev_row isn't already allocated, then
       * it is too late to start using the filters that need it, since we
       * will be missing the data in the previous row.  If an application
       * wants to start and stop using particular filters during compression,
       * it should start out with all of the filters, and then add and
       * remove them after the start of compression.
       */
      if (png_ptr->row_buf != NULL)
      {
#ifdef PNG_WRITE_FILTER_SUPPORTED
         if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
         {
            png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
              (png_ptr->rowbytes + 1));
            png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
         }

         if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
         {
            if (png_ptr->prev_row == NULL)
            {
               png_warning(png_ptr, "Can't add Up filter after starting");
               png_ptr->do_filter &= ~PNG_FILTER_UP;
            }
            else
            {
               png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
                  (png_ptr->rowbytes + 1));
               png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
            }
         }

         if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
         {
            if (png_ptr->prev_row == NULL)
            {
               png_warning(png_ptr, "Can't add Average filter after starting");
               png_ptr->do_filter &= ~PNG_FILTER_AVG;
            }
            else
            {
               png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
                  (png_ptr->rowbytes + 1));
               png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
            }
         }

         if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
             png_ptr->paeth_row == NULL)
         {
            if (png_ptr->prev_row == NULL)
            {
               png_warning(png_ptr, "Can't add Paeth filter after starting");
               png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
            }
            else
            {
               png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
                  (png_ptr->rowbytes + 1));
               png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
            }
         }

         if (png_ptr->do_filter == PNG_NO_FILTERS)
#endif /* PNG_WRITE_FILTER_SUPPORTED */
            png_ptr->do_filter = PNG_FILTER_NONE;
      }
   }
   else
      png_error(png_ptr, "Unknown custom filter method");
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x8d507
movq %rdi, %rbx
cmpl $0x40, %esi
sete %al
testl %esi, %esi
je 0x8d37e
movb 0x408(%rbx), %cl
andb $0x4, %cl
shrb $0x2, %cl
andb %cl, %al
jne 0x8d37e
leaq 0x1f8ca(%rip), %rsi     # 0xacc3a
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x92dd0
cmpb $0x7, %dl
ja 0x8d3be
movb $0x8, %bpl
movzbl %dl, %eax
leaq 0x1f75c(%rip), %rcx     # 0xacaec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1f809(%rip), %rsi     # 0xacba9
movq %rbx, %rdi
callq 0x92e6e
jmp 0x8d3c0
movb $-0x80, %bpl
jmp 0x8d3c0
movb $0x20, %bpl
jmp 0x8d3c0
movb $0x40, %bpl
jmp 0x8d3c0
movb $0x10, %bpl
jmp 0x8d3c0
movl %edx, %ebp
movb %bpl, 0x24d(%rbx)
cmpq $0x0, 0x1f0(%rbx)
je 0x8d507
testb $0x10, 0x24d(%rbx)
je 0x8d404
cmpq $0x0, 0x1f8(%rbx)
jne 0x8d404
movq 0x1d0(%rbx), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x92cb5
movq %rax, 0x1f8(%rbx)
movb $0x1, (%rax)
testb $0x20, 0x24d(%rbx)
je 0x8d455
cmpq $0x0, 0x200(%rbx)
jne 0x8d455
cmpq $0x0, 0x1e8(%rbx)
je 0x8d43f
movq 0x1d0(%rbx), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x92cb5
movq %rax, 0x200(%rbx)
movb $0x2, (%rax)
jmp 0x8d455
leaq 0x1f783(%rip), %rsi     # 0xacbc9
movq %rbx, %rdi
callq 0x92e6e
andb $-0x21, 0x24d(%rbx)
testb $0x40, 0x24d(%rbx)
je 0x8d4a6
cmpq $0x0, 0x208(%rbx)
jne 0x8d4a6
cmpq $0x0, 0x1e8(%rbx)
je 0x8d490
movq 0x1d0(%rbx), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x92cb5
movq %rax, 0x208(%rbx)
movb $0x3, (%rax)
jmp 0x8d4a6
leaq 0x1f755(%rip), %rsi     # 0xacbec
movq %rbx, %rdi
callq 0x92e6e
andb $-0x41, 0x24d(%rbx)
cmpb $0x0, 0x24d(%rbx)
jns 0x8d4f7
cmpq $0x0, 0x210(%rbx)
jne 0x8d4f7
cmpq $0x0, 0x1e8(%rbx)
je 0x8d4e1
movq 0x1d0(%rbx), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x92cb5
movq %rax, 0x210(%rbx)
movb $0x4, (%rax)
jmp 0x8d4f7
leaq 0x1f72c(%rip), %rsi     # 0xacc14
movq %rbx, %rdi
callq 0x92e6e
andb $0x7f, 0x24d(%rbx)
cmpb $0x0, 0x24d(%rbx)
jne 0x8d507
movb $0x8, 0x24d(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq