// File: /workspace/github_c_makefile_star2_O1/back1127[P]linkedge-thing-access-websocket_client_sdk/sdk/leda.c
// Function: wsa_get_reply_result
int wsa_get_reply_result(int msg_id, int timeout_ms, int *code, char **payload)
{
    int time_count = 0, s;
    wsa_reply_t *reply;
    struct timespec ts = {0};

    reply = _wsa_get_reply_by_msg_id(msg_id);
    if (NULL == reply) {
        log_d(LOG_TAG, "get reply err:%d\r\n", msg_id);
        return LE_ERROR_INVAILD_PARAM;
    }
    if (-1 == clock_gettime(CLOCK_REALTIME, &ts)) {
        wsa_remove_reply(msg_id);
        return LE_ERROR_UNKNOWN;
    }
    ts.tv_nsec = ts.tv_nsec + (timeout_ms % 1000) * 1000000000;
    ts.tv_sec = ts.tv_sec + timeout_ms / 1000;
    while ((s = sem_timedwait(&reply->sem, &ts)) == -1 && errno == EINTR) {
        continue;
    }

    if (-1 == s) {
        wsa_remove_reply(msg_id);
        log_e(LOG_TAG, "get reply time_out:%s", strerror(errno));
        return LE_ERROR_TIMEOUT;
    }
    
    if (code) {
        *code = reply->code;
    }
    if (payload) {
        *payload = strdup(reply->payload);
    }
    wsa_remove_reply(msg_id);

    return LE_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r15
movq %rdx, %r12
movl %esi, %r13d
movl %edi, %ebx
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
callq 0x4ea9
testq %rax, %rax
je 0x505d
movq %rax, %r14
leaq -0x50(%rbp), %rsi
xorl %edi, %edi
callq 0x4140
cmpl $-0x1, %eax
je 0x509d
movq %r12, -0x30(%rbp)
movq %r15, -0x38(%rbp)
movslq %r13d, %rax
imulq $0x10624dd3, %rax, %rcx # imm = 0x10624DD3
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x26, %rcx
addl %edx, %ecx
imull $0x3e8, %ecx, %edx      # imm = 0x3E8
subl %edx, %eax
imull $0x3b9aca00, %eax, %eax # imm = 0x3B9ACA00
cltq
leaq -0x50(%rbp), %r13
addq %rax, 0x8(%r13)
movslq %ecx, %rax
addq %rax, (%r13)
movq %r14, %r12
addq $0x18, %r12
movq %r12, %rdi
movq %r13, %rsi
callq 0x41d0
cmpl $-0x1, %eax
jne 0x50ab
callq 0x4070
cmpl $0x4, (%rax)
je 0x4fe6
movq %rax, %r15
movl %ebx, %edi
callq 0x4380
movl (%r15), %edi
callq 0x4620
movq %rax, %r10
leaq 0x615e(%rip), %r11      # 0xb17e
leaq 0x6069(%rip), %rsi      # 0xb090
leaq 0x6068(%rip), %rdx      # 0xb096
leaq 0x6066(%rip), %rcx      # 0xb09b
leaq 0x611a(%rip), %r8       # 0xb156
movl $0x3, %edi
movl $0x168, %r9d            # imm = 0x168
xorl %eax, %eax
pushq %r10
pushq %r11
callq 0x4260
addq $0x10, %rsp
movl $0x186a6, %eax          # imm = 0x186A6
jmp 0x50d8
leaq 0x6107(%rip), %r10      # 0xb16b
leaq 0x60e5(%rip), %rsi      # 0xb150
leaq 0x6024(%rip), %rdx      # 0xb096
leaq 0x6022(%rip), %rcx      # 0xb09b
leaq 0x60d6(%rip), %r8       # 0xb156
xorl %edi, %edi
movl $0x159, %r9d            # imm = 0x159
xorl %eax, %eax
pushq %rbx
pushq %r10
callq 0x4260
addq $0x10, %rsp
movl $0x186a1, %eax          # imm = 0x186A1
jmp 0x50d8
movl %ebx, %edi
callq 0x4380
movl $0x186a0, %eax          # imm = 0x186A0
jmp 0x50d8
movq -0x30(%rbp), %rcx
testq %rcx, %rcx
je 0x50ba
movl 0x14(%r14), %eax
movl %eax, (%rcx)
movq -0x38(%rbp), %r15
testq %r15, %r15
je 0x50cf
movq 0x38(%r14), %rdi
callq 0x4610
movq %rax, (%r15)
movl %ebx, %edi
callq 0x4380
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq