// File: /workspace/github_cpp_makefile_star2_O3/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 0x8c718
movq %rdi, %rbx
cmpl $0x40, %esi
sete %al
testl %esi, %esi
je 0x8c5b1
movb 0x408(%rbx), %cl
andb $0x4, %cl
shrb $0x2, %cl
andb %cl, %al
jne 0x8c5b1
leaq 0x206d7(%rip), %rsi     # 0xacc7a
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x920b4
cmpb $0x7, %dl
ja 0x8c5f1
movb $0x8, %bpl
movzbl %dl, %eax
leaq 0x20569(%rip), %rcx     # 0xacb2c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x20616(%rip), %rsi     # 0xacbe9
movq %rbx, %rdi
callq 0x9214d
jmp 0x8c5f3
movb $-0x80, %bpl
jmp 0x8c5f3
movb $0x20, %bpl
jmp 0x8c5f3
movb $0x40, %bpl
jmp 0x8c5f3
movb $0x10, %bpl
jmp 0x8c5f3
movl %edx, %ebp
movb %bpl, 0x24d(%rbx)
cmpq $0x0, 0x1f0(%rbx)
je 0x8c718
testb $0x10, %bpl
je 0x8c63b
cmpq $0x0, 0x1f8(%rbx)
jne 0x8c63b
movq 0x1d0(%rbx), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x91fa8
movq %rax, 0x1f8(%rbx)
movb $0x1, (%rax)
movb 0x24d(%rbx), %bpl
testb $0x20, %bpl
je 0x8c69b
cmpq $0x0, 0x200(%rbx)
jne 0x8c69b
cmpq $0x0, 0x1e8(%rbx)
je 0x8c67a
movq 0x1d0(%rbx), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x91fa8
movq %rax, 0x200(%rbx)
movb $0x2, (%rax)
movb 0x24d(%rbx), %bpl
jmp 0x8c69b
leaq 0x20588(%rip), %rsi     # 0xacc09
movq %rbx, %rdi
callq 0x9214d
movb 0x24d(%rbx), %bpl
andb $-0x21, %bpl
movb %bpl, 0x24d(%rbx)
testb $0x40, %bpl
je 0x8c6fb
cmpq $0x0, 0x208(%rbx)
jne 0x8c6fb
cmpq $0x0, 0x1e8(%rbx)
je 0x8c6da
movq 0x1d0(%rbx), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x91fa8
movq %rax, 0x208(%rbx)
movb $0x3, (%rax)
movb 0x24d(%rbx), %bpl
jmp 0x8c6fb
leaq 0x2054b(%rip), %rsi     # 0xacc2c
movq %rbx, %rdi
callq 0x9214d
movb 0x24d(%rbx), %bpl
andb $-0x41, %bpl
movb %bpl, 0x24d(%rbx)
testb %bpl, %bpl
js 0x8c70e
testb %bpl, %bpl
jne 0x8c718
movb $0x8, 0x24d(%rbx)
jmp 0x8c718
cmpq $0x0, 0x210(%rbx)
je 0x8c71f
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
cmpq $0x0, 0x1e8(%rbx)
je 0x8c74e
movq 0x1d0(%rbx), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x91fa8
movq %rax, 0x210(%rbx)
movb $0x4, (%rax)
movb 0x24d(%rbx), %bpl
jmp 0x8c700
leaq 0x204ff(%rip), %rsi     # 0xacc54
movq %rbx, %rdi
callq 0x9214d
movb 0x24d(%rbx), %bpl
andb $0x7f, %bpl
movb %bpl, 0x24d(%rbx)
jmp 0x8c700