// File: DoubleString[P]RtConverter/src/Rtklib/stream.cpp
// Function: bamboo::readfile(bamboo::file_t*, unsigned char*, int, char*)
static int readfile(file_t *file, unsigned char *buff, int nmax, char *msg)
	{
		struct timeval tv = { 0 };
		fd_set rs;
		unsigned long fpos_8B;
		unsigned int t, tick, fpos_4B;
		long pos, n;
		int nr = 0;

		tracet(4, "readfile: fp=%d nmax=%d\n", file->fp, nmax);

		if (!file) return 0;

		if (file->fp == stdin) {
#ifndef WIN32
			/* input from stdin */
			FD_ZERO(&rs); FD_SET(0, &rs);
			if (!select(1, &rs, NULL, NULL, &tv)) return 0;
			if ((nr = (int)read(0, buff, nmax)) < 0) return 0;
			return nr;
#else
			return 0;
#endif
		}
		if (file->fp_tag) {

			/* target tick */
			if (file->repmode) { /* slave */
				t = (unsigned int)(tick_master + file->offset);
			}
			else { /* master */
				t = (unsigned int)((tickget() - file->tick)*file->speed + file->start*1000.0);
			}
			/* seek time-tag file to get next tick and file position */
			while (file->tick_n <= t) {

				if (fread(&file->tick_n, sizeof(tick), 1, file->fp_tag) < 1 ||
					fread(file->size_fpos == 4 ? (void *)&fpos_4B : (void *)&fpos_8B,
						file->size_fpos, 1, file->fp_tag) < 1) {
					file->tick_n = (unsigned int)(-1);
					pos = ftell(file->fp);
					fseek(file->fp, 0L, SEEK_END);
					file->fpos_n = (size_t)ftell(file->fp);
					fseek(file->fp, pos, SEEK_SET);
					break;
				}
				file->fpos_n = file->size_fpos == 4 ? (size_t)fpos_4B : (size_t)fpos_8B;
			}
			sprintf(msg, "T%+.1fs", (int)t*0.001);
			file->wtime = timeadd(file->time, (int)t*0.001);
			timeset(timeadd(file->time, (int)file->tick_n*0.001));

			if ((n = file->fpos_n - ftell(file->fp)) < nmax) {
				nmax = n;
			}
		}
		if (nmax > 0) {
			nr = (int)fread(buff, 1, nmax, file->fp);
		}
		if (feof(file->fp)) {
			sprintf(msg, "end");
		}
		tracet(5, "readfile: fp=%d nr=%d\n", file->fp, nr);
		return nr;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x93d0
movl $0x0, -0xe4(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movl -0x1c(%rbp), %ecx
movl $0x4, %edi
leaq 0x29c05(%rip), %rsi     # 0xc93af
movb $0x0, %al
callq 0x95890
cmpq $0x0, -0x10(%rbp)
jne 0x9f7c4
movl $0x0, -0x4(%rbp)
jmp 0x9fc1a
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x577de(%rip), %rcx     # 0xf6fb0
cmpq (%rcx), %rax
jne 0x9f89c
jmp 0x9f7dd
leaq -0xb8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movl $0x0, -0xe8(%rbp)
movl -0xe8(%rbp), %eax
cmpq $0x10, %rax
jae 0x9f827
movq -0xf0(%rbp), %rax
movl -0xe8(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0xe8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe8(%rbp)
jmp 0x9f7f5
jmp 0x9f829
movq -0xb8(%rbp), %rax
orq $0x1, %rax
movq %rax, -0xb8(%rbp)
movl $0x1, %edi
leaq -0xb8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x38(%rbp), %r8
movq %rcx, %rdx
callq 0x9710
cmpl $0x0, %eax
jne 0x9f868
movl $0x0, -0x4(%rbp)
jmp 0x9fc1a
movq -0x18(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
xorl %edi, %edi
callq 0x9aa0
movl %eax, -0xe4(%rbp)
cmpl $0x0, %eax
jge 0x9f88e
movl $0x0, -0x4(%rbp)
jmp 0x9fc1a
movl -0xe4(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x9fc1a
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x9fba9
movq -0x10(%rbp), %rax
cmpl $0x0, 0x828(%rax)
je 0x9f8d0
movl 0x708a2(%rip), %eax     # 0x110160
movq -0x10(%rbp), %rcx
addl 0x82c(%rcx), %eax
movl %eax, -0xc4(%rbp)
jmp 0x9f917
callq 0x8f860
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl 0x858(%rax), %edx
subl %edx, %ecx
cvtsi2sd %rcx, %xmm0
movsd 0x878(%rax), %xmm2
movsd 0x870(%rax), %xmm1
movsd 0x1db28(%rip), %xmm3    # 0xbd428
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0xc4(%rbp)
jmp 0x9f919
movq -0x10(%rbp), %rax
movl 0x868(%rax), %eax
cmpl -0xc4(%rbp), %eax
ja 0x9fa56
movq -0x10(%rbp), %rdi
addq $0x868, %rdi            # imm = 0x868
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x9af0
cmpq $0x1, %rax
jb 0x9f9ae
movq -0x10(%rbp), %rax
cmpl $0x4, 0x830(%rax)
jne 0x9f974
leaq -0xcc(%rbp), %rax
movq %rax, -0x138(%rbp)
jmp 0x9f984
leaq -0xc0(%rbp), %rax
movq %rax, -0x138(%rbp)
jmp 0x9f984
movq -0x138(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq 0x830(%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %edx
callq 0x9af0
cmpq $0x1, %rax
jae 0x9fa15
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x868(%rax) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x9030
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0x9830
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x9030
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x860(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0xd8(%rbp), %rsi
xorl %edx, %edx
callq 0x9830
jmp 0x9fa56
movq -0x10(%rbp), %rax
cmpl $0x4, 0x830(%rax)
jne 0x9fa31
movl -0xcc(%rbp), %eax
movq %rax, -0x140(%rbp)
jmp 0x9fa3f
movq -0xc0(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x140(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x860(%rax)
jmp 0x9f919
movq -0x28(%rbp), %rdi
cvtsi2sdl -0xc4(%rbp), %xmm0
movsd 0x1e2de(%rip), %xmm1    # 0xbdd48
mulsd %xmm1, %xmm0
leaq 0x29953(%rip), %rsi     # 0xc93c8
movb $0x1, %al
callq 0x9150
movq -0x10(%rbp), %rax
movq 0x838(%rax), %rcx
movq %rcx, -0x110(%rbp)
movq 0x840(%rax), %rax
movq %rax, -0x108(%rbp)
cvtsi2sdl -0xc4(%rbp), %xmm1
movsd 0x1e29c(%rip), %xmm0    # 0xbdd48
mulsd %xmm0, %xmm1
movq -0x110(%rbp), %rdi
movsd -0x108(%rbp), %xmm0
callq 0x8e860
movq %rax, -0x100(%rbp)
movsd %xmm0, -0xf8(%rbp)
movq -0x10(%rbp), %rax
movq -0x100(%rbp), %rcx
movq %rcx, 0x848(%rax)
movq -0xf8(%rbp), %rcx
movq %rcx, 0x850(%rax)
movq -0x10(%rbp), %rax
movq 0x838(%rax), %rcx
movq %rcx, -0x130(%rbp)
movq 0x840(%rax), %rax
movq %rax, -0x128(%rbp)
movq -0x10(%rbp), %rax
cvtsi2sdl 0x868(%rax), %xmm1
movsd 0x1e221(%rip), %xmm0    # 0xbdd48
mulsd %xmm0, %xmm1
movq -0x130(%rbp), %rdi
movsd -0x128(%rbp), %xmm0
callq 0x8e860
movq %rax, -0x120(%rbp)
movsd %xmm0, -0x118(%rbp)
movq -0x120(%rbp), %rdi
movsd -0x118(%rbp), %xmm0
callq 0x8ea40
movq -0x10(%rbp), %rax
movq 0x860(%rax), %rax
movq %rax, -0x148(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x9030
movq %rax, %rcx
movq -0x148(%rbp), %rax
subq %rcx, %rax
movq %rax, -0xe0(%rbp)
movslq -0x1c(%rbp), %rcx
cmpq %rcx, %rax
jge 0x9fba7
movq -0xe0(%rbp), %rax
movl %eax, -0x1c(%rbp)
jmp 0x9fba9
cmpl $0x0, -0x1c(%rbp)
jle 0x9fbce
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %esi
callq 0x9af0
movl %eax, -0xe4(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x9b50
cmpl $0x0, %eax
je 0x9fbf1
movq -0x28(%rbp), %rdi
leaq 0x297e6(%rip), %rsi     # 0xc93d0
movb $0x0, %al
callq 0x9150
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movl -0xe4(%rbp), %ecx
movl $0x5, %edi
leaq 0x297ca(%rip), %rsi     # 0xc93d4
movb $0x0, %al
callq 0x95890
movl -0xe4(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopw %cs:(%rax,%rax)