// File: /workspace/github_c_makefile_star2_O2/canboat[P]canboat/nmea0183/../common/common.c
// Function: getJSONValue
bool getJSONValue(const char *message, const char *fieldName, char *value, size_t len)
{
  const char *loc      = message + 1;
  size_t      fieldLen = strlen(fieldName);

  for (;;)
  {
    loc = strstr(loc, fieldName);
    if (!loc)
    {
      logDebug("getJSONValue('%s','%s',...) => name not found\n", message, fieldName);
      return false;
    }
    if (loc[-1] == '"' && loc[fieldLen] == '"' && loc[fieldLen + 1] == ':')
    {
      break;
    }
    loc += fieldLen;
  }

  /* field has been found */
  loc += fieldLen + 2;

  while (isspace((unsigned char) *loc))
  {
    loc++;
  }

  if (*loc == '{')
  {
    /* It is a nested value like "field" : {"value":0,"name":"Under way using engine"} */
    return getJSONLookupValue(message, fieldName, value, len);
  }

  if (strncmp(loc, "null", 4) == 0)
  {
    logDebug("getJSONValue('%s','%s',...) => value null\n", message, fieldName);
    return false;
  }

  if (*loc != '"')
  {
    while ((isdigit((unsigned char) *loc) || *loc == '.' || *loc == '-' || *loc == 'E' || *loc == 'e' || *loc == '+') && len > 1)
    {
      *value++ = *loc++;
      len--;
    }
    *value = 0;
    logDebug("getJSONValue('%s','%s',...) => valid number\n", message, fieldName);
    return true;
  }

  /* field is string */

  loc++;

  while (len > 1)
  {
    if (*loc == '\\')
    {
      loc++;
      switch (*loc)
      {
        case 'b':
          *value++ = '\b';
          loc++;
          break;
        case 'f':
          *value++ = '\f';
          loc++;
          break;
        case 'n':
          *value++ = '\n';
          loc++;
          break;
        case 'r':
          *value++ = '\r';
          loc++;
          break;
        case 't':
          *value++ = '\t';
          loc++;
          break;
        case 'u': {
          unsigned int n;
          sscanf(loc, "%4x", &n);
          loc += 4;
          *value++ = n & 255; // We're single byte, forget about the high byte...
        }
        break;

        default:
          *value++ = *loc++;
      }
    }
    else if (*loc == '"')
    {
      break;
    }
    else
    {
      *value++ = *loc++;
    }
    len--;
  }
  *value = 0;
  logDebug("getJSONValue('%s','%s',...) => valid string\n", message, fieldName);
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r12
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, (%rsp)
leaq 0x1(%rdi), %r13
movq %rsi, %rdi
callq 0x20b0
movq %rax, %rbp
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2280
testq %rax, %rax
je 0x2f36
movq %rax, %r13
cmpb $0x22, -0x1(%rax)
jne 0x2f31
cmpb $0x22, (%r13,%rbp)
jne 0x2f31
movq %r13, %r14
addq %rbp, %r14
cmpb $0x3a, 0x1(%r14)
je 0x2f5e
addq %rbp, %r13
jmp 0x2f03
leaq 0x155c(%rip), %rdi      # 0x4499
xorl %ebp, %ebp
movq (%rsp), %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x283c
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x2, %r14
callq 0x2290
movq (%rax), %rcx
movzbl (%r14), %ebp
movzwl (%rcx,%rbp,2), %r13d
incq %r14
btl $0xd, %r13d
jb 0x2f6a
cmpb $0x7b, %bpl
jne 0x2fa3
movq (%rsp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3103
movq %rax, 0x10(%rsp)
leaq -0x1(%r14), %rdi
leaq 0x1515(%rip), %rsi      # 0x44c8
pushq $0x4
popq %rdx
callq 0x2070
testl %eax, %eax
je 0x3078
cmpb $0x22, %bpl
movq 0x10(%rsp), %rsi
jne 0x3084
leaq 0x144f(%rip), %r13      # 0x4428
leaq 0xc(%rsp), %rbp
cmpq $0x2, %r12
jb 0x30e2
movzbl (%r14), %eax
cmpl $0x5c, %eax
je 0x3002
cmpl $0x22, %eax
je 0x30e2
incq %r14
movb %al, (%r15)
jmp 0x306d
movb 0x1(%r14), %al
movzbl %al, %ecx
leal -0x6e(%rcx), %edx
cmpl $0x7, %edx
ja 0x3021
movslq (%r13,%rdx,4), %rcx
addq %r13, %rcx
jmpq *%rcx
movb $0xa, (%r15)
jmp 0x3069
cmpl $0x66, %ecx
je 0x3065
cmpl $0x62, %ecx
jne 0x3031
movb $0x8, (%r15)
jmp 0x3069
addq $0x2, %r14
jmp 0x3054
leaq 0x1(%r14), %rdi
leaq 0x14e3(%rip), %rsi      # 0x4525
movq %rbp, %rdx
xorl %eax, %eax
callq 0x21b0
addq $0x5, %r14
movb 0xc(%rsp), %al
movb %al, (%r15)
jmp 0x306d
movb $0xd, (%r15)
jmp 0x3069
movb $0x9, (%r15)
jmp 0x3069
movb $0xc, (%r15)
addq $0x2, %r14
incq %r15
decq %r12
jmp 0x2fde
leaq 0x144e(%rip), %rdi      # 0x44cd
jmp 0x2f3d
xorl %eax, %eax
movabsq $0x100000001000003, %rcx # imm = 0x100000001000003
btl $0xb, %r13d
jb 0x30a9
movzbl %bpl, %edx
addl $-0x2d, %edx
cmpl $0x38, %edx
ja 0x30c8
btq %rdx, %rcx
jae 0x30c8
cmpq $0x2, %r12
jb 0x30d4
movb %bpl, (%r15,%rax)
decq %r12
movq (%rsi), %rdx
movzbl (%r14,%rax), %ebp
movzwl (%rdx,%rbp,2), %r13d
incq %rax
jmp 0x3090
cmpb $0x2b, %bpl
jne 0x30d4
cmpq $0x1, %r12
ja 0x30af
movb $0x0, (%r15,%rax)
leaq 0x1418(%rip), %rdi      # 0x44f8
jmp 0x30ed
movb $0x0, (%r15)
leaq 0x143c(%rip), %rdi      # 0x4529
movq (%rsp), %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x283c
movb $0x1, %bpl
jmp 0x2f4d