// File: /workspace/github_cpp_makefile_star2_O3/xocoder[P]m_kcptun/src/kcp_remote.cpp
// Function: remote_kcpin_callback(char const*, int, IKCPCB*, void*)
static int
_remote_kcpin_callback(const char *buf, int len, ikcpcb *kcp, void *user) {
   tun_remote_t *tun = (tun_remote_t*)user;
   chann_t *udpin = tun->udpin[tun->udpin_idx];
   tun->udpin_idx = (tun->udpin_idx + 1) % tun->conf->dest_count;

   if (tun && mnet_chann_state(udpin) >= CHANN_STATE_CONNECTED) {
      const int rs_offset = tun->rt ? sizeof(uint16_t) : 0;
      int data_len = len;
      uint8_t *data = tun->buf + rs_offset;

      if ( tun->conf->crypto ) {
         data_len = rc4_encrypt(buf, len,
                                (char*)data, MKCP_BUF_SIZE - XOR64_CHECKSUM_SIZE,
                                tun->ukey, (tun->ti>>20));
      } else {
         memcpy(data, buf, len);
      }

      int ret = 0;

      if ( tun->rt ) {
         int plen = 0;
         *((uint16_t*)tun->buf) = data_len;
         int raw_len = rskcp_enc_info(tun->rt, (data_len + rs_offset), &plen);
         ret = rskcp_encode(tun->rt, tun->buf, (data_len + rs_offset), &tun->buf[raw_len]);
         data_len = raw_len + plen;
      } else {
         ret = xor64_checksum_gen((uint8_t*)data, data_len, &data[data_len]);
         data_len += XOR64_CHECKSUM_SIZE;
      }

      if (ret && data_len>0  && mnet_chann_cached(udpin) < tun->conf->tcp_cache) {
         ret = mnet_chann_send(udpin, tun->buf, data_len);
         if (ret == data_len) {
            return len;
         }
      }
   }
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r15
movl %esi, %ebx
movq %rdi, %r12
movslq (%rcx), %rax
movq 0x8(%rcx,%rax,8), %r14
incl %eax
movq 0x78(%rcx), %rcx
cltd
idivl 0x94(%rcx)
movl %edx, (%r15)
movq %r14, %rdi
callq 0x45f0
cmpl $0x3, %eax
jl 0x8e71
movq %r14, -0x48(%rbp)
xorl %r13d, %r13d
cmpq $0x0, 0x90(%r15)
setne %r13b
addl %r13d, %r13d
leaq (%r15,%r13), %rcx
addq $0x98, %rcx
movq 0x78(%r15), %rax
cmpl $0x0, 0x148(%rax)
movq %rcx, -0x40(%rbp)
je 0x8dbf
movq 0x60(%r15), %r8
movq 0x68(%r15), %r9
shrq $0x14, %r9
movq %r12, %rdi
movl %ebx, %esi
movq %rcx, %rdx
movl $0xfff8, %ecx           # imm = 0xFFF8
callq 0x56c9
movl %eax, %r12d
jmp 0x8dd0
movslq %ebx, %rdx
movq %rcx, %rdi
movq %r12, %rsi
callq 0x2220
movl %ebx, %r12d
leaq 0x98(%r15), %r14
movq 0x90(%r15), %rdi
testq %rdi, %rdi
movq %r14, -0x38(%rbp)
je 0x8e26
leaq -0x2c(%rbp), %rdx
movl $0x0, (%rdx)
movw %r12w, 0x98(%r15)
addl %r12d, %r13d
movl %r13d, %esi
callq 0x91f7
movq 0x90(%r15), %rdi
movslq %eax, %r12
leaq (%r14,%r12), %rcx
movq %r14, %rsi
movl %r13d, %edx
callq 0x9258
leaq -0x2c(%rbp), %rcx
addl (%rcx), %r12d
jmp 0x8e3c
movslq %r12d, %rdx
movq -0x40(%rbp), %rdi
addq %rdi, %rdx
movl %r12d, %esi
callq 0x5b88
addl $0x8, %r12d
testl %eax, %eax
movq -0x48(%rbp), %r14
je 0x8e71
testl %r12d, %r12d
jle 0x8e71
movq %r14, %rdi
callq 0x5052
movq 0x78(%r15), %rcx
cmpl 0x154(%rcx), %eax
jge 0x8e71
movq %r14, %rdi
movq -0x38(%rbp), %rsi
movl %r12d, %edx
callq 0x4d27
cmpl %r12d, %eax
je 0x8e73
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq