// File: /workspace/github_c_makefile_star2_O0/panux[P]linit/src/linitctl.c
// Function: cmd_start
void cmd_start(int argc, char **argv, FILE *stream) {
    if(argc < 1) {
        fprintf(stderr, "[FATAL] Missing arguments\n");
        exit(1);
    }
    //send command
    {
        //calculate length of command string
        size_t n = argc;                        //spaces
        for(size_t i = 0; i < argc; i++) {
            n += strlen(argv[i]);               //strings
        }
        char pre[] = "start";
        n += strlen(pre);                       //length of pre
        n++;                                    //null terminator
        //generate command string
        char cmd[n];
        char *c = cmd;
        strcpy(c, pre); c += strlen(pre);
        for(size_t i = 0; i < argc; i++) {
            *c = ' ';
            c++;
            strcpy(c, argv[i]);
            c += strlen(argv[i]);
        }
        //send command string
        if(fwrite(cmd, n, 1, stream) != 1) {
            fprintf(stderr, "[FATAL] Failed to write command\n");
            exit(65);
        }
        if(fflush(stream) != 0) {
            fprintf(stderr, "[FATAL] Failed to flush stream: %s\n", strerror(errno));
            exit(65);
        }
    }
    //wait for completion
    while(argc > 0) {
        char *resp = rcvResp(stream);
        char *stat = NULL;
        int nspace = 0;
        for(size_t i = 0; (resp[i] != '\0') && (nspace < 2); i++) {
            if(resp[i] == ' ') {
                stat = resp + i;
                nspace++;
            }
        }
        stat++;
        if(nspace < 2) {
            fprintf(stderr, "[FATAL] Bad response: \"%s\"\n", resp);
            exit(65);
        }
        if(strcmp(stat, "running") == 0) {
            argc--;
        }
        free(resp);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpl $0x1, -0x4(%rbp)
jge 0x149e
movq 0x2b75(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xc4d(%rip), %rsi       # 0x20da
movb $0x0, %al
callq 0x10b0
movl $0x1, %edi
callq 0x10e0
movslq -0x4(%rbp), %rax
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rax
movslq -0x4(%rbp), %rcx
cmpq %rcx, %rax
jae 0x14e2
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1080
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x14ae
movw $0x74, -0x2c(%rbp)
movl $0x72617473, -0x30(%rbp) # imm = 0x72617473
leaq -0x30(%rbp), %rdi
callq 0x1080
movq %rax, %rcx
movq -0x20(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
incq %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rcx
movq %rsp, %rax
movq %rax, -0x38(%rbp)
movq %rcx, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rax
subq %rdx, %rax
movq %rax, -0x78(%rbp)
movq %rax, %rsp
movq %rcx, -0x40(%rbp)
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1060
leaq -0x30(%rbp), %rdi
callq 0x1080
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movslq -0x4(%rbp), %rcx
cmpq %rcx, %rax
jae 0x15be
movq -0x48(%rbp), %rax
movb $0x20, (%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x1060
movq -0x10(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1080
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x1562
movq -0x78(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x18(%rbp), %rcx
movl $0x1, %edx
callq 0x1100
cmpq $0x1, %rax
je 0x15fc
movq 0x2a17(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xb10(%rip), %rsi       # 0x20fb
movb $0x0, %al
callq 0x10b0
movl $0x41, %edi
callq 0x10e0
movq -0x18(%rbp), %rdi
callq 0x10c0
cmpl $0x0, %eax
je 0x1643
movq 0x29e7(%rip), %rax      # 0x3ff8
movq (%rax), %rax
movq %rax, -0x80(%rbp)
callq 0x1050
movl (%rax), %edi
callq 0x1110
movq -0x80(%rbp), %rdi
movq %rax, %rdx
leaq 0xaea(%rip), %rsi       # 0x211c
movb $0x0, %al
callq 0x10b0
movl $0x41, %edi
callq 0x10e0
movq -0x38(%rbp), %rax
movq %rax, %rsp
cmpl $0x0, -0x4(%rbp)
jle 0x1744
movq -0x18(%rbp), %rdi
callq 0x13f0
movq %rax, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x58(%rbp), %rax
movq -0x70(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x81(%rbp)
je 0x169e
cmpl $0x2, -0x64(%rbp)
setl %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x16aa
jmp 0x16e0
movq -0x58(%rbp), %rax
movq -0x70(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jne 0x16d0
movq -0x58(%rbp), %rax
addq -0x70(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x16d2
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x1678
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
cmpl $0x2, -0x64(%rbp)
jge 0x1718
movq 0x28ff(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x58(%rbp), %rdx
leaq 0xa39(%rip), %rsi       # 0x2140
movb $0x0, %al
callq 0x10b0
movl $0x41, %edi
callq 0x10e0
movq -0x60(%rbp), %rdi
leaq 0xa39(%rip), %rsi       # 0x215c
callq 0x10a0
cmpl $0x0, %eax
jne 0x1736
movl -0x4(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x4(%rbp)
movq -0x58(%rbp), %rdi
callq 0x1040
jmp 0x164a
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)