// File: /workspace/github_c_makefile_star2_O2/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, %rdi
callq 0x20aa
testb %al, %al
je 0x2670
movq %r14, %r15
cmpb $0x20, (%r15)
leaq 0x1(%r15), %r15
jne 0x2587
movb $0x0, -0x1(%r15)
leaq 0xa70(%rip), %rsi       # 0x300d
movq %r15, %rdi
callq 0x1120
testl %eax, %eax
je 0x25db
leaq 0xa6e(%rip), %rsi       # 0x301e
movq %r15, %rdi
callq 0x1120
testl %eax, %eax
je 0x25f4
leaq 0x1076(%rip), %rsi      # 0x3639
movq %r15, %rdi
callq 0x1120
testl %eax, %eax
jne 0x2670
pushq $0x3
popq %r13
xorl %ebp, %ebp
jmp 0x25fb
leaq 0x1043(%rip), %rdi      # 0x3625
xorl %ebp, %ebp
movq %r14, %rsi
xorl %eax, %eax
callq 0x10c0
pushq $0x2
popq %r13
jmp 0x25fb
pushq $0x5
popq %r13
movb $0x1, %bpl
movq %r14, %rdi
callq 0x16c1
testq %rax, %rax
je 0x2690
movq %rax, %r12
movl %r13d, 0x8(%rax)
movq %rax, %rdi
callq 0x158c
testb %al, %al
je 0x26de
testb %bpl, %bpl
je 0x26b3
movq (%r12), %rsi
leaq 0x106a(%rip), %rdi      # 0x36a1
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x10c0
movq 0x10(%r12), %rdi
cmpq 0x18(%r12), %r15
jae 0x2661
movq (%rdi,%r15,8), %rdi
subl $0x1, 0x10(%rdi)
jae 0x265c
callq 0x1030
incq %r15
jmp 0x2641
callq 0x1030
movq %r14, %rdi
callq 0x1734
jmp 0x26b3
movq 0x3981(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movl 0x14(%rbx), %edx
leaq 0xf65(%rip), %rsi       # 0x35e9
movq %r14, %rcx
xorl %eax, %eax
callq 0x1130
jmp 0x26ab
movq 0x3961(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0xf9f(%rip), %rsi       # 0x3640
movq %r14, %rdx
xorl %eax, %eax
callq 0x1130
movq %rbx, %rdi
callq 0x14b8
subl $0x1, 0x10(%rbx)
jae 0x26cf
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 0x3913(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0xf6f(%rip), %rsi       # 0x365e
movq %r14, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x1130
pushq $0x41
popq %rdi
callq 0x11f0