// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xf0, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x20ad3ff(%rip), %rax   # 0x20b2c98
movq (%rax), %rcx
movq %rcx, -0x28(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x20(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
movb $0x7b, -0x29(%rbp)
cmpl $0x6, -0x4(%rbp)
jne 0x5a35
movl $0x0, -0x30(%rbp)
movslq -0x30(%rbp), %rax
cmpq 0x20a7b00(%rip), %rax   # 0x20ad3d0
jae 0x5a30
movslq -0x30(%rbp), %rcx
leaq 0x20a6aef(%rip), %rax   # 0x20ac3d0
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movsbl -0x29(%rbp), %edx
movq -0x40(%rbp), %rax
movl (%rax), %ecx
movq -0x40(%rbp), %rax
movq 0x8(%rax), %r8
leaq -0x28(%rbp), %rdi
leaq 0x76a9(%rip), %rsi      # 0xcfb2
movb $0x0, %al
callq 0xa2b0
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x5a0c
movq -0x40(%rbp), %rax
addq $0x10, %rax
movslq -0x34(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0xa4(%rbp)
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0x6eb5(%rip), %rax      # 0xc80f
leaq 0x76a4(%rip), %rcx      # 0xd005
cmpq $0x0, %rdx
cmovneq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x598c
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xb0(%rbp)
jmp 0x599c
leaq 0x6e7c(%rip), %rax      # 0xc80f
movq %rax, -0xb0(%rbp)
jmp 0x599c
movq -0xb0(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x90(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x98a0
movl -0xa4(%rbp), %edx
movq -0xa0(%rbp), %rcx
movq -0xb8(%rbp), %r8
movq %rax, %r9
movq -0x48(%rbp), %rax
movl 0x4(%rax), %r10d
movq -0x48(%rbp), %rax
movl 0x18(%rax), %eax
leaq -0x28(%rbp), %rdi
leaq 0x75e2(%rip), %rsi      # 0xcfd1
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0xa2b0
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x5917
leaq -0x28(%rbp), %rdi
leaq 0x75f0(%rip), %rsi      # 0xd007
movb $0x0, %al
callq 0xa2b0
movb $0x2c, -0x29(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x58c5
jmp 0x5c09
movl $0x0, -0x30(%rbp)
movslq -0x30(%rbp), %rax
cmpq 0x20a7989(%rip), %rax   # 0x20ad3d0
jae 0x5c07
movslq -0x30(%rbp), %rcx
leaq 0x20a6978(%rip), %rax   # 0x20ac3d0
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
cmpl $0x1, -0x4(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xbc(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x7588(%rip), %rsi      # 0xd00c
movl $0x3, %edx
callq 0x2070
movl %eax, %ecx
movl -0xbc(%rbp), %eax
cmpl $0x0, %ecx
sete %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x5ac2
movq -0x40(%rbp), %rax
cmpl $0x1f802, (%rax)        # imm = 0x1F802
je 0x5ac2
movq -0x40(%rbp), %rax
cmpl $0x1f805, (%rax)        # imm = 0x1F805
jne 0x5bf7
movsbl -0x29(%rbp), %edx
movq -0x40(%rbp), %rax
movl (%rax), %ecx
movq -0x40(%rbp), %rax
movq 0x8(%rax), %r8
leaq -0x28(%rbp), %rdi
leaq 0x74d3(%rip), %rsi      # 0xcfb2
movb $0x0, %al
callq 0xa2b0
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jae 0x5be3
movq -0x40(%rbp), %rax
addq $0x10, %rax
movslq -0x34(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x10(%rbp), %rax
jae 0x5b38
movq -0x40(%rbp), %rax
cmpl $0x1f014, (%rax)        # imm = 0x1F014
jne 0x5bd3
movq -0x98(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0xcc(%rbp)
movq -0x98(%rbp), %rax
movq 0x20(%rax), %rdx
leaq 0x6cb5(%rip), %rax      # 0xc80f
leaq 0x74a4(%rip), %rcx      # 0xd005
cmpq $0x0, %rdx
cmovneq %rcx, %rax
movq %rax, -0xc8(%rbp)
movq -0x98(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x5b92
movq -0x98(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xd8(%rbp)
jmp 0x5ba2
leaq 0x6c76(%rip), %rax      # 0xc80f
movq %rax, -0xd8(%rbp)
jmp 0x5ba2
movq -0xc8(%rbp), %rcx
movl -0xcc(%rbp), %edx
movq -0xd8(%rbp), %r8
movq -0x98(%rbp), %rax
movq 0x28(%rax), %r9
leaq -0x28(%rbp), %rdi
leaq 0x7444(%rip), %rsi      # 0xd010
movb $0x0, %al
callq 0xa2b0
jmp 0x5bd5
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x5aed
leaq -0x28(%rbp), %rdi
leaq 0x7419(%rip), %rsi      # 0xd007
callq 0xa500
movb $0x2c, -0x29(%rbp)
jmp 0x5bf9
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x5a3c
jmp 0x5c09
movsbl -0x29(%rbp), %eax
cmpl $0x2c, %eax
jne 0x5c24
leaq -0x28(%rbp), %rdi
leaq 0x73ec(%rip), %rsi      # 0xd009
callq 0xa500
jmp 0x5c34
leaq -0x28(%rbp), %rdi
leaq 0x6bdf(%rip), %rsi      # 0xc80e
callq 0xa500
movq -0x20(%rbp), %rsi
leaq 0x73e0(%rip), %rdi      # 0xd01f
movb $0x0, %al
callq 0x9ae0
movq -0x28(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)