// File: /workspace/github_c_makefile_star2_O1/Carton32[P]quectel-CM/util.c
// Function: cm_open_proxy
int cm_open_proxy(const char *name) {
    int sockfd = -1;
    int reuse_addr = 1;
    struct sockaddr_un sockaddr;
    socklen_t alen;

    /*Create server socket*/
    sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
    if (sockfd < 0)
        return sockfd;

    memset(&sockaddr, 0, sizeof(sockaddr));
    sockaddr.sun_family = AF_LOCAL;
    sockaddr.sun_path[0] = 0;
    memcpy(sockaddr.sun_path + 1, name, strlen(name) );

    alen = strlen(name) + offsetof(struct sockaddr_un, sun_path) + 1;
    if(connect(sockfd, (struct sockaddr *)&sockaddr, alen) < 0) {
        close(sockfd);
        dbg_time("connect %s errno: %d (%s)", name, errno, strerror(errno));
        return -1;
    }
    setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &reuse_addr,sizeof(reuse_addr));
    fcntl(sockfd, F_SETFL, fcntl(sockfd,F_GETFL) | O_NONBLOCK);
    fcntl(sockfd, F_SETFD, FD_CLOEXEC);

    dbg_time("connect to %s sockfd = %d", name, sockfd);

    return sockfd;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
movl $0x1, 0xc(%rsp)
movl $0x1, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x55a0
movl %eax, %ebp
testl %eax, %eax
js 0xedb5
xorps %xmm0, %xmm0
leaq 0x13(%rsp), %r14
movaps %xmm0, -0x3(%r14)
movups %xmm0, 0x5b(%r14)
movaps %xmm0, 0x4d(%r14)
movaps %xmm0, 0x3d(%r14)
movaps %xmm0, 0x2d(%r14)
movaps %xmm0, 0x1d(%r14)
movaps %xmm0, 0xd(%r14)
movw $0x1, -0x3(%r14)
movb $0x0, -0x1(%r14)
movq %rbx, %rdi
callq 0x5160
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x52f0
movq %rbx, %rdi
callq 0x5160
leal 0x3(%rax), %edx
leaq 0x10(%rsp), %rsi
movl %ebp, %edi
callq 0x54f0
testl %eax, %eax
js 0xed2b
leaq 0xc(%rsp), %rcx
movl %ebp, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x50c0
movl %ebp, %edi
movl $0x3, %esi
xorl %eax, %eax
callq 0x50e0
orl $0x800, %eax            # imm = 0x800
movl %ebp, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x50e0
movl %ebp, %edi
movl $0x2, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x50e0
movq 0x1b2f3(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xeb2f
leaq 0x1203a(%rip), %rsi     # 0x20d16
leaq 0x1bfcd(%rip), %rdx     # 0x2acb0
movq %r14, %rdi
movq %rbx, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x52c0
movq 0x1bfae(%rip), %r14     # 0x2aca8
testq %r14, %r14
je 0xedb5
callq 0xeb2f
leaq 0x12007(%rip), %rsi     # 0x20d16
leaq 0x1bf9a(%rip), %rdx     # 0x2acb0
movq %r14, %rdi
movq %rbx, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x52c0
jmp 0xedb5
movl %ebp, %edi
callq 0x5230
movq 0x1b287(%rip), %rax     # 0x29fc0
movq (%rax), %r15
callq 0xeb2f
callq 0x5070
movq %rax, %r14
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5530
leaq 0x11f9d(%rip), %rsi     # 0x20cf6
leaq 0x1bf50(%rip), %rdx     # 0x2acb0
movq %r15, %rdi
movq %rbx, %rcx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
movq 0x1bf2e(%rip), %r15     # 0x2aca8
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r15, %r15
je 0xedb5
callq 0xeb2f
movl (%r14), %r14d
movl %r14d, %edi
callq 0x5530
leaq 0x11f5b(%rip), %rsi     # 0x20cf6
leaq 0x1bf0e(%rip), %rdx     # 0x2acb0
movq %r15, %rdi
movq %rbx, %rcx
movl %r14d, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq