// File: /workspace/github_c_makefile_star2_O1/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 0x1814a(%rip), %r12     # 0x1c688
cmpl $0x1, (%r12)
jne 0x45d5
leaq 0x3b80(%rip), %rdi      # 0x80d0
leaq 0x3b83(%rip), %rsi      # 0x80da
callq 0x23c0
leaq 0x1817d(%rip), %rcx     # 0x1c6e0
movq %rax, (%rcx)
testq %rax, %rax
jne 0x4575
movq 0x30(%r12), %rdi
callq 0x7069
movb $0x0, 0x805c(%rip)      # 0xc5d8
movq 0x18(%r12), %rbx
testq %rbx, %rbx
je 0x4627
leaq 0x3aae(%rip), %rsi      # 0x803f
movq %rbx, %rdi
callq 0x2240
leaq 0x18150(%rip), %rcx     # 0x1c6f0
testl %eax, %eax
setne (%rcx)
je 0x4631
movq 0x7a0e(%rip), %rax      # 0xbfc0
movq (%rax), %rdx
leaq 0x3b1e(%rip), %rsi      # 0x80da
movq %rbx, %rdi
callq 0x21a0
testq %rax, %rax
jne 0x4631
movq 0x18(%r12), %rdi
callq 0x7069
jmp 0x4631
movq 0x30(%r12), %rbx
testq %rbx, %rbx
je 0x4656
leaq 0x3a59(%rip), %rsi      # 0x803f
movq %rbx, %rdi
callq 0x2240
testl %eax, %eax
je 0x4704
leaq 0x3add(%rip), %rsi      # 0x80da
movq %rbx, %rdi
callq 0x23c0
leaq 0x180d4(%rip), %rcx     # 0x1c6e0
movq %rax, (%rcx)
testq %rax, %rax
jne 0x4718
movq 0x30(%r12), %rdi
callq 0x7069
jmp 0x4718
leaq 0x180c2(%rip), %rax     # 0x1c6f0
movb $0x0, (%rax)
cmpb $0x1, 0x20(%r12)
jne 0x4640
callq 0x2230
jmp 0x464a
movq 0x7979(%rip), %rax      # 0xbfc0
movq (%rax), %rax
leaq 0x18097(%rip), %rcx     # 0x1c6e8
jmp 0x4732
leaq 0x1806b(%rip), %rax     # 0x1c6c8
cmpb $0x1, (%rax)
jne 0x4721
movq 0x28(%r12), %rbx
movq %rbx, %rdi
callq 0x2130
leaq 0x13(%rax), %rdi
movl $0x1, %esi
callq 0x2220
movq %rax, %r14
movq %rax, 0x7f45(%rip)      # 0xc5d0
movq %rbx, %rdi
movl $0x2f, %esi
callq 0x2170
movq %rax, %r15
movq %r14, %rax
testq %r15, %r15
je 0x46bc
subq %rbx, %r15
leaq 0x1(%r15), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2070
leaq (%r14,%r15), %rax
incq %rax
movups 0x3a19(%rip), %xmm0     # 0x80dc
movups %xmm0, (%rax)
movl $0x585858, 0xf(%rax)    # imm = 0x585858
movq %r14, %rdi
callq 0x2310
movl %eax, %ebx
cmpl $-0x1, %eax
jne 0x46e1
callq 0x6f9b
movb $0x1, 0x7ef0(%rip)      # 0xc5d8
leaq 0x98(%rip), %rdi        # 0x4787
callq 0x7ba0
leaq 0x39f4(%rip), %rsi      # 0x80ef
movl %ebx, %edi
callq 0x2340
jmp 0x472b
movq 0x78b5(%rip), %rax      # 0xbfc0
movq (%rax), %rax
leaq 0x17fcb(%rip), %rcx     # 0x1c6e0
movq %rax, (%rcx)
movb $0x0, 0x7eb9(%rip)      # 0xc5d8
jmp 0x4735
movq 0x7898(%rip), %rax      # 0xbfc0
movq (%rax), %rax
leaq 0x17fae(%rip), %rcx     # 0x1c6e0
movq %rax, (%rcx)
callq 0x2230
movq %rax, 0x7e9f(%rip)      # 0xc5e0
leaq 0x55(%rip), %rdi        # 0x479d
callq 0x7ba0
movl (%r12), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x477b
leaq 0x17f98(%rip), %rdi     # 0x1c6f8
leaq -0x147d(%rip), %rdx     # 0x32ea
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