// File: /workspace/github_c_makefile_star2_O1/canboat[P]canboat/n2kd/main.c
// Function: getFullStateJSON
static char *getFullStateJSON(StreamType stream, int64_t now)
{
  StringBuffer state     = sbNew;
  char         separator = '{';

  int  i, s;
  Pgn *pgn;

  if (stream == CLIENT_STATUS_STREAM)
  {
    for (i = 0; i < maxPgnList; i++)
    {
      pgn = *pgnList[i];

      sbAppendFormat(&state, "%c\"%u\":\n  {\"description\":\"%s\"\n", separator, pgn->p_prn, pgn->p_description);

      for (s = 0; s < pgn->p_maxSrc; s++)
      {
        Message *m = &pgn->p_message[s];
        char     last_ts[DATE_LENGTH];

        sbAppendFormat(&state,
                       "  ,\"%u%s%s\":{\"last\":\"%s\",\"interval\":%u,\"count\":%u}\n",
                       m->m_src,
                       m->m_key2 ? "_" : "",
                       m->m_key2 ? m->m_key2 : "",
                       fmtTimestamp(last_ts, m->m_last),
                       m->m_interval,
                       m->m_count);
      }
      sbAppendFormat(&state, "  }\n");
      separator = ',';
    }
  }
  else
  {
    for (i = 0; i < maxPgnList; i++)
    {
      pgn = *pgnList[i];

      // AIS data only goes to AIS clients, non-AIS data to non-AIS clients, but
      // PRNs 129026 and 129029 go to both.
      if ((stream == CLIENT_AIS) == (strncmp(pgn->p_description, "AIS", 3) == 0) || pgn->p_prn == 129026 || pgn->p_prn == 129029)
      {
        sbAppendFormat(&state, "%c\"%u\":\n  {\"description\":\"%s\"\n", separator, pgn->p_prn, pgn->p_description);

        for (s = 0; s < pgn->p_maxSrc; s++)
        {
          Message *m = &pgn->p_message[s];

          if (m->m_valid >= now || pgn->p_prn == PRN_PROD_INFO)
          {
            sbAppendFormat(&state, "  ,\"%u%s%s\":%s", m->m_src, m->m_key2 ? "_" : "", m->m_key2 ? m->m_key2 : "", m->m_text);
          }
        }
        sbAppendString(&state, "  }\n");

        separator = ',';
      }
    }
  }
  if (separator == ',')
  {
    sbAppendString(&state, "}\n");
  }
  else
  {
    sbAppendString(&state, "\n");
  }

  logDebug("state %d bytes\n", sbGetLength(&state));
  return state.data;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
leaq 0x20ab842(%rip), %rax   # 0x20afc18
movq 0x10(%rax), %rcx
movq %rcx, 0x20(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x20a5f62(%rip), %rax   # 0x20aa350
movl %edi, 0x8(%rsp)
cmpl $0x6, %edi
jne 0x450a
testq %rax, %rax
je 0x4625
movl $0x7b, %edx
leaq 0x10(%rsp), %rdi
leaq 0x5c14(%rip), %rbp      # 0xa029
xorl %ecx, %ecx
leaq 0x20a4f32(%rip), %rax   # 0x20a9350
movq %rcx, 0x28(%rsp)
movq (%rax,%rcx,8), %rax
movq (%rax), %rbx
movl (%rbx), %ecx
movq 0x8(%rbx), %r8
leaq 0x5b9f(%rip), %rsi      # 0x9fd6
xorl %eax, %eax
callq 0x7a17
movq %rbx, 0x8(%rsp)
cmpl $0x0, 0x4(%rbx)
leaq 0x5401(%rip), %rcx      # 0x984f
leaq 0x30(%rsp), %rbx
je 0x44d2
movq 0x8(%rsp), %rax
leaq 0x30(%rax), %r15
xorl %r13d, %r13d
movzbl -0x20(%r15), %eax
movl %eax, 0x4(%rsp)
movq -0x10(%r15), %rsi
movq (%r15), %r14
testq %r14, %r14
movq %rbp, %r12
cmoveq %rcx, %r12
cmoveq %rcx, %r14
movq %rbx, %rdi
callq 0x7383
movl -0x1c(%r15), %r10d
movl -0x8(%r15), %r11d
leaq 0x10(%rsp), %rdi
leaq 0x5b5a(%rip), %rsi      # 0x9ff5
movl 0x4(%rsp), %edx
movq %r12, %rcx
movq %r14, %r8
movq %rax, %r9
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x7a17
leaq 0x5395(%rip), %rcx      # 0x984f
addq $0x10, %rsp
incq %r13
movq 0x8(%rsp), %rax
movl 0x4(%rax), %eax
addq $0x30, %r15
cmpq %rax, %r13
jb 0x4461
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
leaq 0x5b4a(%rip), %rsi      # 0xa02b
xorl %eax, %eax
callq 0x7a17
movq 0x28(%rsp), %rcx
incq %rcx
movl $0x2c, %edx
cmpq %rcx, 0x20a5e54(%rip)   # 0x20aa350
movq %rbx, %rdi
ja 0x4417
jmp 0x461c
testq %rax, %rax
je 0x4625
movq %rsi, %rbx
movb $0x7b, 0x4(%rsp)
leaq 0x532d(%rip), %r14      # 0x984f
xorl %ebp, %ebp
cmpl $0x1, 0x8(%rsp)
sete %r12b
leaq 0x20a4e1c(%rip), %rax   # 0x20a9350
movq (%rax,%rbp,8), %rax
movq (%rax), %r15
movq 0x8(%r15), %r13
movl $0x3, %edx
movq %r13, %rdi
leaq 0x5ae2(%rip), %rsi      # 0xa030
callq 0x2070
testl %eax, %eax
setne %al
xorb %r12b, %al
jne 0x4572
movl (%r15), %eax
cmpl $0x1f805, %eax          # imm = 0x1F805
je 0x4572
cmpl $0x1f802, %eax          # imm = 0x1F802
jne 0x4605
movzbl 0x4(%rsp), %edx
movl (%r15), %ecx
leaq 0x10(%rsp), %rdi
leaq 0x5a50(%rip), %rsi      # 0x9fd6
movq %r13, %r8
xorl %eax, %eax
callq 0x7a17
cmpl $0x0, 0x4(%r15)
je 0x45ef
leaq 0x38(%r15), %r13
xorl %r12d, %r12d
cmpq %rbx, -0x20(%r13)
jae 0x45ad
cmpl $0x1f014, (%r15)        # imm = 0x1F014
jne 0x45df
movzbl -0x28(%r13), %edx
movq -0x8(%r13), %r8
movq (%r13), %r9
testq %r8, %r8
leaq 0x5a65(%rip), %rcx      # 0xa029
cmoveq %r14, %rcx
cmoveq %r14, %r8
leaq 0x10(%rsp), %rdi
leaq 0x5a5c(%rip), %rsi      # 0xa034
xorl %eax, %eax
callq 0x7a17
incq %r12
movl 0x4(%r15), %eax
addq $0x30, %r13
cmpq %rax, %r12
jb 0x459e
leaq 0x10(%rsp), %rdi
leaq 0x5a30(%rip), %rsi      # 0xa02b
callq 0x7b48
movb $0x2c, 0x4(%rsp)
incq %rbp
cmpq %rbp, 0x20a5d41(%rip)   # 0x20aa350
ja 0x4524
cmpb $0x2c, 0x4(%rsp)
jne 0x4625
leaq 0x5a0a(%rip), %rsi      # 0xa02d
jmp 0x462c
leaq 0x5222(%rip), %rsi      # 0x984e
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x7b48
movq 0x8(%rbx), %rsi
leaq 0x59ff(%rip), %rdi      # 0xa043
xorl %eax, %eax
callq 0x7549
movq (%rbx), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq