// File: /workspace/github_c_makefile_star2_O0/xiaowenhuyuehu[P]remote_access/src/core/remote_terminal.c
// Function: sda_connect_to_cloud
static int sda_connect_to_cloud (void)
{
    int ret = 0;
    char *msg_hdsk = NULL;
    char *msg_hdr = NULL;
    char buf[DEFAULT_MSG_HDR_LEN * 2] = {0};

    rd_net_init(&g_network, RD_NET_WEBSOCKET, g_cfg->is_debug_on == 1 ? 1 : 0,
                    g_cfg->cloud_ip, g_cfg->cloud_port, NULL, 
                    g_cfg->is_tls_on , g_cfg->cert_path, NULL);

    ret = rd_net_connect(&g_network);
    if (0 != ret) {
        log_error("connect error ");
        return ret;
    }

    msg_hdsk = sda_gen_handshake_msg(g_cfg->pk, g_cfg->dn, g_cfg->ds);
    msg_hdr =  sda_gen_msg_header(MSG_SERVICE_PROVIDER_CONN_REQ, strlen(msg_hdsk), DEFAULT_MSG_ID_HDSK, NULL);

    log_info("handshake header:%s", msg_hdr);
    log_info("handshak payload:%s", msg_hdsk);

    snprintf(buf,sizeof(buf),"%s%s",msg_hdr,msg_hdsk); 
    ret = rd_net_write(&g_network, NULL, buf, strlen(buf), 0);
    if (ret <= 0) {
        log_error("write data to cloud failed ");
        return -1;
    }

    log_info("send msg handshake, len:%d ", ret);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x840, %rsp            # imm = 0x840
movl $0x0, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
leaq -0x820(%rbp), %rdi
xorl %esi, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x2090
movq 0x74dc(%rip), %rax      # 0xf3c8
movzbl 0x3d(%rax), %ecx
xorl %edx, %edx
movl $0x1, %eax
cmpl $0x1, %ecx
cmovel %eax, %edx
movq 0x74c4(%rip), %rax      # 0xf3c8
movq (%rax), %rcx
movq 0x74ba(%rip), %rax      # 0xf3c8
movq 0x8(%rax), %r8
movq 0x74af(%rip), %rax      # 0xf3c8
movzbl 0x3c(%rax), %r10d
movq 0x74a3(%rip), %rax      # 0xf3c8
movq 0x10(%rax), %rax
leaq 0x7458(%rip), %rdi      # 0xf388
xorl %esi, %esi
xorl %r9d, %r9d
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
callq 0x2c60
leaq 0x7435(%rip), %rdi      # 0xf388
callq 0x28b0
movl %eax, -0x8(%rbp)
xorl %eax, %eax
cmpl -0x8(%rbp), %eax
je 0x7f93
movl $0x3, %edi
leaq 0x3672(%rip), %rsi      # 0xb5e0
leaq 0x3671(%rip), %rdx      # 0xb5e6
movl $0x33, %ecx
leaq 0x3b95(%rip), %r8       # 0xbb16
movb $0x0, %al
callq 0x4f90
movl -0x8(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x80f6
movq 0x742e(%rip), %rax      # 0xf3c8
movq 0x18(%rax), %rdi
movq 0x7423(%rip), %rax      # 0xf3c8
movq 0x20(%rax), %rsi
movq 0x7418(%rip), %rax      # 0xf3c8
movq 0x28(%rax), %rdx
callq 0x9290
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2260
movl %eax, %esi
movl $0x1, %edi
leaq 0x3a7c(%rip), %rdx      # 0xba50
xorl %eax, %eax
movl %eax, %ecx
callq 0x9100
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %r9
movl $0x1, %edi
leaq 0x3648(%rip), %rsi      # 0xb639
leaq 0x35ee(%rip), %rdx      # 0xb5e6
movl $0x3a, %ecx
leaq 0x3b21(%rip), %r8       # 0xbb25
movb $0x0, %al
callq 0x4f90
movq -0x10(%rbp), %r9
movl $0x1, %edi
leaq 0x361e(%rip), %rsi      # 0xb639
leaq 0x35c4(%rip), %rdx      # 0xb5e6
movl $0x3b, %ecx
leaq 0x3b0b(%rip), %r8       # 0xbb39
movb $0x0, %al
callq 0x4f90
leaq -0x820(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %r8
movl $0x800, %esi            # imm = 0x800
leaq 0x389e(%rip), %rdx      # 0xb8ee
movb $0x0, %al
callq 0x20b0
leaq -0x820(%rbp), %rax
movq %rax, -0x828(%rbp)
leaq -0x820(%rbp), %rdi
callq 0x2260
movq -0x828(%rbp), %rdx
movl %eax, %ecx
leaq 0x7307(%rip), %rdi      # 0xf388
xorl %eax, %eax
movl %eax, %esi
xorl %r8d, %r8d
callq 0x27a0
movl %eax, -0x8(%rbp)
cmpl $0x0, -0x8(%rbp)
jg 0x80c5
movl $0x3, %edi
leaq 0x353e(%rip), %rsi      # 0xb5e0
leaq 0x353d(%rip), %rdx      # 0xb5e6
movl $0x40, %ecx
leaq 0x3a98(%rip), %r8       # 0xbb4d
movb $0x0, %al
callq 0x4f90
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x80f6
movl -0x8(%rbp), %r9d
movl $0x1, %edi
leaq 0x3564(%rip), %rsi      # 0xb639
leaq 0x350a(%rip), %rdx      # 0xb5e6
movl $0x44, %ecx
leaq 0x3a81(%rip), %r8       # 0xbb69
movb $0x0, %al
callq 0x4f90
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x840, %rsp            # imm = 0x840
popq %rbp
retq
nopw %cs:(%rax,%rax)