// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, -0x48(%rbp)
testl %edi, %edi
jle 0x1749
movq %rsi, %r15
movl %edi, %r14d
movl %edi, %r13d
xorl %ebx, %ebx
movq %r13, %r12
movq (%r15,%rbx,8), %rdi
callq 0x1080
addq %rax, %r12
incq %rbx
cmpq %rbx, %r13
jne 0x1609
movq %rsp, -0x30(%rbp)
leaq 0x6(%r12), %rax
movq %rax, -0x40(%rbp)
movq %rsp, %rax
addq $0x15, %r12
andq $-0x10, %r12
movq %rax, %rcx
subq %r12, %rcx
movq %rcx, %rsp
negq %r12
movl $0x72617473, (%rax,%r12) # imm = 0x72617473
movw $0x74, 0x4(%rcx)
movq %rcx, -0x38(%rbp)
leaq 0x5(%rcx), %rbx
movq %r15, -0x50(%rbp)
xorl %r15d, %r15d
movb $0x20, (%rbx)
leaq 0x1(%rbx), %rdi
movq -0x50(%rbp), %rax
movq (%rax,%r15,8), %r12
movq %r12, %rsi
callq 0x1060
movq %r12, %rdi
callq 0x1080
addq %rax, %rbx
incq %rbx
incq %r15
cmpq %r15, %r13
jne 0x165e
movl $0x1, %edx
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rbx
movq %rbx, %rcx
callq 0x10f0
cmpq $0x1, %rax
jne 0x174e
movq %rbx, %rdi
callq 0x10b0
testl %eax, %eax
jne 0x1753
movq -0x30(%rbp), %rsp
leaq 0xa8d(%rip), %r15       # 0x2156
movq %rbx, %rdi
callq 0x15a9
movq %rax, %r12
movb (%rax), %dl
testb %dl, %dl
je 0x1709
xorl %ecx, %ecx
movq %r12, %rax
xorl %edi, %edi
movl %ecx, %esi
xorl %ecx, %ecx
cmpb $0x20, %dl
sete %cl
cmoveq %rax, %rdi
addl %esi, %ecx
movb 0x1(%rax), %dl
cmpl $0x2, %ecx
setb %sil
testb %dl, %dl
je 0x170e
incq %rax
cmpl $0x2, %ecx
jb 0x16e1
jmp 0x170e
movb $0x1, %sil
xorl %edi, %edi
testb %sil, %sil
jne 0x1741
incq %rdi
movq %r15, %rsi
callq 0x1090
cmpl $0x1, %eax
sbbl $0x0, %r14d
movq %r12, %rdi
callq 0x1040
testl %r14d, %r14d
jg 0x16c9
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
callq 0x12a2
callq 0x12c6
callq 0x124a
callq 0x126f