// File: /workspace/github_c_makefile_star2_O0/panux[P]linit/src/linitd.c
// Function: handle_scmd
void handle_scmd(struct conn *c) {
    ref(c);
    //extract command from rx buffer
    char *cmds = strdup(c->rx.dat);
    if(cmds == NULL) {
        fprintf(stderr, "[ERROR] Failed to extract command from conn %d\n", c->fd);
        close_conn(c);
        goto end;
    }
    //slide & shrink rx buffer
    memmove(c->rx.dat, c->rx.dat + strlen(cmds) + 1, c->rx.len - (strlen(cmds) + 1));
    c->rx.len -= strlen(cmds) + 1;
    byte *ndat = realloc(c->rx.dat, c->rx.len);
    if(ndat != NULL) {
        c->rx.dat = ndat;
    }
    //split command and args
    if(!hasSpace(cmds)) {
        fprintf(stderr, "[ERROR] Invalid command syntax (sent by conn %d): \"%s\"\n", c->fd, cmds);
        free(cmds);
        close_conn(c);
        goto end;
    }
    char *cmd, *args;
    for(cmd = args = cmds; *args != ' '; args++) {}
    *args = '\0';
    args++;
    //run handler
    if(streq(cmd, "start")) {
        cmd_start(c, args);
    } else if(streq(cmd, "stop")) {
        cmd_stop(c, args);
    } else if(streq(cmd, "state")) {
        cmd_state(c, args);
    } else {
        fprintf(stderr, "[ERROR] Unrecognized command \"%s\" sent on conn %d\n", cmd, c->fd);
        free(cmds);
        close_conn(c);
        goto end;
    }
    //cleanup
    free(cmds);
end:
    deref(c);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x1220
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x25ee
movq 0x4a30(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edx
leaq 0x20fb(%rip), %rsi      # 0x46d4
movb $0x0, %al
callq 0x1140
movq -0x8(%rbp), %rdi
callq 0x1620
jmp 0x27ce
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1090
movq %rax, %rcx
movq -0x48(%rbp), %rax
addq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1090
movq -0x40(%rbp), %rdx
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
addq $0x1, %rax
subq %rax, %rdx
callq 0x11c0
movq -0x10(%rbp), %rdi
callq 0x1090
movq %rax, %rdx
addq $0x1, %rdx
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x28(%rax)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x1180
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x2699
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rdi
callq 0x2990
testb $0x1, %al
jne 0x26e0
movq 0x494b(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edx
movq -0x10(%rbp), %rcx
leaq 0x2042(%rip), %rsi      # 0x4704
movb $0x0, %al
callq 0x1140
movq -0x10(%rbp), %rdi
callq 0x1030
movq -0x8(%rbp), %rdi
callq 0x1620
jmp 0x27ce
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
je 0x2708
jmp 0x26fa
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x26ec
movq -0x28(%rbp), %rax
movb $0x0, (%rax)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x1cdc(%rip), %rsi      # 0x4402
callq 0x1130
cmpl $0x0, %eax
jne 0x2742
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x29e0
jmp 0x27c5
movq -0x20(%rbp), %rdi
leaq 0x1cc1(%rip), %rsi      # 0x440e
callq 0x1130
cmpl $0x0, %eax
jne 0x2766
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x2d60
jmp 0x27c3
movq -0x20(%rbp), %rdi
leaq 0x1fcb(%rip), %rsi      # 0x473c
callq 0x1130
cmpl $0x0, %eax
jne 0x278a
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x3150
jmp 0x27c1
movq 0x4867(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
leaq 0x1f9c(%rip), %rsi      # 0x4742
movb $0x0, %al
callq 0x1140
movq -0x10(%rbp), %rdi
callq 0x1030
movq -0x8(%rbp), %rdi
callq 0x1620
jmp 0x27ce
jmp 0x27c3
jmp 0x27c5
movq -0x10(%rbp), %rdi
callq 0x1030
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %eax
movl %eax, %edx
addl $-0x1, %edx
movl %edx, 0x10(%rcx)
cmpl $0x0, %eax
jne 0x27eb
movq -0x8(%rbp), %rdi
callq 0x1030
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)