// File: /workspace/github_c_makefile_star2_O3/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 0x171f
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 0x15ed
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 0x1642
movl $0x1, %edx
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rbx
movq %rbx, %rcx
callq 0x10f0
cmpq $0x1, %rax
jne 0x1724
movq %rbx, %rdi
callq 0x10b0
testl %eax, %eax
jne 0x1729
movq -0x30(%rbp), %rsp
leaq 0xaa9(%rip), %r15       # 0x2156
movq %rbx, %rdi
callq 0x158d
movq %rax, %r12
movb (%rax), %dl
testb %dl, %dl
je 0x1717
xorl %eax, %eax
movq %r12, %rcx
xorl %edi, %edi
movl %eax, %esi
xorl %eax, %eax
cmpb $0x20, %dl
cmoveq %rcx, %rdi
sete %al
addl %esi, %eax
movb 0x1(%rcx), %dl
testb %dl, %dl
je 0x16e4
incq %rcx
cmpl $0x2, %eax
jb 0x16c5
cmpl $0x2, %eax
jb 0x1717
incq %rdi
movq %r15, %rsi
callq 0x1090
cmpl $0x1, %eax
sbbl $0x0, %r14d
movq %r12, %rdi
callq 0x1040
testl %r14d, %r14d
jg 0x16ad
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