// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/png/pngwutil.c
// Function: png_check_keyword
png_size_t /* PRIVATE */
png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
{
   png_size_t key_len;
   png_charp kp, dp;
   int kflag;
   int kwarn=0;

   png_debug(1, "in png_check_keyword");

   *new_key = NULL;

   if (key == NULL || (key_len = png_strlen(key)) == 0)
   {
      png_warning(png_ptr, "zero length keyword");
      return ((png_size_t)0);
   }

   png_debug1(2, "Keyword to be checked is '%s'", key);

   *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
   if (*new_key == NULL)
   {
      png_warning(png_ptr, "Out of memory while procesing keyword");
      return ((png_size_t)0);
   }

   /* Replace non-printing characters with a blank and print a warning */
   for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
   {
      if ((png_byte)*kp < 0x20 ||
         ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
      {
#ifdef PNG_STDIO_SUPPORTED
         char msg[40];

         png_snprintf(msg, 40,
           "invalid keyword character 0x%02X", (png_byte)*kp);
         png_warning(png_ptr, msg);
#else
         png_warning(png_ptr, "invalid character in keyword");
#endif
         *dp = ' ';
      }
      else
      {
         *dp = *kp;
      }
   }
   *dp = '\0';

   /* Remove any trailing white space. */
   kp = *new_key + key_len - 1;
   if (*kp == ' ')
   {
      png_warning(png_ptr, "trailing spaces removed from keyword");

      while (*kp == ' ')
      {
         *(kp--) = '\0';
         key_len--;
      }
   }

   /* Remove any leading white space. */
   kp = *new_key;
   if (*kp == ' ')
   {
      png_warning(png_ptr, "leading spaces removed from keyword");

      while (*kp == ' ')
      {
         kp++;
         key_len--;
      }
   }

   png_debug1(2, "Checking for multiple internal spaces in '%s'", kp);

   /* Remove multiple internal spaces. */
   for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
   {
      if (*kp == ' ' && kflag == 0)
      {
         *(dp++) = *kp;
         kflag = 1;
      }
      else if (*kp == ' ')
      {
         key_len--;
         kwarn=1;
      }
      else
      {
         *(dp++) = *kp;
         kflag = 0;
      }
   }
   *dp = '\0';
   if (kwarn)
      png_warning(png_ptr, "extra interior spaces removed from keyword");

   if (key_len == 0)
   {
      png_free(png_ptr, *new_key);
      png_warning(png_ptr, "Zero length keyword");
   }

   if (key_len > 79)
   {
      png_warning(png_ptr, "keyword length must be 1 - 79 characters");
      (*new_key)[79] = '\0';
      key_len = 79;
   }

   return (key_len);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
andq $0x0, (%rdx)
testq %rsi, %rsi
je 0x8fbed
movq %rdx, %r14
movq %rsi, %r12
movq %rsi, %rdi
callq 0xe1e0
testq %rax, %rax
je 0x8fbed
movq %rax, %r15
leal 0x2(%rax), %esi
movq %rbx, %rdi
callq 0x84960
movq %rax, (%r14)
testq %rax, %rax
je 0x8fc4e
movq %rax, %r13
movq %r14, 0x8(%rsp)
movq %rbx, (%rsp)
leaq 0x10(%rsp), %r14
pushq $0x28
popq %rbx
xorl %ebp, %ebp
movzbl (%r12,%rbp), %ecx
testl %ecx, %ecx
je 0x8fc11
cmpb $0x20, %cl
setae %al
leal -0x7f(%rcx), %edx
cmpb $0x22, %dl
setae %dl
testb %dl, %al
jne 0x8fbe3
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x151bf(%rip), %rdx     # 0xa4d87
xorl %eax, %eax
callq 0xe780
movq (%rsp), %rdi
movq %r14, %rsi
callq 0x84a53
movb $0x20, (%r13,%rbp)
jmp 0x8fbe8
movb %cl, (%r13,%rbp)
incq %rbp
jmp 0x8fb9f
leaq 0x15159(%rip), %rsi     # 0xa4d4d
movq %rbx, %rdi
callq 0x84a53
xorl %r15d, %r15d
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x0, (%r13,%rbp)
movq 0x8(%rsp), %r12
movq (%r12), %rbx
cmpb $0x20, -0x1(%rbx,%r15)
jne 0x8fc57
leaq 0x15179(%rip), %rsi     # 0xa4da8
movq (%rsp), %r14
movq %r14, %rdi
callq 0x84a53
cmpb $0x20, -0x1(%rbx,%r15)
jne 0x8fc5d
movb $0x0, -0x1(%rbx,%r15)
decq %r15
jmp 0x8fc3b
leaq 0x1510c(%rip), %rsi     # 0xa4d61
jmp 0x8fbf4
movq (%rsp), %r14
jmp 0x8fc61
movq (%r12), %rbx
movb (%rbx), %dl
cmpb $0x20, %dl
jne 0x8fc86
leaq 0x1515e(%rip), %rsi     # 0xa4dcd
movq %r14, %rdi
callq 0x84a53
movb (%rbx), %dl
cmpb $0x20, %dl
jne 0x8fc8b
incq %rbx
decq %r15
jmp 0x8fc77
movq %rbx, %rax
jmp 0x8fc8f
movq (%r12), %rax
incq %rbx
xorl %esi, %esi
pushq $0x1
popq %rcx
xorl %edi, %edi
testb %dl, %dl
je 0x8fcd7
cmpb $0x20, %dl
sete %r8b
testl %esi, %esi
sete %r9b
andb %r8b, %r9b
cmpb $0x1, %r9b
jne 0x8fcbd
movb $0x20, (%rax)
incq %rax
movl %ecx, %esi
jmp 0x8fcd0
cmpb $0x20, %dl
jne 0x8fcc9
decq %r15
movl %ecx, %edi
jmp 0x8fcd0
movb %dl, (%rax)
incq %rax
xorl %esi, %esi
movb (%rbx), %dl
incq %rbx
jmp 0x8fc99
movb $0x0, (%rax)
testl %edi, %edi
je 0x8fced
leaq 0x1510c(%rip), %rsi     # 0xa4df1
movq %r14, %rdi
callq 0x84a53
testq %r15, %r15
je 0x8fd1c
cmpq $0x50, %r15
jb 0x8fbff
leaq 0x1512d(%rip), %rsi     # 0xa4e30
movq %r14, %rdi
callq 0x84a53
movq (%r12), %rax
movb $0x0, 0x4f(%rax)
pushq $0x4f
popq %r15
jmp 0x8fbff
movq (%r12), %rsi
movq %r14, %rdi
callq 0x84923
leaq 0x150ed(%rip), %rsi     # 0xa4e1c
movq %r14, %rdi
jmp 0x8fbf7