// File: /workspace/github_c_makefile_star2_O3/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 0x4ec7
testq %rax, %rax
je 0x507b
movq %rax, %r14
leaq -0x50(%rbp), %rsi
xorl %edi, %edi
callq 0x4140
cmpl $-0x1, %eax
je 0x50bb
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 0x50c9
callq 0x4070
cmpl $0x4, (%rax)
je 0x5004
movq %rax, %r15
movl %ebx, %edi
callq 0x43a0
movl (%r15), %edi
callq 0x4640
movq %rax, %r10
leaq 0x5140(%rip), %r11      # 0xa17e
leaq 0x504b(%rip), %rsi      # 0xa090
leaq 0x504a(%rip), %rdx      # 0xa096
leaq 0x5048(%rip), %rcx      # 0xa09b
leaq 0x50fc(%rip), %r8       # 0xa156
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 0x50f6
leaq 0x50e9(%rip), %r10      # 0xa16b
leaq 0x50c7(%rip), %rsi      # 0xa150
leaq 0x5006(%rip), %rdx      # 0xa096
leaq 0x5004(%rip), %rcx      # 0xa09b
leaq 0x50b8(%rip), %r8       # 0xa156
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 0x50f6
movl %ebx, %edi
callq 0x43a0
movl $0x186a0, %eax          # imm = 0x186A0
jmp 0x50f6
movq -0x30(%rbp), %rcx
testq %rcx, %rcx
je 0x50d8
movl 0x14(%r14), %eax
movl %eax, (%rcx)
movq -0x38(%rbp), %r15
testq %r15, %r15
je 0x50ed
movq 0x38(%r14), %rdi
callq 0x4630
movq %rax, (%r15)
movl %ebx, %edi
callq 0x43a0
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq