// File: /workspace/github_cpp_makefile_star2_O3/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 %r12
pushq %rbx
movl (%rdi), %eax
cmpl $0x5, %eax
je 0x8be4
cmpl $0x1, %eax
jne 0x8ca3
movq 0x18(%rdi), %r12
movq 0x8(%rdi), %rdi
leaq 0x98(%r12), %rbx
movq %rbx, %rsi
movl $0x10000, %edx          # imm = 0x10000
callq 0x4c04
cmpl $0x19, %eax
jl 0x8ca3
movl %eax, %r14d
movq 0x90(%r12), %rdi
xorl %eax, %eax
testq %rdi, %rdi
setne %al
leaq (%rbx,%rax,2), %r15
je 0x8c2e
movl %r14d, %esi
callq 0x8f82
movq 0x90(%r12), %rdi
testq %rdi, %rdi
je 0x8c34
movslq %eax, %rcx
addq %rbx, %rcx
movq %rbx, %rsi
movl %r14d, %edx
callq 0x905b
movzwl (%rbx), %r14d
jmp 0x8c46
movq 0x73e5(%rip), %rbx      # 0xffd0
leaq 0x346f(%rip), %rsi      # 0xc061
movl $0x16, %edx
movq %rbx, %rdi
callq 0x22f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x21e0
addl $-0x8, %r14d
jmp 0x8c37
movl %eax, %r14d
movslq %r14d, %rsi
leaq (%rbx,%rsi), %rdx
movq %r15, %rdi
callq 0x5c0d
testl %eax, %eax
je 0x8ca3
movq 0x78(%r12), %rax
cmpl $0x0, 0x148(%rax)
je 0x8c82
movq 0x60(%r12), %r8
movq 0x68(%r12), %r9
shrq $0x14, %r9
movq %r15, %rdi
movl %r14d, %esi
movq %rbx, %rdx
movl $0x10000, %ecx          # imm = 0x10000
callq 0x59aa
movl %eax, %r14d
testl %eax, %eax
jns 0x8c85
jmp 0x8ca3
movq %r15, %rbx
cmpl $0x18, %r14d
jl 0x8ca3
movq 0x48(%r12), %rdi
movl %r14d, %edx
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x30d4
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq