// File: DoubleString[P]RtConverter/src/Rtklib/stream.cpp
// Function: bamboo::strread(bamboo::stream_t*, unsigned char*, int)
extern int strread(stream_t *stream, unsigned char *buff, int n)
	{
		unsigned int tick;
		char *msg = stream->msg;
		int nr;

		tracet(4, "strread: n=%d\n", n);

		if (!(stream->mode&STR_MODE_R) || !stream->port) return 0;

		strlock(stream);

		switch (stream->type) {
		case STR_SERIAL: nr = readserial((serial_t *)stream->port, buff, n, msg); break;
		case STR_FILE: nr = readfile((file_t   *)stream->port, buff, n, msg); break;
		case STR_TCPSVR: nr = readtcpsvr((tcpsvr_t *)stream->port, buff, n, msg); break;
		case STR_TCPCLI: nr = readtcpcli((tcpcli_t *)stream->port, buff, n, msg); break;
		case STR_NTRIPSVR:
		case STR_NTRIPCLI: nr = readntrip((ntrip_t  *)stream->port, buff, n, msg); break;
		case STR_NTRIPC_S:
		case STR_NTRIPC_C: nr = readntripc((ntripc_t *)stream->port, buff, n, msg); break;
		case STR_UDPSVR: nr = readudpsvr((udp_t    *)stream->port, buff, n, msg); break;
		case STR_MEMBUF: nr = readmembuf((membuf_t *)stream->port, buff, n, msg); break;
		case STR_FTP: nr = readftp((ftp_t    *)stream->port, buff, n, msg); break;
		case STR_HTTP: nr = readftp((ftp_t    *)stream->port, buff, n, msg); break;
		case STR_VRSCONCLI: nr = readvrsconcli((vrscon_cli_t*)stream->port, buff, n, msg); break;
		case STR_VRSCONSVR: nr = readvrsconsvr((vrscon_svr_t*)stream->port, buff, n, msg); break;
		default:
			strunlock(stream);
			return 0;
		}
		stream->inb += nr;
		tick = tickget(); if (nr > 0) stream->tact = tick;

		if ((int)(tick - stream->tick_i) >= tirate) {
			stream->inr = (stream->inb - stream->inbt) * 8000 / (tick - stream->tick_i);
			stream->tick_i = tick; stream->inbt = stream->inb;
		}
		strunlock(stream);
		return nr;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
addq $0x460, %rax            # imm = 0x460
movq %rax, -0x28(%rbp)
movl -0x1c(%rbp), %edx
movl $0x4, %edi
leaq 0x297b7(%rip), %rsi     # 0xc8bb7
movb $0x0, %al
callq 0x95890
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x9f421
movq -0x10(%rbp), %rax
cmpq $0x0, 0x58(%rax)
jne 0x9f42d
movl $0x0, -0x4(%rbp)
jmp 0x9f673
movq -0x10(%rbp), %rdi
callq 0x9ef00
movq -0x10(%rbp), %rax
movl (%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0xf, %eax
ja 0x9f5d5
movq -0x38(%rbp), %rax
leaq 0x29578(%rip), %rcx     # 0xc89d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x9f680
movl %eax, -0x2c(%rbp)
jmp 0x9f5ea
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x9f760
movl %eax, -0x2c(%rbp)
jmp 0x9f5ea
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x9fc30
movl %eax, -0x2c(%rbp)
jmp 0x9f5ea
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x9fdc0
movl %eax, -0x2c(%rbp)
jmp 0x9f5ea
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x9fef0
movl %eax, -0x2c(%rbp)
jmp 0x9f5ea
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x9ffd0
movl %eax, -0x2c(%rbp)
jmp 0x9f5ea
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa0190
movl %eax, -0x2c(%rbp)
jmp 0x9f5ea
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa0310
movl %eax, -0x2c(%rbp)
jmp 0x9f5ea
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa0400
movl %eax, -0x2c(%rbp)
jmp 0x9f5ea
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa0400
movl %eax, -0x2c(%rbp)
jmp 0x9f5ea
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa0730
movl %eax, -0x2c(%rbp)
jmp 0x9f5ea
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa0870
movl %eax, -0x2c(%rbp)
jmp 0x9f5ea
movq -0x10(%rbp), %rdi
callq 0x9f2f0
movl $0x0, -0x4(%rbp)
jmp 0x9f673
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0xc(%rax), %ecx
movl %ecx, 0xc(%rax)
callq 0x8f860
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x2c(%rbp)
jle 0x9f60f
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x1c(%rcx), %eax
cmpl 0x5a449(%rip), %eax     # 0xf9a68
jl 0x9f664
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x28(%rcx), %eax
imull $0x1f40, %eax, %eax     # imm = 0x1F40
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rdx
subl 0x1c(%rdx), %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rdi
callq 0x9f2f0
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)