// File: /workspace/github_c_makefile_star2_O3/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 0x18147(%rip), %r12     # 0x1c688
cmpl $0x1, (%r12)
jne 0x45a7
leaq 0x3b7f(%rip), %rdi      # 0x80ce
leaq 0x3b82(%rip), %rsi      # 0x80d8
callq 0x23c0
leaq 0x1817e(%rip), %rcx     # 0x1c6e0
movq %rax, (%rcx)
testq %rax, %rax
jne 0x4574
movq 0x30(%r12), %rdi
callq 0x7025
movb $0x0, 0x805d(%rip)      # 0xc5d8
movq 0x18(%r12), %rdi
testq %rdi, %rdi
je 0x45ee
cmpb $0x2d, (%rdi)
jne 0x46ab
cmpb $0x0, 0x1(%rdi)
leaq 0x18157(%rip), %rax     # 0x1c6f0
setne (%rax)
jne 0x46b5
jmp 0x46da
movq 0x30(%r12), %rdi
testq %rdi, %rdi
je 0x45fd
cmpb $0x2d, (%rdi)
jne 0x45c0
cmpb $0x0, 0x1(%rdi)
je 0x4712
leaq 0x3b11(%rip), %rsi      # 0x80d8
callq 0x23c0
leaq 0x1810d(%rip), %rcx     # 0x1c6e0
movq %rax, (%rcx)
testq %rax, %rax
jne 0x4726
movq 0x30(%r12), %rdi
callq 0x7025
jmp 0x4726
leaq 0x180fb(%rip), %rax     # 0x1c6f0
movb $0x0, (%rax)
jmp 0x46da
leaq 0x180c4(%rip), %rax     # 0x1c6c8
cmpb $0x1, (%rax)
jne 0x46fc
movq 0x28(%r12), %rbx
movq %rbx, %rdi
callq 0x2130
leaq 0x13(%rax), %rdi
movl $0x1, %esi
callq 0x2220
movq %rax, %r14
movq %rax, 0x7f9e(%rip)      # 0xc5d0
movq %rbx, %rdi
movl $0x2f, %esi
callq 0x2170
movq %rax, %r15
movq %r14, %rax
testq %r15, %r15
je 0x4663
subq %rbx, %r15
leaq 0x1(%r15), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2070
leaq (%r14,%r15), %rax
incq %rax
movups 0x3a70(%rip), %xmm0     # 0x80da
movups %xmm0, (%rax)
movl $0x585858, 0xf(%rax)    # imm = 0x585858
movq %r14, %rdi
callq 0x2310
movl %eax, %ebx
cmpl $-0x1, %eax
jne 0x4688
callq 0x6f57
movb $0x1, 0x7f49(%rip)      # 0xc5d8
leaq 0xe9(%rip), %rdi        # 0x477f
callq 0x7b90
leaq 0x3a4b(%rip), %rsi      # 0x80ed
movl %ebx, %edi
callq 0x2340
jmp 0x4706
leaq 0x1803e(%rip), %rax     # 0x1c6f0
movb $0x1, (%rax)
movq 0x7904(%rip), %rax      # 0xbfc0
movq (%rax), %rdx
leaq 0x3a12(%rip), %rsi      # 0x80d8
callq 0x21a0
testq %rax, %rax
jne 0x46da
movq 0x18(%r12), %rdi
callq 0x7025
cmpb $0x1, 0x20(%r12)
jne 0x46e9
callq 0x2230
jmp 0x46f3
movq 0x78d0(%rip), %rax      # 0xbfc0
movq (%rax), %rax
leaq 0x17fee(%rip), %rcx     # 0x1c6e8
jmp 0x470d
movq 0x78bd(%rip), %rax      # 0xbfc0
movq (%rax), %rax
leaq 0x17fd3(%rip), %rcx     # 0x1c6e0
movq %rax, (%rcx)
jmp 0x472d
movq 0x78a7(%rip), %rax      # 0xbfc0
movq (%rax), %rax
leaq 0x17fbd(%rip), %rcx     # 0x1c6e0
movq %rax, (%rcx)
movb $0x0, 0x7eab(%rip)      # 0xc5d8
callq 0x2230
movq %rax, 0x7ea7(%rip)      # 0xc5e0
leaq 0x55(%rip), %rdi        # 0x4795
callq 0x7b90
movl (%r12), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x4773
leaq 0x17fa0(%rip), %rdi     # 0x1c6f8
leaq -0x147a(%rip), %rdx     # 0x32e5
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