// File: /workspace/github_c_makefile_star2_O3/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 0x7b8c(%rip), %esi      # 0xb250
movzbl 0x7b66(%rip), %edx      # 0xb231
leaq 0x4299(%rip), %rdi      # 0x796b
xorl %eax, %eax
callq 0x3ae9
movl 0x7b71(%rip), %esi      # 0xb250
testl %esi, %esi
jle 0x38c4
leal -0x2(%rsi), %eax
cmpl $0xc, %eax
ja 0x3733
leaq 0x390e(%rip), %rcx      # 0x7004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x1, 0x7ae7(%rip)      # 0xb1ed
jne 0x3724
leaq 0x7b29(%rip), %rdi      # 0xb238
leaq 0x433c(%rip), %rsi      # 0x7a52
leaq 0x4345(%rip), %rdx      # 0x7a62
xorl %eax, %eax
callq 0x3f95
movl $0x0, 0x7b22(%rip)      # 0xb250
jmp 0x38c4
leaq 0x433b(%rip), %rdi      # 0x7a75
xorl %eax, %eax
popq %rbx
jmp 0x39d8
movq 0x7ac7(%rip), %rax      # 0xb210
orq 0x7aa8(%rip), %rax      # 0xb1f8
je 0x37ea
leaq 0x7adb(%rip), %rdi      # 0xb238
leaq 0x42ee(%rip), %rsi      # 0x7a52
leaq 0x425b(%rip), %rdx      # 0x79c6
jmp 0x38b7
leaq 0x421c(%rip), %rdi      # 0x7993
xorl %eax, %eax
callq 0x39d8
leaq 0x7ab3(%rip), %rdi      # 0xb238
leaq 0x42c6(%rip), %rsi      # 0x7a52
leaq 0x421f(%rip), %rdx      # 0x79b2
jmp 0x38b7
cmpq $0x0, 0x7a58(%rip)      # 0xb1f8
je 0x37ea
movq 0x7a47(%rip), %rsi      # 0xb1f0
testq %rsi, %rsi
leaq 0x3f9a(%rip), %rbx      # 0x774d
cmoveq %rbx, %rsi
leaq 0x421a(%rip), %rdi      # 0x79d8
xorl %eax, %eax
callq 0x39d8
movq 0x7a24(%rip), %rcx      # 0xb1f0
testq %rcx, %rcx
cmoveq %rbx, %rcx
leaq 0x7a5e(%rip), %rdi      # 0xb238
leaq 0x4211(%rip), %rsi      # 0x79f2
leaq 0x4212(%rip), %rdx      # 0x79fa
jmp 0x3844
movl $0x8, 0x7a5c(%rip)      # 0xb250
cmpq $0x0, 0x7a14(%rip)      # 0xb210
je 0x384d
movq 0x7a03(%rip), %rsi      # 0xb208
testq %rsi, %rsi
leaq 0x3f3e(%rip), %rbx      # 0x774d
cmoveq %rbx, %rsi
leaq 0x41ee(%rip), %rdi      # 0x7a08
xorl %eax, %eax
callq 0x39d8
movq 0x79e0(%rip), %rcx      # 0xb208
testq %rcx, %rcx
cmoveq %rbx, %rcx
leaq 0x7a02(%rip), %rdi      # 0xb238
leaq 0x41b5(%rip), %rsi      # 0x79f2
leaq 0x41de(%rip), %rdx      # 0x7a22
xorl %eax, %eax
callq 0x3f95
jmp 0x38be
movl $0x6, 0x79f9(%rip)      # 0xb250
cmpb $0x0, 0x798d(%rip)      # 0xb1eb
jne 0x386e
movl $0x7, %edi
callq 0x3d1c
testb %al, %al
je 0x3885
leaq 0x79c3(%rip), %rdi      # 0xb238
leaq 0x41d6(%rip), %rsi      # 0x7a52
leaq 0x41ad(%rip), %rdx      # 0x7a30
jmp 0x38b7
movl $0x4, 0x79c1(%rip)      # 0xb250
cmpq $0x0, 0x7961(%rip)      # 0xb1f8
leaq 0x41c0(%rip), %rax      # 0x7a5e
leaq 0x41b2(%rip), %rdx      # 0x7a57
cmoveq %rax, %rdx
leaq 0x7988(%rip), %rdi      # 0xb238
leaq 0x418a(%rip), %rsi      # 0x7a41
xorl %eax, %eax
callq 0x3f95
decl 0x798c(%rip)            # 0xb250
popq %rbx
retq
nop