// File: /workspace/github_c_makefile_star2_O3/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 $0x88, %rsp
leaq 0x20ab8b7(%rip), %rax   # 0x20afc18
movq 0x10(%rax), %rcx
movq %rcx, 0x20(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x10(%rsp)
movq 0x20a5fd7(%rip), %rax   # 0x20aa350
cmpl $0x6, %edi
jne 0x4498
testq %rax, %rax
je 0x45d5
movl $0x7b, %edx
leaq 0x10(%rsp), %rdi
leaq 0x5c9d(%rip), %rbp      # 0xa039
xorl %ecx, %ecx
leaq 0x20a4fab(%rip), %rax   # 0x20a9350
movq %rcx, 0x38(%rsp)
movq (%rax,%rcx,8), %rax
movq (%rax), %rbx
movl (%rbx), %ecx
movq 0x8(%rbx), %r8
leaq 0x5c28(%rip), %rsi      # 0x9fe6
xorl %eax, %eax
callq 0x79b5
movq %rbx, 0x30(%rsp)
cmpl $0x0, 0x4(%rbx)
leaq 0x548a(%rip), %rcx      # 0x985f
leaq 0x40(%rsp), %rbx
je 0x4459
movq 0x30(%rsp), %rax
leaq 0x30(%rax), %r15
xorl %r13d, %r13d
movzbl -0x20(%r15), %eax
movl %eax, 0xc(%rsp)
movq -0x10(%r15), %rsi
movq (%r15), %r14
testq %r14, %r14
movq %rbp, %r12
cmoveq %rcx, %r12
cmoveq %rcx, %r14
movq %rbx, %rdi
callq 0x7343
movl -0x1c(%r15), %r10d
movl -0x8(%r15), %r11d
leaq 0x10(%rsp), %rdi
leaq 0x5be3(%rip), %rsi      # 0xa005
movl 0xc(%rsp), %edx
movq %r12, %rcx
movq %r14, %r8
movq %rax, %r9
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x79b5
leaq 0x541e(%rip), %rcx      # 0x985f
addq $0x10, %rsp
incq %r13
movq 0x30(%rsp), %rax
movl 0x4(%rax), %eax
addq $0x30, %r15
cmpq %rax, %r13
jb 0x43e8
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
leaq 0x5bd3(%rip), %rsi      # 0xa03b
xorl %eax, %eax
callq 0x79b5
movq 0x38(%rsp), %rcx
incq %rcx
movl $0x2c, %edx
cmpq %rcx, 0x20a5ecd(%rip)   # 0x20aa350
movq %rbx, %rdi
ja 0x439e
leaq 0x5baa(%rip), %rsi      # 0xa03d
jmp 0x45dc
testq %rax, %rax
je 0x45d5
movq %rsi, %r14
movl $0x7b, %edx
leaq 0x53af(%rip), %r13      # 0x985f
xorl %ebx, %ebx
xorl %esi, %esi
movl %edi, 0xc(%rsp)
leaq 0x20a4e91(%rip), %rcx   # 0x20a9350
leaq (%rcx,%rbx,8), %r10
movq (%r10), %rcx
movq (%rcx), %r15
movq 0x8(%r15), %r8
cmpb $0x41, (%r8)
jne 0x44f3
cmpb $0x49, 0x1(%r8)
jne 0x44f3
cmpl $0x1, %edi
sete %cl
cmpb $0x53, 0x2(%r8)
setne %r9b
xorb %cl, %r9b
movl (%r15), %ecx
je 0x44fb
jmp 0x451c
movl (%r15), %ecx
cmpl $0x1, %edi
jne 0x451c
cmpl $0x1f805, %ecx          # imm = 0x1F805
je 0x451c
cmpl $0x1f802, %ecx          # imm = 0x1F802
je 0x451c
incq %rbx
addq $0x8, %r10
cmpq %rbx, %rax
ja 0x44c3
jmp 0x45c8
leaq 0x10(%rsp), %rdi
leaq 0x5abe(%rip), %rsi      # 0x9fe6
xorl %eax, %eax
callq 0x79b5
movl 0x4(%r15), %eax
testl %eax, %eax
je 0x4593
leaq 0x38(%r15), %r12
xorl %ebp, %ebp
cmpq %r14, -0x20(%r12)
jae 0x454d
cmpl $0x1f014, (%r15)        # imm = 0x1F014
jne 0x4585
movzbl -0x28(%r12), %edx
movq -0x8(%r12), %r8
movq (%r12), %r9
testq %r8, %r8
leaq 0x5ad3(%rip), %rcx      # 0xa039
cmoveq %r13, %rcx
cmoveq %r13, %r8
leaq 0x10(%rsp), %rdi
leaq 0x5ac6(%rip), %rsi      # 0xa040
xorl %eax, %eax
callq 0x79b5
movl 0x4(%r15), %eax
incq %rbp
movl %eax, %ecx
addq $0x30, %r12
cmpq %rcx, %rbp
jb 0x453d
leaq 0x10(%rsp), %rdi
leaq 0x5a9c(%rip), %rsi      # 0xa03b
callq 0x7ae9
movq 0x20a5da5(%rip), %rax   # 0x20aa350
incq %rbx
movl $0x2c, %edx
movb $0x1, %sil
cmpq %rbx, %rax
movl 0xc(%rsp), %edi
ja 0x44b8
jmp 0x448c
testb $0x1, %sil
leaq 0x5a6a(%rip), %rsi      # 0xa03d
jne 0x45dc
leaq 0x5282(%rip), %rsi      # 0x985e
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x7ae9
movq 0x8(%rbx), %rsi
leaq 0x5a5b(%rip), %rdi      # 0xa04f
xorl %eax, %eax
callq 0x7509
movq (%rbx), %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq