// File: /workspace/github_cpp_makefile_star2_O2/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 0x47b0e
leaq 0x19103(%rip), %rsi     # 0x6c028
pushq $0x3
popq %rdi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4acf2
callq 0x47349
movq %rax, %rdi
callq 0x477da
movq %rax, 0x838(%rbx)
movsd %xmm0, 0x840(%rbx)
callq 0x47c01
movl %eax, 0x85c(%rbx)
movl %eax, 0x858(%rbx)
andq $0x0, 0x860(%rbx)
andl $0x0, 0x868(%rbx)
cmpb $0x0, 0x20(%rbx)
je 0x530bf
leaq 0x420(%rbx), %r12
leaq 0xd65c(%rip), %rcx      # 0x605e5
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movsd -0x30(%rbp), %xmm0
movq %rcx, %r8
callq 0x4b018
movl 0x820(%rbx), %eax
movl %eax, %ecx
andl $0x3, %ecx
cmpl $0x2, %ecx
jne 0x52fbd
movq %r12, %rdi
callq 0x4afcc
movl 0x820(%rbx), %eax
testb $0x1, %al
leaq 0x1907e(%rip), %rax     # 0x6c044
leaq 0x18ede(%rip), %r15     # 0x6beab
cmoveq %rax, %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x8750
movq %rax, (%rbx)
testq %rax, %rax
je 0x530d1
leaq 0x1907a(%rip), %rsi     # 0x6c069
pushq $0x4
popq %rdi
movq %r12, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x4acf2
leaq 0x19081(%rip), %rsi     # 0x6c087
leaq -0x490(%rbp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x8110
cmpl $0x0, 0x824(%rbx)
je 0x53124
leaq -0x490(%rbp), %rdi
movq %r15, %rsi
callq 0x8750
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x5315f
leaq 0x838(%rbx), %r14
leaq 0x19053(%rip), %rsi     # 0x6c0a1
pushq $0x4
popq %rdi
leaq -0x490(%rbp), %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x4acf2
testb $0x1, 0x820(%rbx)
jne 0x5319b
leaq 0x1904d(%rip), %rsi     # 0x6c0c3
leaq 0x198b3(%rip), %rdx     # 0x6c930
leaq -0x80(%rbp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x8110
movl 0x85c(%rbx), %eax
movl %eax, 0x3c(%r15)
movq 0x8(%rbx), %rcx
pushq $0x1
popq %r12
pushq $0x40
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x8c50
movq 0x8(%rbx), %rcx
pushq $0x10
popq %rdx
movq %r14, %rdi
movq %r12, %rsi
callq 0x8c50
jmp 0x5310b
testb $0x1, 0x820(%rbx)
jne 0x530fe
movq 0x32ec9(%rip), %rax     # 0x85f98
jmp 0x53105
leaq 0x18f6f(%rip), %rsi     # 0x6c047
xorl %r15d, %r15d
movq %r14, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x8110
leaq 0x18f6c(%rip), %rsi     # 0x6c05b
pushq $0x1
popq %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x4acf2
jmp 0x5310f
movq 0x32eb3(%rip), %rax     # 0x85fb8
movq (%rax), %rax
movq %rax, (%rbx)
pushq $0x1
popq %r15
movl %r15d, %eax
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %r15
testb $0x2, 0x820(%rbx)
je 0x5310f
leaq 0x18d73(%rip), %rsi     # 0x6beab
leaq -0x490(%rbp), %rdi
callq 0x8750
testq %rax, %rax
je 0x5310f
movq %rax, %rdi
callq 0x8620
leaq -0x490(%rbp), %rdi
callq 0x8b80
jmp 0x5310f
leaq 0x18f28(%rip), %rsi     # 0x6c08e
xorl %r15d, %r15d
leaq -0x490(%rbp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x8110
leaq 0x18eda(%rip), %rsi     # 0x6c05b
pushq $0x1
popq %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x4acf2
movq (%rbx), %rdi
callq 0x8620
jmp 0x5310f
movq 0x8(%rbx), %rcx
leaq -0x80(%rbp), %rdi
pushq $0x40
popq %rsi
pushq $0x1
popq %rdx
callq 0x8920
cmpq $0x1, %rax
jne 0x531e2
movq 0x8(%rbx), %rcx
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x8920
cmpq $0x1, %rax
jne 0x531e2
movl -0x44(%rbp), %eax
movl %eax, 0x85c(%rbx)
movups (%r14), %xmm0
movups %xmm0, 0x848(%rbx)
jmp 0x531e9
andl $0x0, 0x85c(%rbx)
movq 0x838(%rbx), %rdi
movsd 0x840(%rbx), %xmm0
callq 0x47415
jmp 0x5310b