// File: /workspace/github_c_makefile_star2_O0/panux[P]linit/src/linitd.c
// Function: cmd_stop
void cmd_stop(struct conn *c, char *arg) {
    ref(c);
    if(hasSpace(arg)) {
        //bad command syntax
        fprintf(stderr, "[ERROR] Bad stop command syntax recieved on conn %d: \"%s\"\n", c->fd, arg);
        close_conn(c);
        goto end;
    }
    struct service *svc = findService(arg);
    if(svc == NULL) {   //already stopped
        //format: "notify %s null"
        char not[] = "notify ";
        char nul[] = " null";
        char ntxt[strlen(not) + strlen(arg) + strlen(nul) + 1];
        memcpy(ntxt, not, strlen(not));
        memcpy(ntxt + strlen(not), arg, strlen(arg));
        memcpy(ntxt + strlen(not) + strlen(arg), nul, strlen(nul) + 1);
        //send it
        struct buf otx = c->tx;
        struct buf ntx = {
            .dat = realloc(otx.dat, otx.len + strlen(ntxt) + 1),
            .len = otx.len + strlen(ntxt) + 1,
        };
        memcpy(ntx.dat + otx.len, ntxt, strlen(ntxt) + 1);
        if(ntx.dat == NULL) {
            fprintf(stderr, "[ERROR] failed to notify %d that %s is already stopped\n", c->fd, arg);
            close_conn(c);
            goto end;
        }
        c->tx = ntx;
        if(c->txoff && (c->tx.len > 0)) {  //tx buffer was just populated
            //enable write in epoll
            struct epoll_event ev = {.events = EPOLLIN | EPOLLOUT, .data = {.ptr = &c->e}};
            if(epoll_ctl(epollfd, EPOLL_CTL_MOD, c->fd, &ev) == -1) {   //failed to enable - close and forget
                fprintf(stderr, "[ERROR] Failed to enable writing on conn %d\n", c->fd);
                close_conn(c);
            } else {
                c->txoff = false;
            }
        }
        goto end;
    }
    setNotify(svc, c);
    //stop service
    if(!runStop(arg)) {
        fprintf(stderr, "[ERROR] Failed to stop service %s: fork/exec error\n", arg);
        close_conn(c);
        goto end;
    }
    svc->state = service_status_stopping;
    if(!notifyAll(svc)) {
        fprintf(stderr, "[FATAL] Failed to notify clients of service %s stopping\n", arg);
        exit(65);
    }
end:
    deref(c);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %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 0x2d8f
jmp 0x2dc0
movq 0x4262(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edx
movq -0x10(%rbp), %rcx
leaq 0x1770(%rip), %rsi      # 0x451b
movb $0x0, %al
callq 0x1140
movq -0x8(%rbp), %rdi
callq 0x1620
jmp 0x3125
movq -0x10(%rbp), %rdi
callq 0x1990
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x30a4
movabsq $0x20796669746f6e, %rax # imm = 0x20796669746F6E
movq %rax, -0x20(%rbp)
movw $0x6c, -0x24(%rbp)
movl $0x6c756e20, -0x28(%rbp) # imm = 0x6C756E20
leaq -0x20(%rbp), %rdi
callq 0x1090
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1090
movq %rax, %rcx
movq -0xd0(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xc8(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x1090
movq -0xc8(%rbp), %rdx
movq %rax, %rcx
leaq 0x1(%rcx,%rdx), %rax
movq %rsp, %rsi
movq %rsi, -0x30(%rbp)
leaq 0x10(%rcx,%rdx), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x70(%rbp)
movq %rcx, %rsp
movq %rax, -0x38(%rbp)
leaq -0x20(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x1090
movq -0xc0(%rbp), %rsi
movq -0x70(%rbp), %rdi
movq %rax, %rdx
callq 0x1150
leaq -0x20(%rbp), %rdi
callq 0x1090
movq %rax, %rcx
movq -0x70(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1090
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
movq %rax, %rdx
callq 0x1150
leaq -0x20(%rbp), %rdi
callq 0x1090
movq %rax, %rcx
movq -0x70(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1090
movq %rax, %rcx
movq -0xa8(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
leaq -0x28(%rbp), %rax
movq %rax, -0x98(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x1090
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x1150
movq -0x70(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rcx
movq %rcx, -0x48(%rbp)
movq 0x38(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x90(%rbp)
callq 0x1090
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdi
addq %rax, %rsi
addq $0x1, %rsi
callq 0x1180
movq -0x70(%rbp), %rdi
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x80(%rbp)
callq 0x1090
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movq -0x80(%rbp), %rax
addq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x78(%rbp)
callq 0x1090
movq -0x78(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x1150
cmpq $0x0, -0x58(%rbp)
jne 0x3005
movq 0x4024(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edx
movq -0x10(%rbp), %rcx
leaq 0x1573(%rip), %rsi      # 0x455c
movb $0x0, %al
callq 0x1140
movq -0x8(%rbp), %rdi
callq 0x1620
movl $0x2, -0x68(%rbp)
jmp 0x3098
movq -0x8(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, 0x30(%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rax
testb $0x1, 0x19(%rax)
je 0x3091
movq -0x8(%rbp), %rax
cmpq $0x0, 0x38(%rax)
jbe 0x3091
movl $0x5, -0x64(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movl 0x410d(%rip), %edi      # 0x7150
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edx
movl $0x3, %esi
leaq -0x64(%rbp), %rcx
callq 0x1100
cmpl $-0x1, %eax
jne 0x3087
movq 0x3f94(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edx
leaq 0xfcd(%rip), %rsi       # 0x4042
movb $0x0, %al
callq 0x1140
movq -0x8(%rbp), %rdi
callq 0x1620
jmp 0x308f
movq -0x8(%rbp), %rax
movb $0x0, 0x19(%rax)
jmp 0x3091
movl $0x2, -0x68(%rbp)
movq -0x30(%rbp), %rax
movq %rax, %rsp
jmp 0x3125
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x1420
movq -0x10(%rbp), %rdi
callq 0x2950
testb $0x1, %al
jne 0x30e5
movq 0x3f33(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x14c1(%rip), %rsi      # 0x4594
movb $0x0, %al
callq 0x1140
movq -0x8(%rbp), %rdi
callq 0x1620
jmp 0x3125
movq -0x18(%rbp), %rax
movl $0x4, 0x8(%rax)
movq -0x18(%rbp), %rdi
callq 0x1760
testb $0x1, %al
jne 0x3123
movq 0x3ef4(%rip), %rax      # 0x6ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq 0x14b6(%rip), %rsi      # 0x45c8
movb $0x0, %al
callq 0x1140
movl $0x41, %edi
callq 0x1210
jmp 0x3125
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %eax
movl %eax, %edx
addl $-0x1, %edx
movl %edx, 0x10(%rcx)
cmpl $0x0, %eax
jne 0x3142
movq -0x8(%rbp), %rdi
callq 0x1030
movq %rbp, %rsp
popq %rbp
retq
nopw (%rax,%rax)