// File: /workspace/github_cpp_makefile_star2_O1/davmac314[P]dinit/src/dinitctl.cc
// Function: signal_send(int, cpbuffer<1024u>&, char const*, int)
static int signal_send(int socknum, cpbuffer_t &rbuffer, const char *service_name, sig_num_t sig_num)
{
    using std::cerr;

    handle_t handle;

    if (!load_service(socknum, rbuffer, service_name, &handle, nullptr, true)) {
        return 1;
    }

    // Issue SIGNAL command.
    auto m = membuf()
            .append((char)cp_cmd::SIGNAL)
            .append(sig_num)
            .append(handle);
    write_all_x(socknum, m);

    wait_for_reply(rbuffer, socknum);
    cp_rply reply_pkt_h = (cp_rply)rbuffer[0];
    if (reply_pkt_h == cp_rply::NAK) {
        cerr << "dinitctl: cannot send signal to service.\n";
        return 1;
    }
    if (reply_pkt_h == cp_rply::SIGNAL_NOPID) {
        cerr << "dinitctl: could not get vaild PID of service; service is not process, "
        "service in wrong state.\n";
        return 1;
    }
    if (reply_pkt_h == cp_rply::SIGNAL_BADSIG) {
        cerr << "dinitctl: provided signal was invalid.\n";
        return 1;
    }
    if (reply_pkt_h == cp_rply::SIGNAL_KILLERR) {
        cerr << "dinitctl: failed sending signal to service.\n";
        return 1;
    }
    if (reply_pkt_h != cp_rply::ACK) {
        cerr << "dinitctl: protocol error.\n";
        return 1;
    }
    rbuffer.consume(1);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %r15d
movq %rsi, %rbx
movl %edi, %ebp
xorl %r12d, %r12d
leaq 0x4(%rsp), %rcx
movl $0x1, %r14d
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0xd198
testb %al, %al
je 0xc1af
movl %r15d, %eax
shrl $0x18, %eax
shlq $0x8, %r15
orq $0x15, %r15
leaq 0x8(%rsp), %r14
movb %al, 0x4(%r14)
movl %r15d, (%r14)
movl 0x4(%rsp), %eax
movl %eax, 0x5(%r14)
movq (%r14), %rax
movb 0x8(%r14), %cl
movq %rax, (%r14)
movb %cl, 0x8(%r14)
movl $0x9, %r15d
movl %r15d, %edx
movl %ebp, %edi
movq %r14, %rsi
callq 0x4100
cmpl $-0x1, %eax
je 0xc09d
addl %eax, %r12d
movslq %eax, %rcx
addq %rcx, %r14
subl %eax, %r15d
xorl %ecx, %ecx
jmp 0xc0be
callq 0x4040
movl $0x2, %ecx
cmpl $0x4, (%rax)
je 0xc0be
testl %r12d, %r12d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmovgl %r12d, %r13d
movl $0x1, %ecx
testb $0x1, %cl
jne 0xc0ca
testl %r15d, %r15d
jg 0xc07b
jmp 0xc0cd
movl %r13d, %r12d
cmpl $-0x1, %r12d
je 0xc1c1
movq %rbx, %rdi
movl %ebp, %esi
callq 0xedbd
movl 0x400(%rbx), %eax
leal -0x400(%rax), %ecx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ecx
movzbl (%rbx,%rcx), %ecx
cmpl $0x49, %ecx
jle 0xc126
cmpl $0x4a, %ecx
je 0xc145
cmpl $0x4b, %ecx
je 0xc15a
cmpl $0x4c, %ecx
jne 0xc191
movq 0x10ed0(%rip), %rdi     # 0x1cfe8
leaq 0xb196(%rip), %rsi      # 0x172b5
movl $0x2c, %edx
jmp 0xc1a4
cmpl $0x32, %ecx
je 0xc16f
cmpl $0x33, %ecx
jne 0xc191
movq 0x10eb1(%rip), %rdi     # 0x1cfe8
leaq 0xb0c6(%rip), %rsi      # 0x17204
movl $0x29, %edx
jmp 0xc1a4
movq 0x10e9c(%rip), %rdi     # 0x1cfe8
leaq 0xb0db(%rip), %rsi      # 0x1722e
movl $0x5e, %edx
jmp 0xc1a4
movq 0x10e87(%rip), %rdi     # 0x1cfe8
leaq 0xb125(%rip), %rsi      # 0x1728d
movl $0x27, %edx
jmp 0xc1a4
leal 0x1(%rax), %ecx
addl $0xfffffc01, %eax       # imm = 0xFFFFFC01
cmpl $0x400, %ecx            # imm = 0x400
cmovbl %ecx, %eax
movl %eax, 0x400(%rbx)
decl 0x404(%rbx)
xorl %r14d, %r14d
jmp 0xc1af
movq 0x10e50(%rip), %rdi     # 0x1cfe8
leaq 0x9fd3(%rip), %rsi      # 0x16172
movl $0x1a, %edx
callq 0x4330
movl $0x1, %r14d
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x4, %edi
callq 0x4190
movq %rax, %rbx
callq 0x4040
movl (%rax), %eax
movl %eax, (%rbx)
leaq 0x10972(%rip), %rsi     # 0x1cb50
movq %rbx, %rdi
xorl %edx, %edx
callq 0x44d0