// File: /workspace/github_cpp_makefile_star2_O1/davmac314[P]dinit/src/includes/dinit-client.h
// Function: connect_to_daemon(char const*)
inline int connect_to_daemon(const char *control_socket_path)
{
    int socknum = socket(AF_UNIX, SOCK_STREAM, 0);
    if (socknum == -1) {
        throw general_error(errno, "opening socket");
    }

    struct sockaddr_un * name;
    uint sockaddr_size = offsetof(struct sockaddr_un, sun_path) + strlen(control_socket_path) + 1;
    name = (struct sockaddr_un *) malloc(sockaddr_size);
    if (name == nullptr) {
        throw general_error(ENOMEM);
    }

    name->sun_family = AF_UNIX;
    strcpy(name->sun_path, control_socket_path);

    int connr = connect(socknum, (struct sockaddr *) name, sockaddr_size);
    free(name);

    if (connr == -1) {
        throw control_sock_conn_err(errno, control_socket_path);
    }

    return socknum;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rdi, %r14
movl $0x1, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x2060
cmpl $-0x1, %eax
je 0x46d9
movl %eax, %ebx
movq %r14, %rdi
callq 0x20e0
movq %rax, %r15
addl $0x3, %r15d
movq %r15, %rdi
callq 0x22c0
testq %rax, %rax
je 0x4763
movq %rax, %r12
movw $0x1, (%rax)
movq %rax, %rdi
addq $0x2, %rdi
movq %r14, %rsi
callq 0x21d0
movl %ebx, %edi
movq %r12, %rsi
movl %r15d, %edx
callq 0x2190
movl %eax, %ebp
movq %r12, %rdi
callq 0x2260
cmpl $-0x1, %ebp
je 0x479f
movl %ebx, %eax
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl $0x30, %edi
callq 0x2100
movq %rax, %rbx
callq 0x2040
movl (%rax), %eax
leaq 0x40(%rsp), %r15
movq %r15, -0x10(%r15)
xorl %ecx, %ecx
movq %rcx, -0x8(%r15)
movb %cl, (%r15)
movl %eax, (%rbx)
leaq 0x2208(%rip), %rax      # 0x6910
movq %rax, 0x8(%rbx)
leaq 0x20(%rbx), %rax
movq %rax, 0x10(%rbx)
movb (%r15), %al
movb %al, 0x20(%rbx)
movq 0x1(%r15), %rax
movq %rax, 0x21(%rbx)
movl 0x9(%r15), %eax
movl %eax, 0x29(%rbx)
movzwl 0xd(%r15), %eax
movw %ax, 0x2d(%rbx)
movb 0xf(%r15), %al
movb %al, 0x2f(%rbx)
movq %rcx, 0x18(%rbx)
movq %r15, -0x10(%r15)
movq %rcx, -0x8(%r15)
movb %cl, (%r15)
leaq 0x5639(%rip), %rsi      # 0x9d88
leaq 0x460(%rip), %rdx       # 0x4bb6
movq %rbx, %rdi
callq 0x2390
jmp 0x47ea
movl $0x30, %edi
callq 0x2100
movl $0xc, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
leaq 0x20(%rax), %rdx
movq %rdx, 0x10(%rax)
movq %rcx, 0x18(%rax)
movb $0x0, 0x20(%rax)
leaq 0x55f8(%rip), %rsi      # 0x9d88
leaq 0x41f(%rip), %rdx       # 0x4bb6
movq %rax, %rdi
callq 0x2390
movl $0x30, %edi
callq 0x2100
movq %rax, %rbx
callq 0x2040
movl (%rax), %ebp
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
movq %r14, %rsi
callq 0x4ae8
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x4b26
leaq 0x55bd(%rip), %rsi      # 0x9d98
leaq 0x3d4(%rip), %rdx       # 0x4bb6
movq %rbx, %rdi
callq 0x2390
movq %rax, %r14
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4808
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2200
xorl %eax, %eax
jmp 0x4811
movq %rax, %r14
movb $0x1, %al
testb %al, %al
je 0x4839
movq %rbx, %rdi
callq 0x2150
jmp 0x4839
movq %rax, %r14
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x4839
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r14, %rdi
callq 0x23b0