// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x468, %rsp            # imm = 0x468
movq %rdx, %r14
movsd %xmm0, -0x30(%rbp)
movq %rsi, %r15
movq %rdi, %rbx
leaq -0x490(%rbp), %rdi
movl $0x404, %edx            # imm = 0x404
xorl %esi, %esi
callq 0x8390
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movb $0x0, -0x40(%rbp)
leaq 0x20(%rbx), %r13
movq %r15, %rdi
movsd -0x30(%rbp), %xmm0
xorl %esi, %esi
callq 0x5077f
leaq 0x19571(%rip), %rsi     # 0x76063
movl $0x3, %edi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x53ec4
callq 0x4febe
movq %rax, %rdi
callq 0x5040e
movq %rax, 0x838(%rbx)
movsd %xmm0, 0x840(%rbx)
callq 0x5088f
movl %eax, 0x85c(%rbx)
movl %eax, 0x858(%rbx)
movq $0x0, 0x860(%rbx)
movl $0x0, 0x868(%rbx)
cmpb $0x0, 0x20(%rbx)
je 0x5cc99
leaq 0x420(%rbx), %r12
leaq 0xda97(%rip), %rcx      # 0x6a5f5
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movsd -0x30(%rbp), %xmm0
movq %rcx, %r8
callq 0x5422a
movl 0x820(%rbx), %eax
andl $0x3, %eax
cmpl $0x2, %eax
jne 0x5cb8a
movq %r12, %rdi
callq 0x541dc
testb $0x1, 0x820(%rbx)
leaq 0x194e7(%rip), %rax     # 0x7607f
leaq 0x1931c(%rip), %r15     # 0x75ebb
cmoveq %rax, %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x8780
movq %rax, (%rbx)
testq %rax, %rax
je 0x5ccab
leaq 0x194e3(%rip), %rsi     # 0x760a4
movl $0x4, %edi
movq %r12, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x53ec4
leaq 0x194e8(%rip), %rsi     # 0x760c2
leaq -0x490(%rbp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x8120
cmpl $0x0, 0x824(%rbx)
je 0x5cd02
leaq -0x490(%rbp), %rdi
movq %r15, %rsi
callq 0x8780
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x5cd3f
leaq 0x838(%rbx), %r14
leaq 0x194ba(%rip), %rsi     # 0x760dc
leaq -0x490(%rbp), %rdx
movl $0x4, %edi
movq %r15, %rcx
xorl %eax, %eax
callq 0x53ec4
testb $0x1, 0x820(%rbx)
jne 0x5cd7d
leaq 0x194b2(%rip), %rsi     # 0x760fe
leaq 0x19d18(%rip), %rdx     # 0x7696b
leaq -0x80(%rbp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x8120
movl 0x85c(%rbx), %eax
movl %eax, 0x3c(%r15)
movq 0x8(%rbx), %rcx
movl $0x1, %esi
movl $0x40, %edx
movq %r15, %rdi
callq 0x8c40
movq 0x8(%rbx), %rcx
movl $0x1, %esi
movl $0x10, %edx
movq %r14, %rdi
callq 0x8c40
jmp 0x5cce7
testb $0x1, 0x820(%rbx)
jne 0x5ccda
movq 0x312e7(%rip), %rax     # 0x8df90
jmp 0x5cce1
leaq 0x193d0(%rip), %rsi     # 0x76082
xorl %r15d, %r15d
movq %r14, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x8120
leaq 0x193cd(%rip), %rsi     # 0x76096
movl $0x1, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x53ec4
jmp 0x5cced
movq 0x312cf(%rip), %rax     # 0x8dfb0
movq (%rax), %rax
movq %rax, (%rbx)
movl $0x1, %r15d
movl %r15d, %eax
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %r15d
testb $0x2, 0x820(%rbx)
je 0x5cced
leaq 0x191a3(%rip), %rsi     # 0x75ebb
leaq -0x490(%rbp), %rdi
callq 0x8780
testq %rax, %rax
je 0x5cced
movq %rax, %rdi
callq 0x8630
leaq -0x490(%rbp), %rdi
callq 0x8b90
jmp 0x5cced
leaq 0x19383(%rip), %rsi     # 0x760c9
xorl %r15d, %r15d
leaq -0x490(%rbp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x8120
leaq 0x19335(%rip), %rsi     # 0x76096
movl $0x1, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x53ec4
movq (%rbx), %rdi
callq 0x8630
jmp 0x5cced
movq 0x8(%rbx), %rcx
leaq -0x80(%rbp), %rdi
movl $0x40, %esi
movl $0x1, %edx
callq 0x8930
cmpq $0x1, %rax
jne 0x5cdcc
movq 0x8(%rbx), %rcx
movl $0x10, %esi
movl $0x1, %edx
movq %r14, %rdi
callq 0x8930
cmpq $0x1, %rax
jne 0x5cdcc
movl -0x44(%rbp), %eax
movl %eax, 0x85c(%rbx)
movups (%r14), %xmm0
movups %xmm0, 0x848(%rbx)
jmp 0x5cdd6
movl $0x0, 0x85c(%rbx)
movq 0x838(%rbx), %rdi
movsd 0x840(%rbx), %xmm0
callq 0x4ff9c
jmp 0x5cce7