// File: /workspace/github_c_makefile_star2_O2/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
testl %edi, %edi
jle 0x154c
movq %rdx, %r14
movq %rsi, %r15
movl %edi, -0x2c(%rbp)
movl %edi, %r13d
xorl %ebx, %ebx
movq %r13, %r12
cmpq %rbx, %r13
je 0x141a
movq (%r15,%rbx,8), %rdi
callq 0x1080
addq %rax, %r12
incq %rbx
jmp 0x1404
movq %r14, -0x50(%rbp)
movq %rsp, -0x38(%rbp)
leaq 0x6(%r12), %rax
movq %rax, -0x48(%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, -0x40(%rbp)
leaq 0x5(%rcx), %rbx
xorl %r14d, %r14d
cmpq %r14, %r13
je 0x1486
movb $0x20, (%rbx)
leaq 0x1(%rbx), %rdi
movq (%r15,%r14,8), %r12
movq %r12, %rsi
callq 0x1060
movq %r12, %rdi
callq 0x1080
addq %rax, %rbx
incq %rbx
incq %r14
jmp 0x145b
pushq $0x1
popq %rdx
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rbx
movq %rbx, %rcx
callq 0x10f0
cmpq $0x1, %rax
jne 0x156c
movq %rbx, %rdi
callq 0x10b0
testl %eax, %eax
movl -0x2c(%rbp), %r14d
jne 0x158a
movq -0x38(%rbp), %rsp
leaq 0xc90(%rip), %r15       # 0x2156
testl %r14d, %r14d
jle 0x151a
movq %rbx, %rdi
callq 0x1386
movq %rax, %r12
xorl %edi, %edi
xorl %ecx, %ecx
movb (%rax), %dl
testb %dl, %dl
je 0x14f9
cmpl $0x2, %ecx
jae 0x14f9
xorl %esi, %esi
cmpb $0x20, %dl
sete %sil
cmoveq %rax, %rdi
addl %esi, %ecx
incq %rax
jmp 0x14da
cmpl $0x2, %ecx
jb 0x1529
incq %rdi
movq %r15, %rsi
callq 0x1090
cmpl $0x1, %eax
sbbl $0x0, %r14d
movq %r12, %rdi
callq 0x1040
jmp 0x14c6
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2ac8(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xc00(%rip), %rsi       # 0x213a
movq %r12, %rdx
xorl %eax, %eax
callq 0x10a0
pushq $0x41
popq %rdi
callq 0x10d0
movq 0x2aa5(%rip), %rax      # 0x3ff8
movq (%rax), %rcx
leaq 0xb7d(%rip), %rdi       # 0x20da
pushq $0x1a
popq %rsi
pushq $0x1
popq %rdx
callq 0x10f0
pushq $0x1
jmp 0x1546
movq 0x2a85(%rip), %rax      # 0x3ff8
movq (%rax), %rcx
leaq 0xb78(%rip), %rdi       # 0x20f5
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
callq 0x10f0
jmp 0x1544
movq 0x2a67(%rip), %rax      # 0x3ff8
movq (%rax), %rbx
callq 0x1050
movl (%rax), %edi
callq 0x1100
leaq 0xb6f(%rip), %rsi       # 0x2116
movq %rbx, %rdi
movq %rax, %rdx
jmp 0x153d