// File: /workspace/github_c_makefile_star2_O0/panux[P]linit/src/linitd.c
// Function: cmd_start
void cmd_start(struct conn *c, char *args) {
    if(c->closed) {
        return;
    }
    ref(c);
    if(hasSpace(args)) {    //starting multiple - break into multiple commands
        char *arg, *a;
        arg = a = args;
        for(;;) {
            switch(*a) {
            case '\0':
                cmd_start(c, arg);
                goto end;
            case ' ':
                *a = '\0';
                cmd_start(c, arg);
                a = arg = a + 1;
                break;
            default:
                a++;
            }
        }
    } else {
        struct service *svc = findService(args);
        if(svc != NULL) {   //service already started
            if(!setNotify(svc, c)) {
                fprintf(stderr, "Failed to set conn %d to be notified about %s\n", c->fd, args);
                close_conn(c);
                goto end;
            }
            //format: "notify %s %s", args, status
            char not[] = "notify ";
            char *status = statestr(svc->state);
            char ntxt[strlen(not) + strlen(args) + strlen(status) + 2];
            char *nt = ntxt;
            strcpy(nt, not);
            nt += strlen(not);
            strcpy(nt, args);
            nt += strlen(args);
            *nt = ' ';
            nt++;
            strcpy(nt, status);
            struct buf dat = { .dat = ntxt, .len = strlen(ntxt) + 1 };
            if(notify(c, svc, dat) != notify_success) {
                fprintf(stderr, "Failed to notify conn %d about the state of %s\n", c->fd, args);
                close_conn(c);
                goto end;
            }
        } else {            //start service and mark to be notified
            struct service *ns = newService();
            if(ns == NULL) {
                fprintf(stderr, "[ERROR] Failed to start service %s: out of memory\n", args);
                close_conn(c);  //we cant notify the service because we are out of memory
                goto end;
            }
            ns->name = strdup(args);
            ns->state = service_status_starting;
            setNotify(ns, c);
            if(!runStart(args)) {
                fprintf(stderr, "[ERROR] Failed to start service %s: fork/exec error\n", args);
                ns->state = service_status_fail;
            }
            if(!notifyAll(ns)) {    //notify client of start
                fprintf(stderr, "[ERROR] Failed to send notification about %s to conn %d\n", args, c->fd);
                close_conn(c);
                goto end;
            }
            if(ns->state == service_status_fail) {  //delete the service if it failed
                rmService(ns->name);
            }
        }
    }
end:
    deref(c);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
testb $0x1, 0x18(%rax)
je 0x2a02
jmp 0x2d57
movq -0x8(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rdi
callq 0x2990
testb $0x1, %al
jne 0x2a1e
jmp 0x2a8a
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x74(%rbp)
testl %eax, %eax
je 0x2a44
jmp 0x2a3a
movl -0x74(%rbp), %eax
subl $0x20, %eax
je 0x2a56
jmp 0x2a7c
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x29e0
jmp 0x2d3a
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x29e0
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq %rax, -0x20(%rbp)
jmp 0x2a88
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x2a2a
movq -0x10(%rbp), %rdi
callq 0x1990
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2c4a
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x1420
testb $0x1, %al
jne 0x2ae4
movq 0x453e(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edx
movq -0x10(%rbp), %rcx
leaq 0x1944(%rip), %rsi      # 0x4413
movb $0x0, %al
callq 0x1140
movq -0x8(%rbp), %rdi
callq 0x1620
jmp 0x2d3a
movabsq $0x20796669746f6e, %rax # imm = 0x20796669746F6E
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %edi
callq 0x13a0
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x1090
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1090
movq %rax, %rcx
movq -0x90(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x38(%rbp), %rdi
callq 0x1090
movq -0x88(%rbp), %rdx
leaq 0x2(%rax,%rdx), %rcx
movq %rsp, %rsi
movq %rsi, -0x40(%rbp)
leaq 0x11(%rax,%rdx), %rdx
andq $-0x10, %rdx
movq %rsp, %rax
subq %rdx, %rax
movq %rax, -0x80(%rbp)
movq %rax, %rsp
movq %rcx, -0x48(%rbp)
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1060
leaq -0x30(%rbp), %rdi
callq 0x1090
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1060
movq -0x10(%rbp), %rdi
callq 0x1090
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movb $0x20, (%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x1060
movq -0x80(%rbp), %rdi
movq %rdi, -0x60(%rbp)
callq 0x1090
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0x14e0
cmpl $0x1, %eax
je 0x2c29
movq 0x43fd(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edx
movq -0x10(%rbp), %rcx
leaq 0x183a(%rip), %rsi      # 0x444a
movb $0x0, %al
callq 0x1140
movq -0x8(%rbp), %rdi
callq 0x1620
movl $0x5, -0x64(%rbp)
jmp 0x2c30
movl $0x0, -0x64(%rbp)
movq -0x40(%rbp), %rax
movq %rax, %rsp
movl -0x64(%rbp), %eax
testl %eax, %eax
je 0x2c45
jmp 0x2c40
jmp 0x2d3a
jmp 0x2d36
callq 0x19f0
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x2c84
movq 0x4397(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x180b(%rip), %rsi      # 0x447a
movb $0x0, %al
callq 0x1140
movq -0x8(%rbp), %rdi
callq 0x1620
jmp 0x2d3a
movq -0x10(%rbp), %rdi
callq 0x1220
movq %rax, %rcx
movq -0x70(%rbp), %rax
movq %rcx, (%rax)
movq -0x70(%rbp), %rax
movl $0x1, 0x8(%rax)
movq -0x70(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x1420
movq -0x10(%rbp), %rdi
callq 0x2910
testb $0x1, %al
jne 0x2ce3
movq 0x4335(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x17dc(%rip), %rsi      # 0x44ad
movb $0x0, %al
callq 0x1140
movq -0x70(%rbp), %rax
movl $0x3, 0x8(%rax)
movq -0x70(%rbp), %rdi
callq 0x1760
testb $0x1, %al
jne 0x2d1e
movq 0x4301(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
movq -0x8(%rbp), %rax
movl 0x14(%rax), %ecx
leaq 0x17d6(%rip), %rsi      # 0x44e2
movb $0x0, %al
callq 0x1140
movq -0x8(%rbp), %rdi
callq 0x1620
jmp 0x2d3a
movq -0x70(%rbp), %rax
cmpl $0x3, 0x8(%rax)
jne 0x2d34
movq -0x70(%rbp), %rax
movq (%rax), %rdi
callq 0x1a80
jmp 0x2d36
jmp 0x2d38
jmp 0x2d3a
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %eax
movl %eax, %edx
addl $-0x1, %edx
movl %edx, 0x10(%rcx)
cmpl $0x0, %eax
jne 0x2d57
movq -0x8(%rbp), %rdi
callq 0x1030
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)