// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl 0x9172(%rip), %esi      # 0xca80
movb 0x914d(%rip), %al       # 0xca61
andb $0x1, %al
movzbl %al, %edx
leaq 0x604b(%rip), %rdi      # 0x996b
movb $0x0, %al
callq 0x4640
cmpl $0x0, 0x9152(%rip)      # 0xca80
jle 0x3bc2
movl 0x9146(%rip), %eax      # 0xca80
addl $-0x2, %eax
movl %eax, %ecx
movq %rcx, -0x8(%rbp)
subl $0xc, %eax
ja 0x3b9d
movq -0x8(%rbp), %rax
leaq 0x56ad(%rip), %rcx      # 0x9004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x602c(%rip), %rdi      # 0x9993
movb $0x0, %al
callq 0x44f0
leaq 0x90f3(%rip), %rdi      # 0xca68
leaq 0x60d6(%rip), %rsi      # 0x9a52
leaq 0x602f(%rip), %rdx      # 0x99b2
movb $0x0, %al
callq 0x4e10
jmp 0x3bb3
cmpq $0x0, 0x9091(%rip)      # 0xca28
ja 0x39a3
cmpq $0x0, 0x909f(%rip)      # 0xca40
jbe 0x39c4
leaq 0x90be(%rip), %rdi      # 0xca68
leaq 0x60a1(%rip), %rsi      # 0x9a52
leaq 0x600e(%rip), %rdx      # 0x99c6
movb $0x0, %al
callq 0x4e10
jmp 0x3bb3
movl $0xa, 0x90b2(%rip)      # 0xca80
cmpq $0x0, 0x9052(%rip)      # 0xca28
jbe 0x3a57
cmpq $0x0, 0x9040(%rip)      # 0xca20
je 0x39ef
movq 0x9037(%rip), %rax      # 0xca20
movq %rax, -0x10(%rbp)
jmp 0x39fc
leaq 0x5d57(%rip), %rax      # 0x974d
movq %rax, -0x10(%rbp)
jmp 0x39fc
movq -0x10(%rbp), %rsi
leaq 0x5fd1(%rip), %rdi      # 0x99d8
movb $0x0, %al
callq 0x44f0
cmpq $0x0, 0x900a(%rip)      # 0xca20
je 0x3a25
movq 0x9001(%rip), %rax      # 0xca20
movq %rax, -0x18(%rbp)
jmp 0x3a32
leaq 0x5d21(%rip), %rax      # 0x974d
movq %rax, -0x18(%rbp)
jmp 0x3a32
movq -0x18(%rbp), %rcx
leaq 0x902b(%rip), %rdi      # 0xca68
leaq 0x5fae(%rip), %rsi      # 0x99f2
leaq 0x5faf(%rip), %rdx      # 0x99fa
movb $0x0, %al
callq 0x4e10
jmp 0x3bb3
movl $0x8, 0x901f(%rip)      # 0xca80
cmpq $0x0, 0x8fd7(%rip)      # 0xca40
jbe 0x3aea
cmpq $0x0, 0x8fc5(%rip)      # 0xca38
je 0x3a82
movq 0x8fbc(%rip), %rax      # 0xca38
movq %rax, -0x20(%rbp)
jmp 0x3a8f
leaq 0x5cc4(%rip), %rax      # 0x974d
movq %rax, -0x20(%rbp)
jmp 0x3a8f
movq -0x20(%rbp), %rsi
leaq 0x5f6e(%rip), %rdi      # 0x9a08
movb $0x0, %al
callq 0x44f0
cmpq $0x0, 0x8f8f(%rip)      # 0xca38
je 0x3ab8
movq 0x8f86(%rip), %rax      # 0xca38
movq %rax, -0x28(%rbp)
jmp 0x3ac5
leaq 0x5c8e(%rip), %rax      # 0x974d
movq %rax, -0x28(%rbp)
jmp 0x3ac5
movq -0x28(%rbp), %rcx
leaq 0x8f98(%rip), %rdi      # 0xca68
leaq 0x5f1b(%rip), %rsi      # 0x99f2
leaq 0x5f44(%rip), %rdx      # 0x9a22
movb $0x0, %al
callq 0x4e10
jmp 0x3bb3
movl $0x6, 0x8f8c(%rip)      # 0xca80
testb $0x1, 0x8f20(%rip)      # 0xca1b
jne 0x3b0d
movl $0x7, %edi
callq 0x4950
testb $0x1, %al
jne 0x3b0d
jmp 0x3b2e
leaq 0x8f54(%rip), %rdi      # 0xca68
leaq 0x5f37(%rip), %rsi      # 0x9a52
leaq 0x5f0e(%rip), %rdx      # 0x9a30
movb $0x0, %al
callq 0x4e10
jmp 0x3bb3
movl $0x4, 0x8f48(%rip)      # 0xca80
movq 0x8ee9(%rip), %rcx      # 0xca28
leaq 0x5f18(%rip), %rdx      # 0x9a5e
leaq 0x5f0a(%rip), %rax      # 0x9a57
cmpq $0x0, %rcx
cmovaq %rax, %rdx
leaq 0x8f0c(%rip), %rdi      # 0xca68
leaq 0x5ede(%rip), %rsi      # 0x9a41
movb $0x0, %al
callq 0x4e10
jmp 0x3bb3
testb $0x1, 0x8eaa(%rip)      # 0xca1d
je 0x3b91
leaq 0x8eec(%rip), %rdi      # 0xca68
leaq 0x5ecf(%rip), %rsi      # 0x9a52
leaq 0x5ed8(%rip), %rdx      # 0x9a62
movb $0x0, %al
callq 0x4e10
movl $0x0, 0x8ee5(%rip)      # 0xca80
jmp 0x3bc2
movl 0x8edd(%rip), %esi      # 0xca80
leaq 0x5ecb(%rip), %rdi      # 0x9a75
movb $0x0, %al
callq 0x44f0
jmp 0x3bc2
movl 0x8ec7(%rip), %eax      # 0xca80
addl $-0x1, %eax
movl %eax, 0x8ebe(%rip)      # 0xca80
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)