// File: /workspace/github_c_makefile_star2_O2/hcmiya[P]opuscomment/src/read.c
// Function: open_output_file
void open_output_file(void) {
	if (O.edit == EDIT_LIST) {
		built_stream = fopen("/dev/null", "w");
		if (!built_stream) {
			fileerror(O.out);
		}
		remove_tmp = false;
		
		tag_output_to_file = O.tag_filename && strcmp(O.tag_filename, "-") != 0;
		if (tag_output_to_file) {
			FILE *tmp = freopen(O.tag_filename, "w", stdout);
			if (!tmp) {
				fileerror(O.tag_filename);
			}
		}
		
		tag_output = O.tag_deferred ? tmpfile() : stdout;
	}
	else if (O.out) {
		if (strcmp(O.out, "-") == 0) {
			built_stream = stdout;
		}
		else {
			built_stream = fopen(O.out, "w");
			if (!built_stream) {
				fileerror(O.out);
			}
		}
		remove_tmp = false;
	}
	else {
		if (input_is_regular_file) {
			char const *tmpl = "opuscomment.XXXXXX";
			outtmp = calloc(strlen(O.in) + strlen(tmpl) + 1, 1);
			char *p = strrchr(O.in, '/');
			if (p) {
				p++;
				strncpy(outtmp, O.in, p - O.in);
				strcpy(outtmp + (p - O.in), tmpl);
			}
			else {
				strcpy(outtmp, tmpl);
			}
			int fd = mkstemp(outtmp);
			if (fd == -1) {
				oserror();
			}
			remove_tmp = true;
			atexit(cleanup);
			built_stream = fdopen(fd, "w+");
		}
		else {
			built_stream = stdout;
		}
	}
	non_opus_stream = tmpfile();
	
	// スレッド間通信で使っているパイプがエラー後のexit内での始末にSIGPIPEを発するのでその対策
	atexit(exit_without_sigpipe);
	switch (O.edit) {
	case EDIT_WRITE:
	case EDIT_APPEND:
		// 編集入力タグパースを別スレッド化 parse_tags.c へ
		pthread_create(&parser_thread, NULL, parse_tags, NULL);
	}
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
leaq 0x184f2(%rip), %r12     # 0x1c688
cmpl $0x1, (%r12)
jne 0x41fc
leaq 0x3f2a(%rip), %rdi      # 0x80ce
leaq 0x3f2d(%rip), %rsi      # 0x80d8
callq 0x23c0
leaq 0x18529(%rip), %rcx     # 0x1c6e0
movq %rax, (%rcx)
testq %rax, %rax
jne 0x41c9
movq 0x30(%r12), %rdi
callq 0x687e
movb $0x0, 0x8408(%rip)      # 0xc5d8
movq 0x18(%r12), %rdi
testq %rdi, %rdi
je 0x4243
cmpb $0x2d, (%rdi)
jne 0x42fc
cmpb $0x0, 0x1(%rdi)
leaq 0x18502(%rip), %rax     # 0x1c6f0
setne (%rax)
jne 0x4306
jmp 0x432b
movq 0x30(%r12), %rdi
testq %rdi, %rdi
je 0x4252
cmpb $0x2d, (%rdi)
jne 0x4215
cmpb $0x0, 0x1(%rdi)
je 0x4363
leaq 0x3ebc(%rip), %rsi      # 0x80d8
callq 0x23c0
leaq 0x184b8(%rip), %rcx     # 0x1c6e0
movq %rax, (%rcx)
testq %rax, %rax
jne 0x4377
movq 0x30(%r12), %rdi
callq 0x687e
jmp 0x4377
leaq 0x184a6(%rip), %rax     # 0x1c6f0
movb $0x0, (%rax)
jmp 0x432b
leaq 0x1846f(%rip), %rax     # 0x1c6c8
cmpb $0x1, (%rax)
jne 0x434d
movq 0x28(%r12), %rbx
movq %rbx, %rdi
callq 0x2130
leaq 0x13(%rax), %rdi
pushq $0x1
popq %rsi
callq 0x2220
movq %rax, %r14
movq %rax, 0x834b(%rip)      # 0xc5d0
pushq $0x2f
popq %rsi
movq %rbx, %rdi
callq 0x2170
movq %rax, %r15
movq %r14, %rax
testq %r15, %r15
je 0x42b4
subq %rbx, %r15
leaq 0x1(%r15), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2070
leaq (%r14,%r15), %rax
incq %rax
movups 0x3e1f(%rip), %xmm0     # 0x80da
movups %xmm0, (%rax)
movl $0x585858, 0xf(%rax)    # imm = 0x585858
movq %r14, %rdi
callq 0x2310
movl %eax, %ebx
cmpl $-0x1, %eax
jne 0x42d9
callq 0x67b6
movb $0x1, 0x82f8(%rip)      # 0xc5d8
leaq 0xe9(%rip), %rdi        # 0x43d0
callq 0x7280
leaq 0x3dfa(%rip), %rsi      # 0x80ed
movl %ebx, %edi
callq 0x2340
jmp 0x4357
leaq 0x183ed(%rip), %rax     # 0x1c6f0
movb $0x1, (%rax)
movq 0x7cb3(%rip), %rax      # 0xbfc0
movq (%rax), %rdx
leaq 0x3dc1(%rip), %rsi      # 0x80d8
callq 0x21a0
testq %rax, %rax
jne 0x432b
movq 0x18(%r12), %rdi
callq 0x687e
cmpb $0x1, 0x20(%r12)
jne 0x433a
callq 0x2230
jmp 0x4344
movq 0x7c7f(%rip), %rax      # 0xbfc0
movq (%rax), %rax
leaq 0x1839d(%rip), %rcx     # 0x1c6e8
jmp 0x435e
movq 0x7c6c(%rip), %rax      # 0xbfc0
movq (%rax), %rax
leaq 0x18382(%rip), %rcx     # 0x1c6e0
movq %rax, (%rcx)
jmp 0x437e
movq 0x7c56(%rip), %rax      # 0xbfc0
movq (%rax), %rax
leaq 0x1836c(%rip), %rcx     # 0x1c6e0
movq %rax, (%rcx)
movb $0x0, 0x825a(%rip)      # 0xc5d8
callq 0x2230
movq %rax, 0x8256(%rip)      # 0xc5e0
leaq 0x55(%rip), %rdi        # 0x43e6
callq 0x7280
movl (%r12), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x43c4
leaq 0x1834f(%rip), %rdi     # 0x1c6f8
leaq -0x1316(%rip), %rdx     # 0x309a
xorl %esi, %esi
xorl %ecx, %ecx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x2390
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq