// File: /workspace/github_cpp_makefile_star2_O2/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 0x7f413
movq %rdi, %rbx
cmpl $0x40, %esi
sete %al
testl %esi, %esi
je 0x7f2ac
movb 0x408(%rbx), %cl
andb $0x4, %cl
shrb $0x2, %cl
andb %cl, %al
jne 0x7f2ac
leaq 0x1e6bc(%rip), %rsi     # 0x9d95a
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x849c0
cmpb $0x7, %dl
ja 0x7f2ec
movb $0x8, %bpl
movzbl %dl, %eax
leaq 0x1e54e(%rip), %rcx     # 0x9d80c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1e5fb(%rip), %rsi     # 0x9d8c9
movq %rbx, %rdi
callq 0x84a53
jmp 0x7f2ee
movb $-0x80, %bpl
jmp 0x7f2ee
movb $0x20, %bpl
jmp 0x7f2ee
movb $0x40, %bpl
jmp 0x7f2ee
movb $0x10, %bpl
jmp 0x7f2ee
movl %edx, %ebp
movb %bpl, 0x24d(%rbx)
cmpq $0x0, 0x1f0(%rbx)
je 0x7f413
testb $0x10, %bpl
je 0x7f336
cmpq $0x0, 0x1f8(%rbx)
jne 0x7f336
movq 0x1d0(%rbx), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x848bb
movq %rax, 0x1f8(%rbx)
movb $0x1, (%rax)
movb 0x24d(%rbx), %bpl
testb $0x20, %bpl
je 0x7f396
cmpq $0x0, 0x200(%rbx)
jne 0x7f396
cmpq $0x0, 0x1e8(%rbx)
je 0x7f375
movq 0x1d0(%rbx), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x848bb
movq %rax, 0x200(%rbx)
movb $0x2, (%rax)
movb 0x24d(%rbx), %bpl
jmp 0x7f396
leaq 0x1e56d(%rip), %rsi     # 0x9d8e9
movq %rbx, %rdi
callq 0x84a53
movb 0x24d(%rbx), %bpl
andb $-0x21, %bpl
movb %bpl, 0x24d(%rbx)
testb $0x40, %bpl
je 0x7f3f6
cmpq $0x0, 0x208(%rbx)
jne 0x7f3f6
cmpq $0x0, 0x1e8(%rbx)
je 0x7f3d5
movq 0x1d0(%rbx), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x848bb
movq %rax, 0x208(%rbx)
movb $0x3, (%rax)
movb 0x24d(%rbx), %bpl
jmp 0x7f3f6
leaq 0x1e530(%rip), %rsi     # 0x9d90c
movq %rbx, %rdi
callq 0x84a53
movb 0x24d(%rbx), %bpl
andb $-0x41, %bpl
movb %bpl, 0x24d(%rbx)
testb %bpl, %bpl
js 0x7f409
testb %bpl, %bpl
jne 0x7f413
movb $0x8, 0x24d(%rbx)
jmp 0x7f413
cmpq $0x0, 0x210(%rbx)
je 0x7f41a
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
cmpq $0x0, 0x1e8(%rbx)
je 0x7f449
movq 0x1d0(%rbx), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x848bb
movq %rax, 0x210(%rbx)
movb $0x4, (%rax)
movb 0x24d(%rbx), %bpl
jmp 0x7f3fb
leaq 0x1e4e4(%rip), %rsi     # 0x9d934
movq %rbx, %rdi
callq 0x84a53
movb 0x24d(%rbx), %bpl
andb $0x7f, %bpl
movb %bpl, 0x24d(%rbx)
jmp 0x7f3fb