// File: DoubleString[P]RtConverter/src/Rtklib/stream.cpp
// Function: bamboo::writefile(bamboo::file_t*, unsigned char*, int, char*)
static int writefile(file_t *file, unsigned char *buff, int n, char *msg)
	{
		gtime_t wtime;
		unsigned int tick = tickget();
		int week1, week2, ns;
		double tow1, tow2, intv;
		size_t fpos, fpos_tmp;

		tracet(3, "writefile: fp=%d n=%d\n", file->fp, n);

		if (!file) return 0;

		wtime = utc2gpst(timeget()); /* write time in gpst */

		/* swap writing file */
		if (file->swapintv > 0.0&&file->wtime.time != 0) {
			intv = file->swapintv*3600.0;
			tow1 = time2gpst(file->wtime, &week1);
			tow2 = time2gpst(wtime, &week2);
			tow2 += 604800.0*(week2 - week1);

			/* open new swap file */
			if (floor((tow1 + fswapmargin) / intv) < floor((tow2 + fswapmargin) / intv)) {
				swapfile(file, timeadd(wtime, fswapmargin), msg);
			}
			/* close old swap file */
			if (floor((tow1 - fswapmargin) / intv) < floor((tow2 - fswapmargin) / intv)) {
				swapclose(file);
			}
		}
		if (!file->fp) return 0;

		ns = (int)fwrite(buff, 1, n, file->fp);
		fpos = ftell(file->fp);
		fflush(file->fp);
		file->wtime = wtime;

		if (file->fp_tmp) {
			fwrite(buff, 1, n, file->fp_tmp);
			fpos_tmp = ftell(file->fp_tmp);
			fflush(file->fp_tmp);
		}
		if (file->fp_tag) {
			tick -= file->tick;
			fwrite(&tick, 1, sizeof(tick), file->fp_tag);
			fwrite(&fpos, 1, sizeof(fpos), file->fp_tag);
			fflush(file->fp_tag);

			if (file->fp_tag_tmp) {
				fwrite(&tick, 1, sizeof(tick), file->fp_tag_tmp);
				fwrite(&fpos_tmp, 1, sizeof(fpos_tmp), file->fp_tag_tmp);
				fflush(file->fp_tag_tmp);
			}
		}
		tracet(5, "writefile: fp=%d ns=%d tick=%5d fpos=%d\n", file->fp, ns, tick, fpos);

		return ns;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
callq 0x8f860
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movl -0x1c(%rbp), %ecx
movl $0x3, %edi
leaq 0x29246(%rip), %rsi     # 0xc9f5e
movb $0x0, %al
callq 0x95890
cmpq $0x0, -0x10(%rbp)
jne 0xa0d32
movl $0x0, -0x4(%rbp)
jmp 0xa10e3
callq 0x8e920
movq %rax, -0x90(%rbp)
movsd %xmm0, -0x88(%rbp)
movq -0x90(%rbp), %rdi
movsd -0x88(%rbp), %xmm0
callq 0x8f0a0
movq %rax, -0x80(%rbp)
movsd %xmm0, -0x78(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movsd 0x880(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xa0f59
movq -0x10(%rbp), %rax
cmpq $0x0, 0x848(%rax)
je 0xa0f59
movq -0x10(%rbp), %rax
movsd 0x1c066(%rip), %xmm0    # 0xbce10
mulsd 0x880(%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x848(%rax), %rcx
movq %rcx, -0xa0(%rbp)
movq 0x850(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0xa0(%rbp), %rdi
movsd -0x98(%rbp), %xmm0
leaq -0x40(%rbp), %rsi
callq 0x8e540
movsd %xmm0, -0x50(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xb0(%rbp), %rdi
movsd -0xa8(%rbp), %xmm0
leaq -0x44(%rbp), %rsi
callq 0x8e540
movsd %xmm0, -0x58(%rbp)
movl -0x44(%rbp), %eax
subl -0x40(%rbp), %eax
cvtsi2sd %eax, %xmm0
movsd -0x58(%rbp), %xmm1
movsd 0x1cf2a(%rip), %xmm2    # 0xbdd68
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x50(%rbp), %xmm0
cvtsi2sdl 0x58c20(%rip), %xmm1 # 0xf9a78
addsd %xmm1, %xmm0
divsd -0x60(%rbp), %xmm0
callq 0x9c90
movsd %xmm0, -0xd8(%rbp)
movsd -0x58(%rbp), %xmm0
cvtsi2sdl 0x58bfd(%rip), %xmm1 # 0xf9a78
addsd %xmm1, %xmm0
divsd -0x60(%rbp), %xmm0
callq 0x9c90
movsd -0xd8(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xa0f02
movq -0x10(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xc8(%rbp)
cvtsi2sdl 0x58bb8(%rip), %xmm1 # 0xf9a78
movq -0xd0(%rbp), %rdi
movsd -0xc8(%rbp), %xmm0
callq 0x8e860
movq -0xe0(%rbp), %rdi
movq %rax, -0xc0(%rbp)
movsd %xmm0, -0xb8(%rbp)
movq -0x28(%rbp), %rdx
movq -0xc0(%rbp), %rsi
movsd -0xb8(%rbp), %xmm0
callq 0xa8440
movsd -0x50(%rbp), %xmm0
cvtsi2sdl 0x58b69(%rip), %xmm1 # 0xf9a78
subsd %xmm1, %xmm0
divsd -0x60(%rbp), %xmm0
callq 0x9c90
movsd %xmm0, -0xe8(%rbp)
movsd -0x58(%rbp), %xmm0
cvtsi2sdl 0x58b46(%rip), %xmm1 # 0xf9a78
subsd %xmm1, %xmm0
divsd -0x60(%rbp), %xmm0
callq 0x9c90
movsd -0xe8(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xa0f57
movq -0x10(%rbp), %rdi
callq 0xa85b0
jmp 0xa0f59
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0xa0f6f
movl $0x0, -0x4(%rbp)
jmp 0xa10e3
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %esi
callq 0x9e70
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x9030
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x98c0
movq -0x10(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, 0x848(%rax)
movq -0x30(%rbp), %rcx
movq %rcx, 0x850(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0xa1004
movq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movl $0x1, %esi
callq 0x9e70
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x9030
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x98c0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xa10b8
movq -0x10(%rbp), %rax
movl 0x858(%rax), %ecx
movl -0x3c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
leaq -0x3c(%rbp), %rdi
movl $0x1, %esi
movl $0x4, %edx
callq 0x9e70
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
leaq -0x68(%rbp), %rdi
movl $0x1, %esi
movl $0x8, %edx
callq 0x9e70
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x98c0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0xa10b6
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
leaq -0x3c(%rbp), %rdi
movl $0x1, %esi
movl $0x4, %edx
callq 0x9e70
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
leaq -0x70(%rbp), %rdi
movl $0x1, %esi
movl $0x8, %edx
callq 0x9e70
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x98c0
jmp 0xa10b8
movq -0x10(%rbp), %rax
movq (%rax), %rdx
movl -0x48(%rbp), %ecx
movl -0x3c(%rbp), %r8d
movq -0x68(%rbp), %r9
movl $0x5, %edi
leaq 0x28e9f(%rip), %rsi     # 0xc9f75
movb $0x0, %al
callq 0x95890
movl -0x48(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nop