// File: /workspace/github_cpp_makefile_star2_O1/xocoder[P]m_kcptun/src/kcp_local.cpp
// Function: local_udpout_callback(chann_msg_t*)
void
_local_udpout_callback(chann_msg_t *e) {
   tun_local_t *tun = (tun_local_t*)e->opaque;   

   switch (e->event) {

      case CHANN_EVENT_RECV: {
         long ret = mnet_chann_recv(e->n, tun->buf, MKCP_BUF_SIZE);

         if (ret > MKCP_OVERHEAD) {
            const int rs_offset = tun->rt ? sizeof(uint16_t) : 0;
            uint8_t *data = tun->buf + rs_offset;
            int data_len = tun->rt ? rskcp_dec_info(tun->rt, ret) : (ret - XOR64_CHECKSUM_SIZE);
            
            if ( tun->rt ) {
               ret = rskcp_decode(tun->rt, tun->buf, ret, &tun->buf[data_len]);
               data_len = *((uint16_t*)tun->buf); // restore data_len
            } else {
               ret = xor64_checksum_check(data, data_len, &tun->buf[data_len]);
            }

            if ( ret ) {
               if ( tun->conf->crypto ) {
                  data_len = rc4_decrypt((const char*)data, data_len,
                                         (char*)tun->buf, MKCP_BUF_SIZE,
                                         tun->ukey, (tun->ti>>20));
                  if (data_len < 0) {
                     return;
                  }
                  data = tun->buf;
               }

               if (data_len >= MKCP_OVERHEAD) {
                  ikcp_input(tun->kcpout, (const char*)data, data_len);
               }
            }
         }

         break;
      }

      case CHANN_EVENT_DISCONNECT:  {
         cout << "local udp disconnect !" << endl;
         break;
      }

      default: {
         break;
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl (%rdi), %eax
cmpl $0x5, %eax
je 0x8d86
cmpl $0x1, %eax
jne 0x8e71
movq 0x18(%rdi), %r13
movq 0x8(%rdi), %rdi
leaq 0x98(%r13), %rbx
movq %rbx, %rsi
movl $0x10000, %edx          # imm = 0x10000
callq 0x4c63
cmpl $0x19, %eax
jl 0x8e71
movl %eax, %r12d
movq 0x90(%r13), %rdi
xorl %r15d, %r15d
testq %rdi, %rdi
setne %r15b
je 0x8dd6
movl %r12d, %esi
callq 0x915e
movl %eax, %r14d
jmp 0x8ddd
movq 0x7243(%rip), %rbx      # 0xffd0
leaq 0x32cd(%rip), %rsi      # 0xc061
movl $0x16, %edx
movq %rbx, %rdi
callq 0x22e0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2270
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21d0
movl %r12d, %r14d
addl $-0x8, %r14d
leaq (%rbx,%r15,2), %r15
movq 0x90(%r13), %rdi
movslq %r14d, %rcx
addq %rbx, %rcx
testq %rdi, %rdi
je 0x8e04
movq %rbx, %rsi
movl %r12d, %edx
callq 0x9239
movzwl (%rbx), %r14d
jmp 0x8e12
movq %r15, %rdi
movl %r14d, %esi
movq %rcx, %rdx
callq 0x5c95
testl %eax, %eax
je 0x8e71
movq 0x78(%r13), %rax
cmpl $0x0, 0x148(%rax)
je 0x8e4b
movq 0x60(%r13), %r8
movq 0x68(%r13), %r9
shrq $0x14, %r9
movq %r15, %rdi
movl %r14d, %esi
movq %rbx, %rdx
movl $0x10000, %ecx          # imm = 0x10000
callq 0x5a32
movl %eax, %r14d
testl %eax, %eax
jns 0x8e4e
jmp 0x8e71
movq %r15, %rbx
cmpl $0x18, %r14d
jl 0x8e71
movq 0x48(%r13), %rdi
movl %r14d, %edx
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x308e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq