// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r10
movl 0x10(%rdi), %ebx
testb $0x2, 0xf4(%rdi)
movq %rdi, -0x38(%rbp)
je 0x30df
cmpq $0x0, 0x100(%r10)
je 0x30df
leaq 0x8048(%rip), %rdx      # 0xb111
movq %r10, %rdi
movl $0x2, %esi
movq %r15, %rcx
xorl %eax, %eax
callq 0x2620
movq -0x38(%rbp), %r10
testq %r12, %r12
sete %al
cmpl $0x18, %r15d
setl %cl
orb %al, %cl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jne 0x36fc
movl %ebx, -0x70(%rbp)
leaq 0xa8(%r10), %rax
movq %rax, -0x50(%rbp)
leaq 0x14(%r10), %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x3, %ebx
cmpq $0x18, %r15
jl 0x3162
movl (%r12), %r14d
movl $0x1, %ebx
cmpl (%r10), %r14d
jne 0x3159
movl 0x14(%r12), %esi
leaq 0x18(%r12), %rdx
addq $-0x18, %r15
movq %r15, %r13
subq %rsi, %r13
jge 0x3171
movq %r15, %r13
movq %rdx, %r12
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0x3165
addq $0x4, %r12
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %r15, %r13
movq %r13, %r15
testl %ebx, %ebx
je 0x311d
jmp 0x3633
movzbl 0x4(%r12), %ecx
movq %rcx, -0x88(%rbp)
addl $-0x55, %ecx
cmpb $-0x4, %cl
jae 0x3193
movq %r15, %r13
movq %rdx, %r12
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jmp 0x3165
movq %rsi, -0x30(%rbp)
movq %rdx, -0x68(%rbp)
movl %eax, -0x74(%rbp)
movzbl 0x5(%r12), %eax
movl %eax, -0x6c(%rbp)
movzwl 0x6(%r12), %ecx
movl 0x8(%r12), %eax
movl %eax, -0x3c(%rbp)
movl 0xc(%r12), %eax
movl %eax, -0x58(%rbp)
movl 0x10(%r12), %eax
movl %eax, -0x5c(%rbp)
movl %ecx, -0x54(%rbp)
movl %ecx, 0x40(%r10)
movq 0xa8(%r10), %rdi
cmpq -0x50(%rbp), %rdi
je 0x3222
movl -0x5c(%rbp), %eax
subl 0x24(%rdi), %eax
testl %eax, %eax
jle 0x3222
movq (%rdi), %r12
movq 0x8(%rdi), %rax
movq %rax, 0x8(%r12)
movq 0x8(%rdi), %rax
movq %r12, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq 0xd08d(%rip), %rax      # 0x10290
testq %rax, %rax
je 0x320c
callq *%rax
jmp 0x3211
callq 0x2310
movq -0x38(%rbp), %r10
decl 0x60(%r10)
movq %r12, %rdi
cmpq -0x50(%rbp), %r12
jne 0x31d9
movq 0xa8(%r10), %rdi
leaq 0x24(%rdi), %rax
cmpq -0x50(%rbp), %rdi
cmoveq -0x80(%rbp), %rax
movl (%rax), %eax
movl %eax, 0x10(%r10)
movq -0x88(%rbp), %rax
addl $-0x51, %eax
cmpl $0x3, %eax
ja 0x33d6
leaq 0x7dda(%rip), %rcx      # 0xb030
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testb $0x10, 0xf4(%r10)
movl -0x58(%rbp), %r12d
je 0x3298
cmpq $0x0, 0x100(%r10)
je 0x3298
movq %r10, %rdi
movl $0x10, %esi
leaq 0x7ebb(%rip), %rdx      # 0xb141
movl %r12d, %ecx
movl -0x3c(%rbp), %r8d
xorl %eax, %eax
callq 0x2620
movq -0x38(%rbp), %r10
movl 0x18(%r10), %eax
addl 0x3c(%r10), %eax
cmpl %eax, %r12d
jns 0x34b8
movl 0xd0(%r10), %eax
incl %eax
cmpl 0xd4(%r10), %eax
movq -0x30(%rbp), %rdx
jbe 0x3570
movl $0x8, %ecx
movq %rcx, %rbx
addq %rcx, %rcx
cmpq %rax, %rbx
jb 0x32c8
leaq (,%rbx,8), %rdi
movq 0xcfa6(%rip), %rax      # 0x10288
testq %rax, %rax
je 0x34f9
callq *%rax
jmp 0x34fe
orb $0x2, 0x48(%r10)
testb $0x40, 0xf4(%r10)
je 0x34b8
cmpq $0x0, 0x100(%r10)
je 0x34b8
movq %r10, %rdi
movl $0x40, %esi
leaq 0x7e38(%rip), %rdx      # 0xb15a
xorl %eax, %eax
callq 0x2620
jmp 0x34b4
testb $-0x80, 0xf4(%r10)
je 0x34b8
cmpq $0x0, 0x100(%r10)
je 0x34b8
movq %r10, %rdi
movl $0x80, %esi
leaq 0x7e0d(%rip), %rdx      # 0xb166
movl -0x54(%rbp), %ecx
xorl %eax, %eax
callq 0x2620
jmp 0x34b4
movl 0x4c(%r10), %eax
subl -0x3c(%rbp), %eax
movl -0x44(%rbp), %ebx
movl -0x58(%rbp), %r14d
js 0x3417
movl 0x2c(%r10), %ecx
testl %ecx, %ecx
je 0x33e2
movl %eax, %edx
subl %ecx, %edx
movl %edx, %esi
negl %esi
cmovsl %edx, %esi
movslq 0x28(%r10), %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rsi,%rdx), %r8
addq $0x3, %r8
addq %rsi, %rdx
cmovnsq %rdx, %r8
shrq $0x2, %r8
movl %r8d, 0x28(%r10)
leal (,%rcx,8), %edx
subl %ecx, %edx
leal (%rdx,%rax), %ecx
addl $0x7, %ecx
addl %eax, %edx
cmovnsl %edx, %ecx
sarl $0x3, %ecx
cmpl $0x8, %edx
movl $0x1, %eax
cmovll %eax, %ecx
movl %ecx, 0x2c(%r10)
jmp 0x33ec
movq %r15, %r13
movq -0x68(%rbp), %r12
jmp 0x318c
movl %eax, 0x2c(%r10)
shrl %eax
movl %eax, 0x28(%r10)
movl 0x50(%r10), %eax
movl 0x28(%r10), %ecx
shll $0x2, %ecx
cmpl %ecx, %eax
cmoval %eax, %ecx
movl 0x34(%r10), %eax
addl 0x2c(%r10), %ecx
cmpl %ecx, %eax
cmoval %eax, %ecx
movl $0xea60, %eax           # imm = 0xEA60
cmpl %eax, %ecx
cmovael %eax, %ecx
movl %ecx, 0x30(%r10)
cmpl 0x10(%r10), %r14d
js 0x3423
cmpl 0x14(%r10), %r14d
js 0x3466
movq 0xa8(%r10), %rax
leaq 0x24(%rax), %rcx
cmpq -0x50(%rbp), %rax
cmoveq -0x80(%rbp), %rcx
movl %r14d, %eax
subl %ebx, %eax
testl %eax, %eax
cmovgl %r14d, %ebx
movl (%rcx), %eax
cmpl $0x0, -0x40(%rbp)
cmovel %r14d, %ebx
movl %eax, 0x10(%r10)
testb $0x20, 0xf4(%r10)
movl %ebx, -0x44(%rbp)
jne 0x347c
movl $0x1, -0x40(%rbp)
jmp 0x34b8
cmpq -0x50(%rbp), %rdi
je 0x3423
movq (%rdi), %rax
cmpl 0x24(%rdi), %r14d
je 0x34cd
movq %rax, %rdi
jns 0x3466
jmp 0x3423
movl $0x1, -0x40(%rbp)
cmpq $0x0, 0x100(%r10)
je 0x34b8
movl 0x4c(%r10), %eax
subl -0x3c(%rbp), %eax
movslq %eax, %r8
movslq 0x30(%r10), %r9
movq %r10, %rdi
movl $0x10, %esi
leaq 0x7c75(%rip), %rdx      # 0xb11f
movl %r14d, %ecx
xorl %eax, %eax
callq 0x2620
movq -0x38(%rbp), %r10
movq -0x30(%rbp), %rdx
movq -0x68(%rbp), %r12
addq %rdx, %r12
xorl %ebx, %ebx
movl -0x74(%rbp), %eax
jmp 0x3165
movq 0x8(%rdi), %rcx
movq %rcx, 0x8(%rax)
movq 0x8(%rdi), %rcx
movq %rax, (%rcx)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq 0xcda7(%rip), %rax      # 0x10290
testq %rax, %rax
je 0x3621
callq *%rax
jmp 0x3626
callq 0x2350
movq %rax, %r15
testq %rax, %rax
movq -0x38(%rbp), %r10
je 0x370b
movq 0xc8(%r10), %rdi
testq %rdi, %rdi
je 0x355e
cmpl $0x0, 0xd0(%r10)
je 0x3545
xorl %eax, %eax
movl (%rdi,%rax,8), %ecx
movl %ecx, (%r15,%rax,8)
movl 0x4(%rdi,%rax,8), %ecx
movl %ecx, 0x4(%r15,%rax,8)
incq %rax
movl 0xd0(%r10), %ecx
cmpq %rcx, %rax
jb 0x3526
movq 0xcd44(%rip), %rax      # 0x10290
testq %rax, %rax
je 0x3555
callq *%rax
jmp 0x355a
callq 0x2310
movq -0x38(%rbp), %r10
movq %r15, 0xc8(%r10)
movl %ebx, 0xd4(%r10)
movq -0x30(%rbp), %rdx
movq 0xc8(%r10), %rax
movl 0xd0(%r10), %ecx
addl %ecx, %ecx
movl %r12d, (%rax,%rcx,4)
movl -0x3c(%rbp), %esi
movl %esi, 0x4(%rax,%rcx,4)
incl 0xd0(%r10)
cmpl 0x18(%r10), %r12d
js 0x34bc
movslq %edx, %rdi
addq $0x48, %rdi
movq 0xccde(%rip), %rax      # 0x10288
testq %rax, %rax
je 0x35b3
callq *%rax
jmp 0x35b8
callq 0x2350
movq %rax, %r15
movl %r14d, 0x10(%rax)
movq -0x88(%rbp), %rax
movl %eax, 0x14(%r15)
movl -0x6c(%rbp), %eax
movl %eax, 0x18(%r15)
movl -0x54(%rbp), %eax
movl %eax, 0x1c(%r15)
movl -0x3c(%rbp), %eax
movl %eax, 0x20(%r15)
movl %r12d, 0x24(%r15)
movl -0x5c(%rbp), %eax
movl %eax, 0x28(%r15)
movq -0x30(%rbp), %r14
movl %r14d, 0x2c(%r15)
testl %r14d, %r14d
je 0x3607
leaq 0x40(%r15), %rdi
movq -0x68(%rbp), %rsi
movq %r14, %rdx
callq 0x2220
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2f78
movq %rbx, %r10
movq %r14, %rdx
jmp 0x34bc
callq 0x2310
movq -0x38(%rbp), %r10
decl 0x60(%r10)
jmp 0x3423
cmpl $0x3, %ebx
jne 0x36fc
cmpl $0x0, -0x40(%rbp)
movl -0x70(%rbp), %edx
movl -0x44(%rbp), %esi
je 0x3674
cmpl 0x10(%r10), %esi
js 0x3674
cmpl 0x14(%r10), %esi
jns 0x3674
movq 0xa8(%r10), %rax
cmpq -0x50(%rbp), %rax
je 0x3674
movl %esi, %ecx
subl 0x24(%rax), %ecx
je 0x366d
js 0x366d
incl 0x38(%rax)
movq (%rax), %rax
testl %ecx, %ecx
jns 0x365b
movl 0x10(%r10), %ecx
subl %edx, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jle 0x36fc
movl 0x40(%r10), %ecx
movl 0x44(%r10), %edi
cmpl %ecx, %edi
jae 0x36fa
movl 0x8(%r10), %esi
cmpl 0x24(%r10), %edi
jae 0x36a5
incl %edi
movl %edi, 0x44(%r10)
addl %esi, 0x80(%r10)
jmp 0x36e6
cmpl %esi, 0x80(%r10)
jae 0x36b5
movl %esi, 0x80(%r10)
movl %esi, %eax
imull %esi, %eax
movl 0x80(%r10), %r8d
xorl %edx, %edx
divl %r8d
movl %esi, %edx
shrl $0x4, %edx
addl %r8d, %edx
addl %eax, %edx
movl %edx, 0x80(%r10)
incl %edi
movl %esi, %eax
imull %edi, %eax
cmpl %edx, %eax
ja 0x36e6
movl %edi, 0x44(%r10)
cmpl %ecx, 0x44(%r10)
jbe 0x36fa
movl %ecx, 0x44(%r10)
imull %ecx, %esi
movl %esi, 0x80(%r10)
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7a64(%rip), %rdi      # 0xb176
leaq 0x792b(%rip), %rsi      # 0xb044
leaq 0x7a66(%rip), %rcx      # 0xb186
movl $0x283, %edx            # imm = 0x283
callq 0x21b0