// File: /workspace/github_c_makefile_star2_O3/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 0x2b05
testl %ecx, %ecx
je 0x2c2c
incq %rax
jmp 0x2af0
movq %r14, %r15
cmpb $0x20, (%r15)
leaq 0x1(%r15), %r15
jne 0x2b08
movb $0x0, -0x1(%r15)
leaq 0x14ef(%rip), %rsi      # 0x400d
movq %r15, %rdi
callq 0x1120
testl %eax, %eax
je 0x2b5e
leaq 0x14ed(%rip), %rsi      # 0x401e
movq %r15, %rdi
callq 0x1120
testl %eax, %eax
je 0x2b79
leaq 0x1af5(%rip), %rsi      # 0x4639
movq %r15, %rdi
callq 0x1120
testl %eax, %eax
jne 0x2c2c
movl $0x3, %r13d
xorl %ebp, %ebp
jmp 0x2b82
leaq 0x1ac0(%rip), %rdi      # 0x4625
xorl %ebp, %ebp
movq %r14, %rsi
xorl %eax, %eax
callq 0x10c0
movl $0x2, %r13d
jmp 0x2b82
movl $0x5, %r13d
movb $0x1, %bpl
movq %r14, %rdi
callq 0x1e3e
testq %rax, %rax
je 0x2c39
movq %rax, %r12
movl %r13d, 0x8(%rax)
movq %rax, %rdi
callq 0x1cf0
testb %al, %al
je 0x2c5e
testb %bpl, %bpl
je 0x2c01
movq (%r12), %rsi
leaq 0x1ae7(%rip), %rdi      # 0x46a1
xorl %eax, %eax
callq 0x10c0
movq 0x18(%r12), %rax
testq %rax, %rax
je 0x2bef
xorl %r15d, %r15d
movq 0x10(%r12), %rcx
movq (%rcx,%r15,8), %rdi
subl $0x1, 0x10(%rdi)
jae 0x2be7
callq 0x1030
movq 0x18(%r12), %rax
incq %r15
cmpq %rax, %r15
jb 0x2bce
movq 0x10(%r12), %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1eb5
subl $0x1, 0x10(%rbx)
jae 0x2c1d
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 0x17c2
jmp 0x2c01
movq 0x43b8(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
leaq 0x19f6(%rip), %rsi      # 0x4640
movq %r14, %rdx
xorl %eax, %eax
callq 0x1130
movq %rbx, %rdi
callq 0x1c5b
jmp 0x2c01
movq %r14, %rdi
movq %r15, %rsi
callq 0x179b