// File: /workspace/github_c_makefile_star2_O3/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 $0x78, %rsp
movq %rdi, %rbx
movl $0x1, 0x4(%rsp)
movl $0x1, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x55a0
movl %eax, %ebp
testl %eax, %eax
js 0xecb8
xorps %xmm0, %xmm0
leaq 0xd(%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 0xa(%rsp), %rsi
movl %ebp, %edi
movl %r15d, %edx
callq 0x54f0
testl %eax, %eax
js 0xec2e
leaq 0x4(%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 0x1b3f0(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xea3b
leaq 0x12133(%rip), %rsi     # 0x20d12
leaq 0x1c0ca(%rip), %rdx     # 0x2acb0
movq %r14, %rdi
movq %rbx, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x52c0
movq 0x1c0ab(%rip), %r14     # 0x2aca8
testq %r14, %r14
je 0xecb8
callq 0xea3b
leaq 0x12100(%rip), %rsi     # 0x20d12
leaq 0x1c097(%rip), %rdx     # 0x2acb0
movq %r14, %rdi
movq %rbx, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x52c0
jmp 0xecb8
movl %ebp, %edi
callq 0x5230
movq 0x1b384(%rip), %rax     # 0x29fc0
movq (%rax), %r15
callq 0xea3b
callq 0x5070
movq %rax, %r14
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5530
leaq 0x12096(%rip), %rsi     # 0x20cf2
leaq 0x1c04d(%rip), %rdx     # 0x2acb0
movq %r15, %rdi
movq %rbx, %rcx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
movq 0x1c02b(%rip), %r15     # 0x2aca8
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r15, %r15
je 0xecb8
callq 0xea3b
movl (%r14), %r14d
movl %r14d, %edi
callq 0x5530
leaq 0x12054(%rip), %rsi     # 0x20cf2
leaq 0x1c00b(%rip), %rdx     # 0x2acb0
movq %r15, %rdi
movq %rbx, %rcx
movl %r14d, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq