// File: /workspace/github_cpp_makefile_star2_O1/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
movq $0x0, (%rdx)
testq %rsi, %rsi
je 0x9ed1e
movq %rdx, %r14
movq %rsi, %r15
movq %rsi, %rdi
callq 0xe1e0
testq %rax, %rax
je 0x9ed1e
movq %rax, %r12
leal 0x2(%rax), %esi
movq %rbx, %rdi
callq 0x92d72
movq %rax, (%r14)
testq %rax, %rax
je 0x9eddb
movq %rax, %r13
movq %r14, 0x8(%rsp)
movb (%r15), %al
testb %al, %al
je 0x9ecd9
incq %r15
leaq 0x153fd(%rip), %rbp     # 0xb4087
leaq 0x10(%rsp), %r14
cmpb $0x20, %al
setae %cl
leal -0x7f(%rax), %edx
cmpb $0x22, %dl
setae %dl
testb %dl, %cl
jne 0x9ecc8
movzbl %al, %ecx
movl $0x28, %esi
movq %r14, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe750
movq %rbx, %rdi
movq %r14, %rsi
callq 0x92e6e
movb $0x20, (%r13)
jmp 0x9eccc
movb %al, (%r13)
incq %r13
movb (%r15), %al
incq %r15
testb %al, %al
jne 0x9ec8f
movb $0x0, (%r13)
movq 0x8(%rsp), %r13
movq (%r13), %r14
cmpb $0x20, -0x1(%r14,%r12)
jne 0x9ed42
leaq 0x153b2(%rip), %rsi     # 0xb40a8
movq %rbx, %rdi
callq 0x92e6e
cmpb $0x20, -0x1(%r14,%r12)
jne 0x9ed42
movb $0x0, -0x1(%r14,%r12)
leaq -0x1(%r12), %r15
cmpb $0x20, -0x2(%r14,%r12)
movq %r15, %r12
je 0x9ed06
jmp 0x9ed45
leaq 0x15328(%rip), %rsi     # 0xb404d
movq %rbx, %rdi
callq 0x92e6e
xorl %r15d, %r15d
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %r15
movq (%r13), %r14
cmpb $0x20, (%r14)
jne 0x9ed77
leaq 0x15377(%rip), %rsi     # 0xb40cd
movq %rbx, %rdi
callq 0x92e6e
cmpb $0x20, (%r14)
jne 0x9ed77
leaq 0x1(%r14), %rax
decq %r15
cmpb $0x20, 0x1(%r14)
movq %rax, %r14
je 0x9ed64
jmp 0x9ed7a
movq %r14, %rax
movq (%r13), %rcx
movb (%rax), %dil
testb %dil, %dil
je 0x9ede7
incq %rax
xorl %edx, %edx
xorl %esi, %esi
cmpb $0x20, %dil
sete %r8b
testl %esi, %esi
sete %r9b
andb %r8b, %r9b
cmpb $0x1, %r9b
jne 0x9edb1
movb %dil, (%rcx)
incq %rcx
movl $0x1, %esi
jmp 0x9edc9
cmpb $0x20, %dil
jne 0x9edc1
decq %r15
movl $0x1, %edx
jmp 0x9edc9
movb %dil, (%rcx)
incq %rcx
xorl %esi, %esi
movb (%rax), %dil
incq %rax
testb %dil, %dil
jne 0x9ed8d
testl %edx, %edx
sete %al
jmp 0x9ede9
leaq 0x1527f(%rip), %rsi     # 0xb4061
jmp 0x9ed25
movb $0x1, %al
movb $0x0, (%rcx)
testb %al, %al
jne 0x9edff
leaq 0x152fa(%rip), %rsi     # 0xb40f1
movq %rbx, %rdi
callq 0x92e6e
testq %r15, %r15
jne 0x9ee1f
movq (%r13), %rsi
movq %rbx, %rdi
callq 0x92d32
leaq 0x15305(%rip), %rsi     # 0xb411c
movq %rbx, %rdi
callq 0x92e6e
cmpq $0x50, %r15
jb 0x9ed30
leaq 0x15300(%rip), %rsi     # 0xb4130
movq %rbx, %rdi
callq 0x92e6e
movq (%r13), %rax
movb $0x0, 0x4f(%rax)
movl $0x4f, %r15d
jmp 0x9ed30