// File: DoubleString[P]RtConverter/src/Rtklib/stream.cpp
// Function: bamboo::strwrite(bamboo::stream_t*, unsigned char*, int)
extern int strwrite(stream_t *stream, unsigned char *buff, int n)
	{
		unsigned int tick;
		char *msg = stream->msg;
		int ns;

		tracet(4, "strwrite: n=%d\n", n);

		if (!(stream->mode&STR_MODE_W) || !stream->port) return 0;

		strlock(stream);

		switch (stream->type) {
		case STR_SERIAL: ns = writeserial((serial_t *)stream->port, buff, n, msg); break;
		case STR_FILE: ns = writefile((file_t   *)stream->port, buff, n, msg); break;
		case STR_TCPSVR: ns = writetcpsvr((tcpsvr_t *)stream->port, buff, n, msg); break;
		case STR_TCPCLI: ns = writetcpcli((tcpcli_t *)stream->port, buff, n, msg); break;
		case STR_NTRIPSVR:
		case STR_NTRIPCLI: ns = writentrip((ntrip_t  *)stream->port, buff, n, msg); break;
		case STR_NTRIPC_S:
		case STR_NTRIPC_C: ns = writentripc((ntripc_t *)stream->port, buff, n, msg); break;
		case STR_UDPCLI: ns = writeudpcli((udp_t    *)stream->port, buff, n, msg); break;
		case STR_MEMBUF: ns = writemembuf((membuf_t *)stream->port, buff, n, msg); break;
		case STR_VRSCONCLI: ns = writevrsconcli((vrscon_cli_t*)stream->port, buff, n, msg); break;
		case STR_VRSCONSVR: ns = writevrsconsvr((vrscon_svr_t*)stream->port, buff, n, msg); break;
		case STR_FTP:
		case STR_HTTP:

		default:
			strunlock(stream);
			return 0;
		}
		stream->outb += ns;
		tick = tickget(); if (ns > 0) stream->tact = tick;

		if ((int)(tick - stream->tick_o) > tirate) {
			stream->outr = (int)((double)(stream->outb - stream->outbt) * 8000 / (tick - stream->tick_o));
			stream->tick_o = tick; stream->outbt = stream->outb;
		}
		strunlock(stream);
		return ns;
	}

// 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 0x281d6(%rip), %rsi     # 0xc8bc6
movb $0x0, %al
callq 0x95890
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xa0a11
movq -0x10(%rbp), %rax
cmpq $0x0, 0x58(%rax)
jne 0xa0a1d
movl $0x0, -0x4(%rbp)
jmp 0xa0c33
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 0xa0b87
movq -0x38(%rbp), %rax
leaq 0x27fc8(%rip), %rcx     # 0xc8a10
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 0xa0c40
movl %eax, -0x2c(%rbp)
jmp 0xa0b9c
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa0ce0
movl %eax, -0x2c(%rbp)
jmp 0xa0b9c
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa10f0
movl %eax, -0x2c(%rbp)
jmp 0xa0b9c
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa1280
movl %eax, -0x2c(%rbp)
jmp 0xa0b9c
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa13c0
movl %eax, -0x2c(%rbp)
jmp 0xa0b9c
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa1430
movl %eax, -0x2c(%rbp)
jmp 0xa0b9c
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa1600
movl %eax, -0x2c(%rbp)
jmp 0xa0b9c
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa1670
movl %eax, -0x2c(%rbp)
jmp 0xa0b9c
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa1790
movl %eax, -0x2c(%rbp)
jmp 0xa0b9c
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0xa17f0
movl %eax, -0x2c(%rbp)
jmp 0xa0b9c
jmp 0xa0b87
movq -0x10(%rbp), %rdi
callq 0x9f2f0
movl $0x0, -0x4(%rbp)
jmp 0xa0c33
movl -0x2c(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x14(%rax), %ecx
movl %ecx, 0x14(%rax)
callq 0x8f860
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x2c(%rbp)
jle 0xa0bc1
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x20(%rcx), %eax
cmpl 0x58e97(%rip), %eax     # 0xf9a68
jle 0xa0c24
movq -0x10(%rbp), %rcx
movl 0x2c(%rcx), %edx
movl 0x14(%rcx), %eax
movl 0x20(%rcx), %ecx
subl %edx, %eax
cvtsi2sd %rax, %xmm0
movsd 0x27f31(%rip), %xmm1    # 0xc8b20
mulsd %xmm1, %xmm0
movl -0x20(%rbp), %eax
subl %ecx, %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%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)