// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x80, %rsp
movq %rdi, %rbx
movl $0x1, 0xc(%rsp)
pushq $0x1
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x55b0
movl %eax, %ebp
testl %eax, %eax
js 0xe5a8
xorps %xmm0, %xmm0
leaq 0x15(%rsp), %r14
movups %xmm0, 0x5b(%r14)
movups %xmm0, 0x4f(%r14)
movups %xmm0, 0x3f(%r14)
movups %xmm0, 0x2f(%r14)
movups %xmm0, 0x1f(%r14)
movups %xmm0, 0xf(%r14)
movups %xmm0, -0x1(%r14)
movw $0x1, -0x3(%r14)
movq %rbx, %rdi
callq 0x5160
movq %rax, %r15
movq %r14, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x52f0
addl $0x3, %r15d
leaq 0x12(%rsp), %rsi
movl %ebp, %edi
movl %r15d, %edx
callq 0x5500
testl %eax, %eax
js 0xe520
pushq $0x1
popq %r14
pushq $0x2
popq %r15
leaq 0xc(%rsp), %rcx
pushq $0x4
popq %r12
movl %ebp, %edi
movl %r14d, %esi
movl %r15d, %edx
movl %r12d, %r8d
callq 0x50c0
pushq $0x3
popq %rsi
movl %ebp, %edi
xorl %eax, %eax
callq 0x50e0
orl $0x800, %eax            # imm = 0x800
movl %ebp, %edi
movl %r12d, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x50e0
movl %ebp, %edi
movl %r15d, %esi
movl %r14d, %edx
xorl %eax, %eax
callq 0x50e0
movq 0x1aaf6(%rip), %rax     # 0x28fb8
movq (%rax), %r14
callq 0xe343
leaq 0x10857(%rip), %rsi     # 0x1ed28
leaq 0x1b7d8(%rip), %rdx     # 0x29cb0
movq %r14, %rdi
movq %rbx, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x52c0
movq 0x1b7b9(%rip), %r14     # 0x29ca8
testq %r14, %r14
je 0xe5a8
callq 0xe343
leaq 0x10824(%rip), %rsi     # 0x1ed28
leaq 0x1b7a5(%rip), %rdx     # 0x29cb0
movq %r14, %rdi
movq %rbx, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x52c0
jmp 0xe5a8
movl %ebp, %edi
callq 0x5230
movq 0x1aa8a(%rip), %rax     # 0x28fb8
movq (%rax), %r15
callq 0xe343
callq 0x5070
movq %rax, %r14
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5540
leaq 0x107ba(%rip), %rsi     # 0x1ed08
leaq 0x1b75b(%rip), %rdx     # 0x29cb0
movq %r15, %rdi
movq %rbx, %rcx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
movq 0x1b739(%rip), %r15     # 0x29ca8
pushq $-0x1
popq %rbp
testq %r15, %r15
je 0xe5a8
callq 0xe343
movl (%r14), %r14d
movl %r14d, %edi
callq 0x5540
leaq 0x1077a(%rip), %rsi     # 0x1ed08
leaq 0x1b71b(%rip), %rdx     # 0x29cb0
movq %r15, %rdi
movq %rbx, %rcx
movl %r14d, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
movl %ebp, %eax
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq