// File: /workspace/github_c_makefile_star2_O1/panux[P]linit/src/linitd.c
// Function: cmd_state
void cmd_state(struct conn *c, char *args) {
    ref(c);
    if(!hasSpace(args)) {
    bad:
        //bad command syntax
        fprintf(stderr, "[ERROR] Bad state command syntax recieved on conn %d: \"%s\"\n", c->fd, args);
        close_conn(c);
        goto end;
    }
    //split up args
    char *sname, *states;
    for(sname = states = args; *states != ' '; states++) {}
    *states = '\0';
    states++;
    //identify state
    servicestate s = service_status_null;
    if(streq(states, "running")) {
        s = service_status_running;
        printf("[INFO] Finished %s\n", sname);
    } else if(streq(states, "stopped")) {
        s = service_status_stopped;
    } else if(streq(states, "failed")) {
        s = service_status_fail;
    } else {
        goto bad;
    }
    //get service and set state
    struct service *svc = findService(sname);
    if(svc == NULL) {
        fprintf(stderr, "[ERROR] Service %s not found\n", sname);
        close_conn(c);
        goto end;
    }
    svc->state = s;
    //notify of change
    if(!notifyAll(svc)) {
        fprintf(stderr, "[FATAL] Failed to notify conns of service %s state change (to %s)\n", sname, states);
        exit(65);
    }
    if(s == service_status_stopped) {   //service has stopped - clean it up
        printf("[INFO] Service %s stopped\n", svc->name);
        for(size_t i = 0; i < svc->notify_n; i++) {
            deref(svc->notify[i]);
        }
        free(svc->notify);
        rmService(sname);
    }
end:
    deref(c);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
incl 0x10(%rdi)
movq %rsi, %rax
movzbl (%rax), %ecx
cmpl $0x20, %ecx
je 0x2b59
testl %ecx, %ecx
je 0x2c7b
incq %rax
jmp 0x2b44
movq %r14, %r15
cmpb $0x20, (%r15)
leaq 0x1(%r15), %r15
jne 0x2b5c
movb $0x0, -0x1(%r15)
leaq 0x14b7(%rip), %rsi      # 0x4029
movq %r15, %rdi
callq 0x1120
testl %eax, %eax
je 0x2bb2
leaq 0x14b5(%rip), %rsi      # 0x403a
movq %r15, %rdi
callq 0x1120
testl %eax, %eax
je 0x2bcd
leaq 0x1abd(%rip), %rsi      # 0x4655
movq %r15, %rdi
callq 0x1120
testl %eax, %eax
jne 0x2c7b
movl $0x3, %r13d
xorl %ebp, %ebp
jmp 0x2bd6
leaq 0x1a88(%rip), %rdi      # 0x4641
xorl %ebp, %ebp
movq %r14, %rsi
xorl %eax, %eax
callq 0x10c0
movl $0x2, %r13d
jmp 0x2bd6
movl $0x5, %r13d
movb $0x1, %bpl
movq %r14, %rdi
callq 0x1e8c
testq %rax, %rax
je 0x2c88
movq %rax, %r12
movl %r13d, 0x8(%rax)
movq %rax, %rdi
callq 0x1d28
testb %al, %al
je 0x2cad
testb %bpl, %bpl
je 0x2c50
movq (%r12), %rsi
leaq 0x1aaf(%rip), %rdi      # 0x46bd
xorl %eax, %eax
callq 0x10c0
cmpq $0x0, 0x18(%r12)
je 0x2c3e
xorl %r15d, %r15d
movq 0x10(%r12), %rax
movq (%rax,%r15,8), %rdi
subl $0x1, 0x10(%rdi)
jae 0x2c34
callq 0x1030
incq %r15
cmpq 0x18(%r12), %r15
jb 0x2c20
movq 0x10(%r12), %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1f12
subl $0x1, 0x10(%rbx)
jae 0x2c6c
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1030
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %r14, %rsi
callq 0x17d2
jmp 0x2c50
movq 0x4369(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x19c3(%rip), %rsi      # 0x465c
movq %r14, %rdx
xorl %eax, %eax
callq 0x1130
movq %rbx, %rdi
callq 0x1c93
jmp 0x2c50
movq %r14, %rdi
movq %r15, %rsi
callq 0x17ab