// File: /workspace/github_cpp_makefile_star2_O3/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 0x9e37a
movq %rdx, %r14
movq %rsi, %r15
movq %rsi, %rdi
callq 0xe1e0
testq %rax, %rax
je 0x9e37a
movq %rax, %r12
leal 0x2(%rax), %esi
movq %rbx, %rdi
callq 0x92056
movq %rax, (%r14)
testq %rax, %rax
je 0x9e454
movq %rax, %r13
movq %r14, 0x8(%rsp)
movb (%r15), %al
testb %al, %al
je 0x9e335
incq %r15
leaq 0x15df1(%rip), %rbp     # 0xb40d7
leaq 0x10(%rsp), %r14
cmpb $0x20, %al
setae %cl
leal -0x7f(%rax), %edx
cmpb $0x22, %dl
setae %dl
testb %dl, %cl
jne 0x9e324
movzbl %al, %ecx
movl $0x28, %esi
movq %r14, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe750
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9214d
movb $0x20, (%r13)
jmp 0x9e328
movb %al, (%r13)
incq %r13
movb (%r15), %al
incq %r15
testb %al, %al
jne 0x9e2eb
movb $0x0, (%r13)
movq 0x8(%rsp), %r13
movq (%r13), %r14
cmpb $0x20, -0x1(%r14,%r12)
jne 0x9e39e
leaq 0x15da6(%rip), %rsi     # 0xb40f8
movq %rbx, %rdi
callq 0x9214d
cmpb $0x20, -0x1(%r14,%r12)
jne 0x9e39e
movb $0x0, -0x1(%r14,%r12)
leaq -0x1(%r12), %r15
cmpb $0x20, -0x2(%r14,%r12)
movq %r15, %r12
je 0x9e362
jmp 0x9e3a1
leaq 0x15d1c(%rip), %rsi     # 0xb409d
movq %rbx, %rdi
callq 0x9214d
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
movb (%r14), %al
cmpb $0x20, %al
jne 0x9e3ce
leaq 0x15d6a(%rip), %rsi     # 0xb411d
movq %rbx, %rdi
callq 0x9214d
movb (%r14), %al
cmpb $0x20, %al
jne 0x9e3ce
decq %r15
movb 0x1(%r14), %al
incq %r14
jmp 0x9e3be
movq (%r13), %rcx
testb %al, %al
je 0x9e460
xorl %edi, %edi
movb $0x1, %sil
movl $0x20, %edx
incq %r14
cmpb $0x20, %al
setne %r8b
testl %edi, %edi
sete %r9b
orb %r8b, %r9b
cmpb $0x1, %r9b
jne 0x9e429
testl %edi, %edi
sete %dil
cmpb $0x20, %al
sete %r8b
andb %dil, %r8b
movzbl %r8b, %edi
movzbl %al, %eax
testb %dil, %dil
cmovnel %edx, %eax
movb %al, (%rcx)
incq %rcx
movb (%r14), %al
incq %r14
testb %al, %al
jne 0x9e3e7
jmp 0x9e43a
decq %r15
movb (%r14), %al
xorl %esi, %esi
testb %al, %al
jne 0x9e3e4
movb $0x0, (%rcx)
jmp 0x9e443
movb $0x0, (%rcx)
testb $0x1, %sil
jne 0x9e463
leaq 0x15cf7(%rip), %rsi     # 0xb4141
movq %rbx, %rdi
callq 0x9214d
jmp 0x9e463
leaq 0x15c56(%rip), %rsi     # 0xb40b1
jmp 0x9e381
movb $0x0, (%rcx)
testq %r15, %r15
je 0x9e494
cmpq $0x50, %r15
jb 0x9e38c
leaq 0x15d07(%rip), %rsi     # 0xb4180
movq %rbx, %rdi
callq 0x9214d
movq (%r13), %rax
movb $0x0, 0x4f(%rax)
movl $0x4f, %r15d
jmp 0x9e38c
movq (%r13), %rsi
movq %rbx, %rdi
callq 0x92016
leaq 0x15cc5(%rip), %rsi     # 0xb416c
jmp 0x9e381