// File: /workspace/github_cpp_makefile_star2_O3/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 0x4fdbe
leaq 0x1a034(%rip), %rsi     # 0x75fe8
movl $0x3, %edi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x5342c
callq 0x4f542
movq %rax, %rdi
callq 0x4fa70
movq %rax, 0x838(%rbx)
movsd %xmm0, 0x840(%rbx)
callq 0x4fece
movl %eax, 0x85c(%rbx)
movl %eax, 0x858(%rbx)
movq $0x0, 0x860(%rbx)
movl $0x0, 0x868(%rbx)
cmpb $0x0, 0x20(%rbx)
je 0x5c15e
leaq 0x420(%rbx), %r12
leaq 0xe5d5(%rip), %rcx      # 0x6a5f5
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movsd -0x30(%rbp), %xmm0
movq %rcx, %r8
callq 0x5379e
movl 0x820(%rbx), %eax
movl %eax, %ecx
andl $0x3, %ecx
cmpl $0x2, %ecx
jne 0x5c054
movq %r12, %rdi
callq 0x53750
movl 0x820(%rbx), %eax
testb $0x1, %al
leaq 0x19fa7(%rip), %rax     # 0x76004
leaq 0x19e07(%rip), %r15     # 0x75e6b
cmoveq %rax, %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x8770
movq %rax, (%rbx)
testq %rax, %rax
je 0x5c170
leaq 0x19fa3(%rip), %rsi     # 0x76029
movl $0x4, %edi
movq %r12, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x5342c
leaq 0x19fa8(%rip), %rsi     # 0x76047
leaq -0x490(%rbp), %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x8120
cmpl $0x0, 0x824(%rbx)
je 0x5c1c7
leaq -0x490(%rbp), %rdi
movq %r15, %rsi
callq 0x8770
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x5c204
leaq 0x838(%rbx), %r14
leaq 0x19f7a(%rip), %rsi     # 0x76061
leaq -0x490(%rbp), %rdx
movl $0x4, %edi
movq %r15, %rcx
xorl %eax, %eax
callq 0x5342c
testb $0x1, 0x820(%rbx)
jne 0x5c242
leaq 0x19f72(%rip), %rsi     # 0x76083
leaq 0x1a7d8(%rip), %rdx     # 0x768f0
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 0x8c30
movq 0x8(%rbx), %rcx
movl $0x1, %esi
movl $0x10, %edx
movq %r14, %rdi
callq 0x8c30
jmp 0x5c1ac
testb $0x1, 0x820(%rbx)
jne 0x5c19f
movq 0x31e2a(%rip), %rax     # 0x8df98
jmp 0x5c1a6
leaq 0x19e90(%rip), %rsi     # 0x76007
xorl %r15d, %r15d
movq %r14, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x8120
leaq 0x19e8d(%rip), %rsi     # 0x7601b
movl $0x1, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x5342c
jmp 0x5c1b2
movq 0x31e12(%rip), %rax     # 0x8dfb8
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 0x5c1b2
leaq 0x19c8e(%rip), %rsi     # 0x75e6b
leaq -0x490(%rbp), %rdi
callq 0x8770
testq %rax, %rax
je 0x5c1b2
movq %rax, %rdi
callq 0x8630
leaq -0x490(%rbp), %rdi
callq 0x8b80
jmp 0x5c1b2
leaq 0x19e43(%rip), %rsi     # 0x7604e
xorl %r15d, %r15d
leaq -0x490(%rbp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x8120
leaq 0x19df5(%rip), %rsi     # 0x7601b
movl $0x1, %edi
movq %r14, %rdx
xorl %eax, %eax
callq 0x5342c
movq (%rbx), %rdi
callq 0x8630
jmp 0x5c1b2
movq 0x8(%rbx), %rcx
leaq -0x80(%rbp), %rdi
movl $0x40, %esi
movl $0x1, %edx
callq 0x8920
cmpq $0x1, %rax
jne 0x5c291
movq 0x8(%rbx), %rcx
movl $0x10, %esi
movl $0x1, %edx
movq %r14, %rdi
callq 0x8920
cmpq $0x1, %rax
jne 0x5c291
movl -0x44(%rbp), %eax
movl %eax, 0x85c(%rbx)
movups (%r14), %xmm0
movups %xmm0, 0x848(%rbx)
jmp 0x5c29b
movl $0x0, 0x85c(%rbx)
movq 0x838(%rbx), %rdi
movsd 0x840(%rbx), %xmm0
callq 0x4f620
jmp 0x5c1ac