// File: /workspace/github_c_makefile_star2_O1/canboat[P]canboat/ikonvert-serial/ikonvert-serial.c
// Function: sendNextInitCommand
static void sendNextInitCommand(void)
{
  logDebug("sendNextInitCommand state=%d serial=%d\n", sendInitState, isSerialDevice);
  if (sendInitState > 0)
  {
    switch (sendInitState)
    {
      case 14:
        logInfo("iKonvert initialization start\n");
        sbAppendFormat(&writeBuffer, "%s\r\n", TX_OFFLINE_MSG);
        break;

      case 12:
        if (sbGetLength(&rxList) > 0 || sbGetLength(&txList) > 0)
        {
          sbAppendFormat(&writeBuffer, "%s\r\n", TX_RESET_MSG);
          break;
        }
        sendInitState = 10;
        // and fallthru

      case 10:
        if (sbGetLength(&rxList) > 0)
        {
          logInfo("iKonvert send RX list %s\n", sbGet(&rxList));
          sbAppendFormat(&writeBuffer, "%s,%s\r\n", TX_SET_RX_LIST_MSG, sbGet(&rxList));
          break;
        }
        sendInitState = 8;
        // and fallthru

      case 8:
        if (sbGetLength(&txList) > 0)
        {
          logInfo("iKonvert send TX list %s\n", sbGet(&txList));
          sbAppendFormat(&writeBuffer, "%s,%s\r\n", TX_SET_TX_LIST_MSG, sbGet(&txList));
          break;
        }
        sendInitState = 6;
        // and fallthru

      case 6:
        if (verbose || isLogLevelEnabled(LOG_DEBUG))
        {
          sbAppendFormat(&writeBuffer, "%s\r\n", TX_SHOWLISTS_MSG);
          break;
        }
        sendInitState = 4;
        // and fallthru

      case 4:
        sbAppendFormat(&writeBuffer, TX_ONLINE_MSG "\r\n", sbGetLength(&rxList) > 0 ? "NORMAL" : "ALL");
        break;

      case 2:
        if (rate_limit_off)
        {
          sbAppendFormat(&writeBuffer, "%s\r\n", TX_LIMIT_OFF);
          // Note: this has no confirmation, so reset init and set initstate to 0
        }
        sendInitState = 0;
        return;

      default:
        logInfo("Waiting for ack value %d\n", sendInitState);
        return;
    }
    sendInitState--;
  }
}

// Assembly:
pushq %rbx
movl 0x7bcb(%rip), %esi      # 0xb250
movzbl 0x7ba5(%rip), %edx      # 0xb231
leaq 0x42d8(%rip), %rdi      # 0x796b
xorl %eax, %eax
callq 0x3ab1
movl 0x7bb0(%rip), %esi      # 0xb250
testl %esi, %esi
jle 0x388b
leal -0x2(%rsi), %eax
cmpl $0xc, %eax
ja 0x36f4
leaq 0x394d(%rip), %rcx      # 0x7004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x1, 0x7b26(%rip)      # 0xb1ed
jne 0x36e5
leaq 0x7b68(%rip), %rdi      # 0xb238
leaq 0x437b(%rip), %rsi      # 0x7a52
leaq 0x4384(%rip), %rdx      # 0x7a62
xorl %eax, %eax
callq 0x3f7f
movl $0x0, 0x7b61(%rip)      # 0xb250
jmp 0x388b
leaq 0x437a(%rip), %rdi      # 0x7a75
xorl %eax, %eax
popq %rbx
jmp 0x39a0
movq 0x7b06(%rip), %rax      # 0xb210
orq 0x7ae7(%rip), %rax      # 0xb1f8
je 0x3755
leaq 0x7b1e(%rip), %rdi      # 0xb238
leaq 0x4331(%rip), %rsi      # 0x7a52
leaq 0x429e(%rip), %rdx      # 0x79c6
jmp 0x387e
leaq 0x425f(%rip), %rdi      # 0x7993
xorl %eax, %eax
callq 0x39a0
leaq 0x7af6(%rip), %rdi      # 0xb238
leaq 0x4309(%rip), %rsi      # 0x7a52
leaq 0x4262(%rip), %rdx      # 0x79b2
jmp 0x387e
movl $0xa, 0x7af1(%rip)      # 0xb250
cmpq $0x0, 0x7a91(%rip)      # 0xb1f8
je 0x37b1
movq 0x7a80(%rip), %rsi      # 0xb1f0
testq %rsi, %rsi
leaq 0x3fd3(%rip), %rbx      # 0x774d
cmoveq %rbx, %rsi
leaq 0x4253(%rip), %rdi      # 0x79d8
xorl %eax, %eax
callq 0x39a0
movq 0x7a5d(%rip), %rcx      # 0xb1f0
testq %rcx, %rcx
cmoveq %rbx, %rcx
leaq 0x7a97(%rip), %rdi      # 0xb238
leaq 0x424a(%rip), %rsi      # 0x79f2
leaq 0x424b(%rip), %rdx      # 0x79fa
jmp 0x380b
movl $0x8, 0x7a95(%rip)      # 0xb250
cmpq $0x0, 0x7a4d(%rip)      # 0xb210
je 0x3814
movq 0x7a3c(%rip), %rsi      # 0xb208
testq %rsi, %rsi
leaq 0x3f77(%rip), %rbx      # 0x774d
cmoveq %rbx, %rsi
leaq 0x4227(%rip), %rdi      # 0x7a08
xorl %eax, %eax
callq 0x39a0
movq 0x7a19(%rip), %rcx      # 0xb208
testq %rcx, %rcx
cmoveq %rbx, %rcx
leaq 0x7a3b(%rip), %rdi      # 0xb238
leaq 0x41ee(%rip), %rsi      # 0x79f2
leaq 0x4217(%rip), %rdx      # 0x7a22
xorl %eax, %eax
callq 0x3f7f
jmp 0x3885
movl $0x6, 0x7a32(%rip)      # 0xb250
cmpb $0x0, 0x79c6(%rip)      # 0xb1eb
jne 0x3835
movl $0x7, %edi
callq 0x3ce8
testb %al, %al
je 0x384c
leaq 0x79fc(%rip), %rdi      # 0xb238
leaq 0x420f(%rip), %rsi      # 0x7a52
leaq 0x41e6(%rip), %rdx      # 0x7a30
jmp 0x387e
movl $0x4, 0x79fa(%rip)      # 0xb250
cmpq $0x0, 0x799a(%rip)      # 0xb1f8
leaq 0x41f9(%rip), %rax      # 0x7a5e
leaq 0x41eb(%rip), %rdx      # 0x7a57
cmoveq %rax, %rdx
leaq 0x79c1(%rip), %rdi      # 0xb238
leaq 0x41c3(%rip), %rsi      # 0x7a41
xorl %eax, %eax
callq 0x3f7f
decl 0x79c5(%rip)            # 0xb250
popq %rbx
retq
nopl (%rax)