// File: /workspace/github_cpp_makefile_star2_O3/xocoder[P]m_kcptun/vendor/kcp/ikcp.c
// Function: ikcp_input
int ikcp_input(ikcpcb *kcp, const char *data, long size)
{
	IUINT32 una = kcp->snd_una;
	IUINT32 maxack = 0;
	int flag = 0;

	if (ikcp_canlog(kcp, IKCP_LOG_INPUT)) {
		ikcp_log(kcp, IKCP_LOG_INPUT, "[RI] %d bytes", size);
	}

	if (data == NULL || (int)size < (int)IKCP_OVERHEAD) return -1;

	while (1) {
		IUINT32 ts, sn, len, una, conv;
		IUINT16 wnd;
		IUINT8 cmd, frg;
		IKCPSEG *seg;

		if (size < (int)IKCP_OVERHEAD) break;

		data = ikcp_decode32u(data, &conv);
		if (conv != kcp->conv) return -1;

		data = ikcp_decode8u(data, &cmd);
		data = ikcp_decode8u(data, &frg);
		data = ikcp_decode16u(data, &wnd);
		data = ikcp_decode32u(data, &ts);
		data = ikcp_decode32u(data, &sn);
		data = ikcp_decode32u(data, &una);
		data = ikcp_decode32u(data, &len);

		size -= IKCP_OVERHEAD;

		if ((long)size < (long)len) return -2;

		if (cmd != IKCP_CMD_PUSH && cmd != IKCP_CMD_ACK &&
			cmd != IKCP_CMD_WASK && cmd != IKCP_CMD_WINS) 
			return -3;

		kcp->rmt_wnd = wnd;
		ikcp_parse_una(kcp, una);
		ikcp_shrink_buf(kcp);

		if (cmd == IKCP_CMD_ACK) {
			if (_itimediff(kcp->current, ts) >= 0) {
				ikcp_update_ack(kcp, _itimediff(kcp->current, ts));
			}
			ikcp_parse_ack(kcp, sn);
			ikcp_shrink_buf(kcp);
			if (flag == 0) {
				flag = 1;
				maxack = sn;
			}	else {
				if (_itimediff(sn, maxack) > 0) {
					maxack = sn;
				}
			}
			if (ikcp_canlog(kcp, IKCP_LOG_IN_ACK)) {
				ikcp_log(kcp, IKCP_LOG_IN_DATA, 
					"input ack: sn=%lu rtt=%ld rto=%ld", sn, 
					(long)_itimediff(kcp->current, ts),
					(long)kcp->rx_rto);
			}
		}
		else if (cmd == IKCP_CMD_PUSH) {
			if (ikcp_canlog(kcp, IKCP_LOG_IN_DATA)) {
				ikcp_log(kcp, IKCP_LOG_IN_DATA, 
					"input psh: sn=%lu ts=%lu", sn, ts);
			}
			if (_itimediff(sn, kcp->rcv_nxt + kcp->rcv_wnd) < 0) {
				ikcp_ack_push(kcp, sn, ts);
				if (_itimediff(sn, kcp->rcv_nxt) >= 0) {
					seg = ikcp_segment_new(kcp, len);
					seg->conv = conv;
					seg->cmd = cmd;
					seg->frg = frg;
					seg->wnd = wnd;
					seg->ts = ts;
					seg->sn = sn;
					seg->una = una;
					seg->len = len;

					if (len > 0) {
						memcpy(seg->data, data, len);
					}

					ikcp_parse_data(kcp, seg);
				}
			}
		}
		else if (cmd == IKCP_CMD_WASK) {
			// ready to send back IKCP_CMD_WINS in ikcp_flush
			// tell remote my window size
			kcp->probe |= IKCP_ASK_TELL;
			if (ikcp_canlog(kcp, IKCP_LOG_IN_PROBE)) {
				ikcp_log(kcp, IKCP_LOG_IN_PROBE, "input probe");
			}
		}
		else if (cmd == IKCP_CMD_WINS) {
			// do nothing
			if (ikcp_canlog(kcp, IKCP_LOG_IN_WINS)) {
				ikcp_log(kcp, IKCP_LOG_IN_WINS,
					"input wins: %lu", (IUINT32)(wnd));
			}
		}
		else {
			return -3;
		}

		data += len;
		size -= len;
	}

	if (flag != 0) {
		ikcp_parse_fastack(kcp, maxack);
	}

	if (_itimediff(kcp->snd_una, una) > 0) {
		if (kcp->cwnd < kcp->rmt_wnd) {
			IUINT32 mss = kcp->mss;
			if (kcp->cwnd < kcp->ssthresh) {
				kcp->cwnd++;
				kcp->incr += mss;
			}	else {
				if (kcp->incr < mss) kcp->incr = mss;
				kcp->incr += (mss * mss) / kcp->incr + (mss / 16);
				if ((kcp->cwnd + 1) * mss <= kcp->incr) {
					kcp->cwnd++;
				}
			}
			if (kcp->cwnd > kcp->rmt_wnd) {
				kcp->cwnd = kcp->rmt_wnd;
				kcp->incr = kcp->rmt_wnd * mss;
			}
		}
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movl 0x10(%rdi), %eax
movl %eax, -0x58(%rbp)
testb $0x2, 0xf4(%rdi)
je 0x3120
cmpq $0x0, 0x100(%rbx)
je 0x3120
leaq 0x8003(%rip), %rdx      # 0xb111
movq %rbx, %rdi
movl $0x2, %esi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2630
testq %r15, %r15
sete %al
cmpl $0x18, %r14d
setl %cl
orb %al, %cl
je 0x313d
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
jmp 0x3702
cmpq $0x17, %r14
jg 0x3184
movl 0x10(%rbx), %eax
movl -0x58(%rbp), %edx
subl %edx, %eax
testl %eax, %eax
jle 0x364e
movl 0x40(%rbx), %ecx
movl 0x44(%rbx), %edi
cmpl %ecx, %edi
jae 0x364e
movl 0x8(%rbx), %esi
cmpl 0x24(%rbx), %edi
jae 0x36af
movl $0x0, -0x30(%rbp)
incl %edi
movl %edi, 0x44(%rbx)
addl %esi, 0x80(%rbx)
jmp 0x36f2
leaq 0xa8(%rbx), %r10
leaq 0x14(%rbx), %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x50(%rbp)
movq %r10, -0x48(%rbp)
movl (%r15), %edx
cmpl (%rbx), %edx
jne 0x3131
movl 0x14(%r15), %ecx
addq $-0x18, %r14
subq %rcx, %r14
jb 0x365a
movzbl 0x4(%r15), %r13d
leal -0x55(%r13), %eax
movl $0xfffffffd, -0x30(%rbp) # imm = 0xFFFFFFFD
cmpb $-0x4, %al
jb 0x3702
movl %edx, -0x70(%rbp)
movq %rcx, -0x40(%rbp)
movzbl 0x5(%r15), %eax
movl %eax, -0x6c(%rbp)
movzwl 0x6(%r15), %ecx
movl 0x8(%r15), %eax
movl %eax, -0x34(%rbp)
movl 0xc(%r15), %eax
movl %eax, -0x4c(%rbp)
movl 0x10(%r15), %r12d
movl %ecx, -0x5c(%rbp)
movl %ecx, 0x40(%rbx)
movq 0xa8(%rbx), %rdi
cmpq %r10, %rdi
je 0x325a
movq %r14, -0x78(%rbp)
movl %r12d, %eax
subl 0x24(%rdi), %eax
testl %eax, %eax
jle 0x3253
movq (%rdi), %r14
movq 0x8(%rdi), %rax
movq %rax, 0x8(%r14)
movq %r14, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq 0xd05a(%rip), %rax      # 0x10290
testq %rax, %rax
je 0x323f
callq *%rax
jmp 0x3244
callq 0x2320
decl 0x60(%rbx)
movq %r14, %rdi
movq -0x48(%rbp), %r10
cmpq %r10, %r14
jne 0x3211
movq (%r10), %rdi
movq -0x78(%rbp), %r14
leaq 0x24(%rdi), %rax
cmpq %r10, %rdi
cmoveq -0x68(%rbp), %rax
movl (%rax), %eax
movl %eax, 0x10(%rbx)
addl $-0x51, %r13d
cmpl $0x3, %r13d
ja 0x3702
addq $0x18, %r15
leaq 0x7dac(%rip), %rdx      # 0xb030
movslq (%rdx,%r13,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
testb $0x10, 0xf4(%rbx)
movl -0x4c(%rbp), %r13d
je 0x32c5
cmpq $0x0, 0x100(%rbx)
je 0x32c5
movq %rbx, %rdi
movl $0x10, %esi
leaq 0x7e8e(%rip), %rdx      # 0xb141
movl %r13d, %ecx
movl -0x34(%rbp), %r8d
xorl %eax, %eax
callq 0x2630
movq -0x48(%rbp), %r10
movl 0x18(%rbx), %eax
addl 0x3c(%rbx), %eax
cmpl %eax, %r13d
jns 0x35bf
movl 0xd0(%rbx), %edx
leal 0x1(%rdx), %ecx
cmpl 0xd4(%rbx), %ecx
jbe 0x34d9
movl $0x8, %eax
movq %rax, %r13
addq %rax, %rax
cmpq %rcx, %r13
jb 0x32ee
leaq (,%r13,8), %rdi
movq 0xcf80(%rip), %rax      # 0x10288
testq %rax, %rax
je 0x3510
callq *%rax
jmp 0x3515
orb $0x2, 0x48(%rbx)
testb $0x40, 0xf4(%rbx)
je 0x35bf
cmpq $0x0, 0x100(%rbx)
movq -0x40(%rbp), %r12
je 0x3627
movq %rbx, %rdi
movl $0x40, %esi
leaq 0x7e10(%rip), %rdx      # 0xb15a
xorl %eax, %eax
callq 0x2630
jmp 0x3623
testb $-0x80, 0xf4(%rbx)
je 0x35bf
cmpq $0x0, 0x100(%rbx)
movq -0x40(%rbp), %r12
je 0x3627
movq %rbx, %rdi
movl $0x80, %esi
leaq 0x7de2(%rip), %rdx      # 0xb166
movl -0x5c(%rbp), %ecx
xorl %eax, %eax
callq 0x2630
jmp 0x3623
movl 0x4c(%rbx), %ecx
subl -0x34(%rbp), %ecx
movl -0x4c(%rbp), %r13d
js 0x3430
movl 0x2c(%rbx), %esi
testl %esi, %esi
je 0x3401
movl %ecx, %edx
subl %esi, %edx
movl %edx, %r8d
negl %r8d
cmovsl %edx, %r8d
movslq 0x28(%rbx), %rdx
leaq (%rdx,%rdx,2), %r9
leaq (%r8,%r9), %rdx
addq $0x3, %rdx
addq %r8, %r9
cmovnsq %r9, %rdx
shrq $0x2, %rdx
movl %edx, 0x28(%rbx)
leal (,%rsi,8), %r8d
subl %esi, %r8d
movl %r8d, %esi
addl %ecx, %esi
leal 0x7(%r8,%rcx), %ecx
cmovnsl %esi, %ecx
sarl $0x3, %ecx
cmpl $0x8, %esi
movl $0x1, %esi
cmovll %esi, %ecx
movl %ecx, 0x2c(%rbx)
jmp 0x340b
movl %ecx, 0x2c(%rbx)
movl %ecx, %edx
shrl %edx
movl %edx, 0x28(%rbx)
movl 0x34(%rbx), %esi
movl 0x50(%rbx), %r8d
shll $0x2, %edx
cmpl %edx, %r8d
cmoval %r8d, %edx
addl %ecx, %edx
cmpl %edx, %esi
cmoval %esi, %edx
movl $0xea60, %ecx           # imm = 0xEA60
cmpl %ecx, %edx
cmovael %ecx, %edx
movl %edx, 0x30(%rbx)
cmpl %eax, %r13d
js 0x345e
movq -0x68(%rbp), %rax
cmpl (%rax), %r13d
movq -0x40(%rbp), %r12
jns 0x3462
movq %rdi, %rax
cmpq %r10, %rax
je 0x3462
movq (%rax), %rcx
cmpl 0x24(%rax), %r13d
je 0x34e5
movq %rcx, %rax
jns 0x3445
jmp 0x3462
movq -0x40(%rbp), %r12
leaq 0x24(%rdi), %rax
cmpq %r10, %rdi
cmoveq -0x68(%rbp), %rax
movl %r13d, %ecx
movl -0x50(%rbp), %edx
subl %edx, %ecx
testl %ecx, %ecx
cmovgl %r13d, %edx
movl (%rax), %eax
cmpl $0x0, -0x54(%rbp)
cmovel %r13d, %edx
movl %edx, -0x50(%rbp)
movl %eax, 0x10(%rbx)
movl $0x1, -0x54(%rbp)
testb $0x20, 0xf4(%rbx)
je 0x3627
cmpq $0x0, 0x100(%rbx)
je 0x3627
movl 0x4c(%rbx), %eax
subl -0x34(%rbp), %eax
movslq %eax, %r8
movslq 0x30(%rbx), %r9
movq %rbx, %rdi
movl $0x10, %esi
leaq 0x7c55(%rip), %rdx      # 0xb11f
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2630
jmp 0x3623
movq 0xc8(%rbx), %rax
jmp 0x358e
movq 0x8(%rax), %rdx
movq %rdx, 0x8(%rcx)
movq %rcx, (%rdx)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0xcd93(%rip), %rcx      # 0x10290
movq %rax, %rdi
testq %rcx, %rcx
je 0x3636
callq *%rcx
jmp 0x363b
callq 0x2360
testq %rax, %rax
movq -0x48(%rbp), %r10
je 0x3714
movq 0xc8(%rbx), %rdi
testq %rdi, %rdi
je 0x3576
cmpl $0x0, 0xd0(%rbx)
je 0x3555
xorl %edx, %edx
movl (%rdi,%rdx,8), %ecx
movl %ecx, (%rax,%rdx,8)
movl 0x4(%rdi,%rdx,8), %ecx
movl %ecx, 0x4(%rax,%rdx,8)
incq %rdx
movl 0xd0(%rbx), %ecx
cmpq %rcx, %rdx
jb 0x3539
movq %rax, -0x30(%rbp)
movq 0xcd30(%rip), %rax      # 0x10290
testq %rax, %rax
je 0x3569
callq *%rax
jmp 0x356e
callq 0x2320
movq -0x48(%rbp), %r10
movq -0x30(%rbp), %rax
movq %rax, 0xc8(%rbx)
movl %r13d, 0xd4(%rbx)
movl 0xd0(%rbx), %edx
movl -0x4c(%rbp), %r13d
addl %edx, %edx
movl %r13d, (%rax,%rdx,4)
movl -0x34(%rbp), %ecx
movl %ecx, 0x4(%rax,%rdx,4)
incl 0xd0(%rbx)
cmpl 0x18(%rbx), %r13d
js 0x35bf
movslq -0x40(%rbp), %rdi
addq $0x48, %rdi
movq 0xccd2(%rip), %rax      # 0x10288
testq %rax, %rax
je 0x35c5
callq *%rax
jmp 0x35ca
movq -0x40(%rbp), %r12
jmp 0x3627
callq 0x2360
movq %rax, %r13
movl -0x70(%rbp), %eax
movl %eax, 0x10(%r13)
movl $0x51, 0x14(%r13)
movl -0x6c(%rbp), %eax
movl %eax, 0x18(%r13)
movl -0x5c(%rbp), %eax
movl %eax, 0x1c(%r13)
movl -0x34(%rbp), %eax
movl %eax, 0x20(%r13)
movl -0x4c(%rbp), %eax
movl %eax, 0x24(%r13)
movl %r12d, 0x28(%r13)
movq -0x40(%rbp), %r12
movl %r12d, 0x2c(%r13)
testl %r12d, %r12d
je 0x3618
leaq 0x40(%r13), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2230
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2fd6
movq -0x48(%rbp), %r10
addq %r12, %r15
cmpq $0x17, %r14
jg 0x31a5
jmp 0x3666
callq 0x2320
decl 0x60(%rbx)
movq 0xa8(%rbx), %rdi
movq -0x48(%rbp), %r10
jmp 0x3462
movl $0x0, -0x30(%rbp)
jmp 0x3702
movl $0xfffffffe, -0x30(%rbp) # imm = 0xFFFFFFFE
jmp 0x3702
movl 0x10(%rbx), %eax
cmpl $0x0, -0x54(%rbp)
je 0x3146
movl -0x50(%rbp), %esi
movl %esi, %ecx
subl %eax, %ecx
movl -0x58(%rbp), %edx
js 0x3149
cmpl 0x14(%rbx), %esi
jns 0x3149
movq 0xa8(%rbx), %rcx
cmpq %r10, %rcx
je 0x3149
cmpl 0x24(%rcx), %esi
js 0x3149
je 0x36aa
incl 0x38(%rcx)
movq (%rcx), %rcx
jmp 0x3693
movl $0x0, -0x30(%rbp)
movl 0x80(%rbx), %r8d
cmpl %esi, %r8d
cmovbel %esi, %r8d
movl %esi, %eax
imull %esi, %eax
xorl %edx, %edx
divl %r8d
movl %esi, %edx
shrl $0x4, %edx
addl %r8d, %edx
addl %eax, %edx
movl %edx, 0x80(%rbx)
leal 0x1(%rdi), %eax
movl %esi, %r8d
imull %eax, %r8d
cmpl %edx, %r8d
ja 0x36f2
movl %eax, 0x44(%rbx)
movl %eax, %edi
cmpl %ecx, %edi
jbe 0x3702
movl %ecx, 0x44(%rbx)
imull %ecx, %esi
movl %esi, 0x80(%rbx)
movl -0x30(%rbp), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7a5b(%rip), %rdi      # 0xb176
leaq 0x7922(%rip), %rsi      # 0xb044
leaq 0x7a5d(%rip), %rcx      # 0xb186
movl $0x283, %edx            # imm = 0x283
callq 0x21b0