// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
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 0x31ad
jmp 0x317c
movq 0x3e75(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edx
movq -0x10(%rbp), %rcx
leaq 0x1469(%rip), %rsi      # 0x4601
movb $0x0, %al
callq 0x1140
movq -0x8(%rbp), %rdi
callq 0x1620
jmp 0x3375
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
je 0x31d5
jmp 0x31c7
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x31b9
movq -0x20(%rbp), %rax
movb $0x0, (%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x20(%rbp), %rdi
leaq 0xe2b(%rip), %rsi       # 0x4025
callq 0x1130
cmpl $0x0, %eax
jne 0x321f
movl $0x2, -0x24(%rbp)
movq -0x18(%rbp), %rsi
leaq 0x1427(%rip), %rdi      # 0x463d
movb $0x0, %al
callq 0x10c0
jmp 0x3264
movq -0x20(%rbp), %rdi
leaq 0xe0c(%rip), %rsi       # 0x4036
callq 0x1130
cmpl $0x0, %eax
jne 0x323d
movl $0x5, -0x24(%rbp)
jmp 0x3262
movq -0x20(%rbp), %rdi
leaq 0x1409(%rip), %rsi      # 0x4651
callq 0x1130
cmpl $0x0, %eax
jne 0x325b
movl $0x3, -0x24(%rbp)
jmp 0x3260
jmp 0x317c
jmp 0x3262
jmp 0x3264
movq -0x18(%rbp), %rdi
callq 0x1990
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x32a2
movq 0x3d79(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x13cb(%rip), %rsi      # 0x4658
movb $0x0, %al
callq 0x1140
movq -0x8(%rbp), %rdi
callq 0x1620
jmp 0x3375
movl -0x24(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x30(%rbp), %rdi
callq 0x1760
testb $0x1, %al
jne 0x32e3
movq 0x3d38(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq 0x13a4(%rip), %rsi      # 0x4676
movb $0x0, %al
callq 0x1140
movl $0x41, %edi
callq 0x1210
cmpl $0x5, -0x24(%rbp)
jne 0x3373
movq -0x30(%rbp), %rax
movq (%rax), %rsi
leaq 0x13be(%rip), %rdi      # 0x46b9
movb $0x0, %al
callq 0x10c0
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0x335d
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movl 0x10(%rcx), %eax
movl %eax, %edx
addl $-0x1, %edx
movl %edx, 0x10(%rcx)
cmpl $0x0, %eax
jne 0x334d
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x1030
jmp 0x334f
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x330a
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x1030
movq -0x18(%rbp), %rdi
callq 0x1a80
jmp 0x3375
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %eax
movl %eax, %edx
addl $-0x1, %edx
movl %edx, 0x10(%rcx)
cmpl $0x0, %eax
jne 0x3392
movq -0x8(%rbp), %rdi
callq 0x1030
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)