// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x18(%rbp)
movl $0x1, %esi
xorl %edx, %edx
movl %esi, %edi
callq 0x55a0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x13a2f
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x13c9d
leaq -0x86(%rbp), %rdi
xorl %esi, %esi
movl $0x6e, %edx
callq 0x5200
movw $0x1, -0x86(%rbp)
movb $0x0, -0x84(%rbp)
leaq -0x86(%rbp), %rax
addq $0x2, %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5160
movq -0xa0(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq %rax, %rdx
callq 0x52f0
movq -0x10(%rbp), %rdi
callq 0x5160
addq $0x2, %rax
addq $0x1, %rax
movl %eax, -0x8c(%rbp)
movl -0x14(%rbp), %edi
movl -0x8c(%rbp), %edx
leaq -0x86(%rbp), %rsi
callq 0x5500
cmpl $0x0, %eax
jge 0x13bc0
movl -0x14(%rbp), %edi
callq 0x5230
movq 0x2350a(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
callq 0x13930
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0xa4(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0xc0(%rbp), %rdi
movq -0xb8(%rbp), %rdx
movq -0xb0(%rbp), %rcx
movl -0xa4(%rbp), %r8d
movq %rax, %r9
leaq 0x1a3b2(%rip), %rsi     # 0x2dee8
movb $0x0, %al
callq 0x52c0
cmpq $0x0, 0x24323(%rip)     # 0x37e68
je 0x13bb2
movq 0x2431a(%rip), %rax     # 0x37e68
movq %rax, -0xe0(%rbp)
callq 0x13930
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0xc4(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0xe0(%rbp), %rdi
movq -0xd8(%rbp), %rdx
movq -0xd0(%rbp), %rcx
movl -0xc4(%rbp), %r8d
movq %rax, %r9
leaq 0x1a33d(%rip), %rsi     # 0x2dee8
movb $0x0, %al
callq 0x52c0
jmp 0x13bb4
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x13c9d
movl -0x14(%rbp), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq -0x18(%rbp), %rcx
movl $0x4, %r8d
callq 0x50c0
movl -0x14(%rbp), %eax
movl %eax, -0xe4(%rbp)
movl -0x14(%rbp), %edi
movl $0x3, %esi
movb $0x0, %al
callq 0x50e0
movl -0xe4(%rbp), %edi
movl %eax, %edx
orl $0x800, %edx            # imm = 0x800
movl $0x4, %esi
movb $0x0, %al
callq 0x50e0
movl -0x14(%rbp), %edi
movl $0x2, %esi
movl $0x1, %edx
movb $0x0, %al
callq 0x50e0
movq 0x233b7(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0xf0(%rbp)
callq 0x13930
movq -0xf0(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rcx
movl -0x14(%rbp), %r8d
leaq 0x1a2b7(%rip), %rsi     # 0x2df08
movb $0x0, %al
callq 0x52c0
cmpq $0x0, 0x24208(%rip)     # 0x37e68
je 0x13c95
movq 0x241ff(%rip), %rax     # 0x37e68
movq %rax, -0xf8(%rbp)
callq 0x13930
movq -0xf8(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rcx
movl -0x14(%rbp), %r8d
leaq 0x1a27a(%rip), %rsi     # 0x2df08
movb $0x0, %al
callq 0x52c0
jmp 0x13c97
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopl (%rax)