// File: DoubleString[P]RtConverter/src/Rtklib/stream.cpp
// Function: bamboo::openfile_(bamboo::file_t*, bamboo::gtime_t, char*)
static int openfile_(file_t *file, gtime_t time, char *msg)
	{
		FILE *fp;
		char tagpath[MAXSTRPATH + 4] = "";
		char tagh[TIMETAGH_LEN + 1] = "";
		const char* rw;

		tracet(3, "openfile_: path=%s time=%s\n", file->path, time_str(time, 0));

		file->time = utc2gpst(timeget());
		file->tick = file->tick_f = tickget();
		file->fpos_n = 0;
		file->tick_n = 0;

		/* use stdin or stdout if file path is null */
		if (!*file->path) {
			file->fp = file->mode&STR_MODE_R ? stdin : stdout;
			return 1;
		}
		/* replace keywords */
		reppath(file->path, file->openpath, time, "", "");

		/* create directory */
		if ((file->mode&STR_MODE_W) && !(file->mode&STR_MODE_R)) {
			createdir(file->openpath);
		}
		if (file->mode&STR_MODE_R) rw = "rb"; else rw = "wb";

		if (!(file->fp = fopen(file->openpath, rw))) {
			sprintf(msg, "file open error: %s", file->openpath);
			tracet(1, "openfile: %s\n", msg);
			return 0;
		}
		tracet(4, "openfile_: open file %s (%s)\n", file->openpath, rw);

		sprintf(tagpath, "%s.tag", file->openpath);

		if (file->timetag) { /* output/sync time-tag */

			if (!(file->fp_tag = fopen(tagpath, rw))) {
				sprintf(msg, "tag open error: %s", tagpath);
				tracet(1, "openfile: %s\n", msg);
				fclose(file->fp);
				return 0;
			}
			tracet(4, "openfile_: open tag file %s (%s)\n", tagpath, rw);

			if (file->mode&STR_MODE_R) {
				if (fread(&tagh, TIMETAGH_LEN, 1, file->fp_tag) == 1 &&
					fread(&file->time, sizeof(file->time), 1, file->fp_tag) == 1) {
					memcpy(&file->tick_f, tagh + TIMETAGH_LEN - 4, sizeof(file->tick_f));
					file->wtime = file->time;
				}
				else {
					file->tick_f = 0;
				}
				/* adust time to read playback file */
				timeset(file->time);
			}
			else {
				sprintf(tagh, "TIMETAG RTKLIB %s", VER_RTKLIB);
				memcpy(tagh + TIMETAGH_LEN - 4, &file->tick_f, sizeof(file->tick_f));
				fwrite(&tagh, 1, TIMETAGH_LEN, file->fp_tag);
				fwrite(&file->time, 1, sizeof(file->time), file->fp_tag);
				/* time tag file structure   */
				/*   HEADER(60)+TICK(4)+TIME(12)+ */
				/*   TICK0(4)+FPOS0(4/8)+    */
				/*   TICK1(4)+FPOS1(4/8)+... */
			}
		}
		else if (file->mode&STR_MODE_W) { /* remove time-tag */
			if ((fp = fopen(tagpath, "rb"))) {
				fclose(fp);
				remove(tagpath);
			}
		}
		return 1;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x500, %rsp            # imm = 0x500
movq %rsi, -0x18(%rbp)
movsd %xmm0, -0x10(%rbp)
movq %rdi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
leaq -0x440(%rbp), %rdi
xorl %esi, %esi
movl $0x404, %edx            # imm = 0x404
callq 0x93d0
leaq -0x490(%rbp), %rdi
xorl %esi, %esi
movl $0x41, %edx
callq 0x93d0
movq -0x20(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x4f0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x4a8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x4a0(%rbp)
movq -0x4a8(%rbp), %rdi
movsd -0x4a0(%rbp), %xmm0
xorl %esi, %esi
callq 0x8f6d0
movq -0x4f0(%rbp), %rdx
movq %rax, %rcx
movl $0x3, %edi
leaq 0x25134(%rip), %rsi     # 0xc8db7
movb $0x0, %al
callq 0x95890
callq 0x8e920
movq %rax, -0x4c8(%rbp)
movsd %xmm0, -0x4c0(%rbp)
movq -0x4c8(%rbp), %rdi
movsd -0x4c0(%rbp), %xmm0
callq 0x8f0a0
movq %rax, -0x4b8(%rbp)
movsd %xmm0, -0x4b0(%rbp)
movq -0x20(%rbp), %rax
movq -0x4b8(%rbp), %rcx
movq %rcx, 0x838(%rax)
movq -0x4b0(%rbp), %rcx
movq %rcx, 0x840(%rax)
callq 0x8f860
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x85c(%rax)
movq -0x20(%rbp), %rax
movl %ecx, 0x858(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x860(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x868(%rax)
movq -0x20(%rbp), %rax
cmpb $0x0, 0x20(%rax)
jne 0xa3d73
movq -0x20(%rbp), %rax
movl 0x820(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xa3d48
movq 0x53274(%rip), %rax     # 0xf6fb0
movq (%rax), %rax
movq %rax, -0x4f8(%rbp)
jmp 0xa3d59
movq 0x53241(%rip), %rax     # 0xf6f90
movq (%rax), %rax
movq %rax, -0x4f8(%rbp)
movq -0x4f8(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0xa40fb
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
movq -0x20(%rbp), %rsi
addq $0x420, %rsi            # imm = 0x420
movq -0x18(%rbp), %rax
movq %rax, -0x4d8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x4d0(%rbp)
movq -0x4d8(%rbp), %rdx
movsd -0x4d0(%rbp), %xmm0
leaq 0x18f55(%rip), %r8      # 0xbcd07
movq %r8, %rcx
callq 0x95e20
movq -0x20(%rbp), %rax
movl 0x820(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xa3dee
movq -0x20(%rbp), %rax
movl 0x820(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xa3dee
movq -0x20(%rbp), %rdi
addq $0x420, %rdi            # imm = 0x420
callq 0x95da0
movq -0x20(%rbp), %rax
movl 0x820(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xa3e10
leaq 0x24e04(%rip), %rax     # 0xc8c0b
movq %rax, -0x498(%rbp)
jmp 0xa3e1e
leaq 0x24fbc(%rip), %rax     # 0xc8dd3
movq %rax, -0x498(%rbp)
movq -0x20(%rbp), %rdi
addq $0x420, %rdi            # imm = 0x420
movq -0x498(%rbp), %rsi
callq 0x98d0
movq -0x20(%rbp), %rcx
movq %rax, (%rcx)
cmpq $0x0, %rax
jne 0xa3e82
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rdx
addq $0x420, %rdx            # imm = 0x420
leaq 0x24f7e(%rip), %rsi     # 0xc8dd6
movb $0x0, %al
callq 0x9150
movq -0x28(%rbp), %rdx
movl $0x1, %edi
leaq 0x24f7b(%rip), %rsi     # 0xc8dea
movb $0x0, %al
callq 0x95890
movl $0x0, -0x4(%rbp)
jmp 0xa40fb
movq -0x20(%rbp), %rdx
addq $0x420, %rdx            # imm = 0x420
movq -0x498(%rbp), %rcx
movl $0x4, %edi
leaq 0x24f58(%rip), %rsi     # 0xc8df8
movb $0x0, %al
callq 0x95890
leaq -0x440(%rbp), %rdi
movq -0x20(%rbp), %rdx
addq $0x420, %rdx            # imm = 0x420
leaq 0x24f56(%rip), %rsi     # 0xc8e16
movb $0x0, %al
callq 0x9150
movq -0x20(%rbp), %rax
cmpl $0x0, 0x824(%rax)
je 0xa40ac
leaq -0x440(%rbp), %rdi
movq -0x498(%rbp), %rsi
callq 0x98d0
movq -0x20(%rbp), %rcx
movq %rax, 0x8(%rcx)
cmpq $0x0, %rax
jne 0xa3f41
movq -0x28(%rbp), %rdi
leaq -0x440(%rbp), %rdx
leaq 0x24f12(%rip), %rsi     # 0xc8e1d
movb $0x0, %al
callq 0x9150
movq -0x28(%rbp), %rdx
movl $0x1, %edi
leaq 0x24ec8(%rip), %rsi     # 0xc8dea
movb $0x0, %al
callq 0x95890
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x9770
movl $0x0, -0x4(%rbp)
jmp 0xa40fb
leaq -0x440(%rbp), %rdx
movq -0x498(%rbp), %rcx
movl $0x4, %edi
leaq 0x24ed5(%rip), %rsi     # 0xc8e30
movb $0x0, %al
callq 0x95890
movq -0x20(%rbp), %rax
movl 0x820(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xa403e
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
leaq -0x490(%rbp), %rdi
movl $0x40, %esi
movl $0x1, %edx
callq 0x9af0
cmpq $0x1, %rax
jne 0xa3ffa
movq -0x20(%rbp), %rdi
addq $0x838, %rdi            # imm = 0x838
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x10, %esi
movl $0x1, %edx
callq 0x9af0
cmpq $0x1, %rax
jne 0xa3ffa
movq -0x20(%rbp), %rax
movl -0x454(%rbp), %ecx
movl %ecx, 0x85c(%rax)
movq -0x20(%rbp), %rcx
movq -0x20(%rbp), %rax
movq 0x838(%rcx), %rdx
movq %rdx, 0x848(%rax)
movq 0x840(%rcx), %rcx
movq %rcx, 0x850(%rax)
jmp 0xa4008
movq -0x20(%rbp), %rax
movl $0x0, 0x85c(%rax)
movq -0x20(%rbp), %rax
movq 0x838(%rax), %rcx
movq %rcx, -0x4e8(%rbp)
movq 0x840(%rax), %rax
movq %rax, -0x4e0(%rbp)
movq -0x4e8(%rbp), %rdi
movsd -0x4e0(%rbp), %xmm0
callq 0x8ea40
jmp 0xa40aa
leaq -0x490(%rbp), %rdi
leaq 0x24e06(%rip), %rsi     # 0xc8e52
leaq 0x25678(%rip), %rdx     # 0xc96cb
movb $0x0, %al
callq 0x9150
movq -0x20(%rbp), %rax
movl 0x85c(%rax), %eax
movl %eax, -0x454(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
leaq -0x490(%rbp), %rdi
movl $0x1, %esi
movl $0x40, %edx
callq 0x9e70
movq -0x20(%rbp), %rdi
addq $0x838, %rdi            # imm = 0x838
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %esi
movl $0x10, %edx
callq 0x9e70
jmp 0xa40f4
movq -0x20(%rbp), %rax
movl 0x820(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xa40f2
leaq -0x440(%rbp), %rdi
leaq 0x24b3f(%rip), %rsi     # 0xc8c0b
callq 0x98d0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0xa40f0
movq -0x30(%rbp), %rdi
callq 0x9770
leaq -0x440(%rbp), %rdi
callq 0x9d90
jmp 0xa40f2
jmp 0xa40f4
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x500, %rsp            # imm = 0x500
popq %rbp
retq
nopw (%rax,%rax)