// File: /workspace/github_cpp_makefile_star2_O3/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 %r12
pushq %rbx
subq $0x20, %rsp
movl %ecx, %r15d
movq %rsi, %rbx
movl %edi, %ebp
xorl %r12d, %r12d
leaq 0xc(%rsp), %rcx
movl $0x1, %r14d
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0xd2a8
testb %al, %al
je 0xc2dd
movl %r15d, %eax
shrl $0x18, %eax
shlq $0x8, %r15
orq $0x15, %r15
leaq 0x10(%rsp), %r14
movb %al, 0x4(%r14)
movl %r15d, (%r14)
movl 0xc(%rsp), %eax
movl %eax, 0x5(%r14)
movq (%r14), %rcx
shrl $0x18, %eax
movq %rcx, (%r14)
movb %al, 0x8(%r14)
movl $0x9, %r15d
movl %r15d, %edx
movl %ebp, %edi
movq %r14, %rsi
callq 0x4100
cmpl $-0x1, %eax
je 0xc1a6
addl %eax, %r12d
movslq %eax, %rcx
addq %rcx, %r14
subl %eax, %r15d
jmp 0xc1b4
callq 0x4040
cmpl $0x4, (%rax)
jne 0xc243
testl %r15d, %r15d
jg 0xc186
cmpl $-0x1, %r12d
je 0xc24c
movq %rbx, %rdi
movl %ebp, %esi
callq 0xed47
movl 0x400(%rbx), %eax
leal -0x400(%rax), %ecx
cmpl $0x400, %eax            # imm = 0x400
cmovbl %eax, %ecx
movzbl (%rbx,%rcx), %ecx
cmpl $0x49, %ecx
jle 0xc21d
cmpl $0x4a, %ecx
je 0xc273
cmpl $0x4b, %ecx
je 0xc288
cmpl $0x4c, %ecx
jne 0xc2bf
movq 0x10ddc(%rip), %rdi     # 0x1cfe8
leaq 0xb08d(%rip), %rsi      # 0x172a0
movl $0x2c, %edx
jmp 0xc2d2
cmpl $0x32, %ecx
je 0xc29d
cmpl $0x33, %ecx
jne 0xc2bf
movq 0x10db6(%rip), %rdi     # 0x1cfe8
leaq 0xafb6(%rip), %rsi      # 0x171ef
movl $0x29, %edx
jmp 0xc2d2
testl %r12d, %r12d
jg 0xc1c3
movl $0x4, %edi
callq 0x4190
movq %rax, %rbx
callq 0x4040
movl (%rax), %eax
movl %eax, (%rbx)
leaq 0x108e7(%rip), %rsi     # 0x1cb50
movq %rbx, %rdi
xorl %edx, %edx
callq 0x44d0
movq 0x10d6e(%rip), %rdi     # 0x1cfe8
leaq 0xaf98(%rip), %rsi      # 0x17219
movl $0x5e, %edx
jmp 0xc2d2
movq 0x10d59(%rip), %rdi     # 0x1cfe8
leaq 0xafe2(%rip), %rsi      # 0x17278
movl $0x27, %edx
jmp 0xc2d2
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 0xc2dd
movq 0x10d22(%rip), %rdi     # 0x1cfe8
leaq 0x9e90(%rip), %rsi      # 0x1615d
movl $0x1a, %edx
callq 0x4330
movl $0x1, %r14d
movl %r14d, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq