// File: /workspace/github_c_makefile_star2_O1/hcmiya[P]opuscomment/src/read-flac.c
// Function: read_flac
void read_flac(void) {
	size_t readlen = fread(gbuf, 1, 4, stream_input);
	if (readlen == (size_t)-1) oserror();
	if (readlen != 4) {
		opuserror(err_opus_non_flac);
	}
	if (memcmp(gbuf, "\x66\x4C\x61\x43", 4) != 0) { // fLaC
		opuserror(err_opus_non_flac);
	}
	write_buffer(gbuf, 4, built_stream);
	
	bool last_metadata = false;
	size_t metadata_num = 0;
	while (!last_metadata) {
		uint8_t type;
		size_t left;
		last_metadata = get_metadata_header(&type, &left);
		if (type == 0 && metadata_num != 0
			|| type == 0 && left != 34
			|| type == 127
			|| met_comment && type == 4) {
			opuserror(err_opus_bad_content);
		}
		bool delete_header = O.edit == EDIT_LIST;
		if (type == 1) delete_header = true;
		switch (type) {
		case 4:
			if (O.edit == EDIT_LIST && O.tag_escape == TAG_ESCAPE_NUL && met_picture) {
				write_buffer("", 1, tag_output);
			}
			read_comment(left);
			met_comment = true;
			break;
		case 6:
			if (O.edit == EDIT_LIST) {
				if (!O.tag_ignore_picture) {
					read_picture_list(left);
					break;
				}
			}
			else if (O.edit == EDIT_WRITE) {
				delete_header = !O.tag_ignore_picture;
			}
			// FALLTHROUGH
		default:
			if (!delete_header) write_buffer(gbuf, 4, built_stream);
			while (left) {
				size_t readlen = left > gbuflen ? gbuflen : left;
				size_t readret = fread(gbuf, 1, readlen, stream_input);
				if (readlen != readret) oserror();
				if (!delete_header) write_buffer(gbuf, readlen, built_stream);
				left -= readlen;
			}
			break;
		}
		metadata_num++;
	}
	if (O.edit == EDIT_LIST) {
		tag_output_close();
		exit(0);
	}
	if (!met_comment) {
		struct edit_st *est;
		pthread_join(parser_thread, (void **)&est);
		struct rettag_st *rst = NULL;
		if (est->num) {
			rst = calloc(1, sizeof(*rst));
			rst->tag = tmpfile();
			rst->part_of_comment = true;
			size_t vendorlen = strlen(new_vendor_string_ascii);
			fwrite((uint32_t[]){oi32(vendorlen)}, 4, 1, rst->tag);
			fwrite(new_vendor_string_ascii, 1, vendorlen, rst->tag);
			rst->tagbegin = vendorlen + 4;
			fwrite((uint32_t[]){0}, 4, 1, rst->tag);
		}
		store_tags_flac(rst, est);
	}
	write_buffer("\x81\0\0", 4, built_stream); // 「最後のヘッダ」標識を立てたパディングで〆
	
	opst = PAGE_SOUND;
	while (readlen = fread(gbuf, 1, gbuflen, stream_input)) {
		size_t writelen = fwrite(gbuf, 1, readlen, built_stream);
		if (writelen != readlen) oserror();
	}
	if (ferror(stream_input)) oserror();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
leaq 0x1758a(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
leaq 0x74f0(%rip), %rdi      # 0xc630
movl $0x1, %esi
movl $0x4, %edx
callq 0x20e0
cmpq $0x4, %rax
je 0x516c
cmpq $-0x1, %rax
jne 0x5160
callq 0x6f9b
movl $0xf, %edi
xorl %eax, %eax
callq 0x6e10
cmpl $0x43614c66, 0x74ba(%rip) # imm = 0x43614C66
je 0x5184
movl $0xf, %edi
xorl %eax, %eax
callq 0x6e10
leaq 0x17555(%rip), %rax     # 0x1c6e0
movq (%rax), %rcx
leaq 0x749b(%rip), %rdi      # 0xc630
movl $0x1, %esi
movl $0x4, %edx
callq 0x2460
cmpq $0x4, %rax
je 0x51af
callq 0x6f9b
leaq 0x6be2(%rip), %rax      # 0xbd98
movq (%rax), %rax
movq %rax, 0x40(%rsp)
leaq 0x6bdb(%rip), %rax      # 0xbda0
movq (%rax), %rbx
movl $0x10000, %r13d         # imm = 0x10000
leaq 0x745b(%rip), %r12      # 0xc630
xorl %r14d, %r14d
leaq 0x17(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x4f54
movb %al, 0xb(%rsp)
movzbl 0x17(%rsp), %ebp
testl %ebp, %ebp
sete %al
testq %r14, %r14
setne %cl
testb %cl, %al
je 0x535a
movl $0xc, %edi
xorl %eax, %eax
callq 0x6e10
leaq 0x17472(%rip), %rax     # 0x1c688
movl (%rax), %eax
cmpl $0x1, %eax
sete %cl
cmpl $0x1, %ebp
sete %r15b
orb %cl, %r15b
cmpl $0x6, %ebp
movq %r14, 0x38(%rsp)
je 0x5394
cmpl $0x4, %ebp
jne 0x53e4
cmpl $0x1, %eax
jne 0x5285
leaq 0x1743d(%rip), %rax     # 0x1c688
cmpl $0x2, 0x10(%rax)
jne 0x5285
cmpb $0x1, 0x173d9(%rip)     # 0x1c631
jne 0x5285
leaq 0x17487(%rip), %rax     # 0x1c6e8
movq (%rax), %rcx
movl $0x1, %esi
movl $0x1, %edx
leaq 0x3441(%rip), %rdi      # 0x86b6
callq 0x2460
cmpq $0x1, %rax
je 0x5285
callq 0x6f9b
movq 0x28(%rsp), %r15
leaq 0xc(%rsp), %rdi
callq 0x21e0
movl 0xc(%rsp), %edi
leaq 0x2de0(%rip), %rsi      # 0x807f
callq 0x2340
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
leaq 0x926(%rip), %rdx       # 0x5bd8
movq %rax, %rcx
callq 0x2390
testq %r15, %r15
leaq 0x18(%rsp), %rbp
je 0x5309
cmpq %r13, %r15
movl $0x10000, %r14d         # imm = 0x10000
cmovbq %r15, %r14
leaq 0x173e8(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
movl $0x1, %esi
movq %r12, %rdi
movq %r14, %rdx
callq 0x20e0
cmpq %rax, %r14
je 0x52f5
callq 0x6f9b
movl 0x10(%rsp), %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2100
subq %r14, %r15
jne 0x52c4
movl 0x10(%rsp), %edi
callq 0x21c0
movq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x2490
leaq 0x17362(%rip), %rax     # 0x1c688
cmpl $0x1, (%rax)
je 0x534e
leaq 0x173c6(%rip), %rax     # 0x1c6f8
movq (%rax), %rdi
leaq 0x48(%rsp), %rsi
callq 0x2490
movq 0x18(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x4fcd
movb $0x1, 0x172db(%rip)     # 0x1c630
jmp 0x547e
testl %ebp, %ebp
sete %al
cmpq $0x22, 0x28(%rsp)
setne %cl
cmpl $0x7f, %ebp
je 0x5203
andb %cl, %al
jne 0x5203
cmpl $0x4, %ebp
jne 0x520f
testb $0x1, 0x172a7(%rip)     # 0x1c630
jne 0x5203
jmp 0x520f
cmpl $0x1, %eax
jne 0x53d0
leaq 0x172e8(%rip), %rax     # 0x1c688
cmpb $0x0, 0xe(%rax)
jne 0x53e4
movq 0x28(%rsp), %r14
leaq 0x172d6(%rip), %rax     # 0x1c688
cmpb $0x0, 0x15(%rax)
je 0x5499
leaq 0x17325(%rip), %rax     # 0x1c6e8
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x54de
cmpl $0x2, %eax
jne 0x53e4
leaq 0x172ac(%rip), %rax     # 0x1c688
movb 0xe(%rax), %r15b
xorb $0x1, %r15b
testb %r15b, %r15b
jne 0x5410
leaq 0x172f0(%rip), %rax     # 0x1c6e0
movq (%rax), %rcx
movl $0x1, %esi
movl $0x4, %edx
movq %r12, %rdi
callq 0x2460
cmpq $0x4, %rax
je 0x5410
callq 0x6f9b
movq 0x28(%rsp), %rbp
testq %rbp, %rbp
je 0x5479
cmpq %r13, %rbp
movl $0x10000, %r14d         # imm = 0x10000
cmovbq %rbp, %r14
leaq 0x17292(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
movl $0x1, %esi
movq %r12, %rdi
movq %r14, %rdx
callq 0x20e0
cmpq %rax, %r14
je 0x544b
callq 0x6f9b
testb %r15b, %r15b
jne 0x5474
leaq 0x17289(%rip), %rax     # 0x1c6e0
movq (%rax), %rcx
movl $0x1, %esi
movq %r12, %rdi
movq %r14, %rdx
callq 0x2460
cmpq %r14, %rax
je 0x5474
callq 0x6f9b
subq %r14, %rbp
jne 0x541a
movq %rbp, 0x28(%rsp)
movq 0x38(%rsp), %r14
movb 0xb(%rsp), %bpl
incq %r14
testb %bpl, %bpl
je 0x51d8
jmp 0x56c6
leaq 0xc(%rsp), %rdi
callq 0x21e0
movl 0x10(%rsp), %edi
leaq 0x2c2c(%rip), %rsi      # 0x80da
callq 0x2340
movq %rax, 0x20(%rsp)
movl 0xc(%rsp), %edi
leaq 0x2bbc(%rip), %rsi      # 0x807f
callq 0x2340
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
leaq 0x3b1(%rip), %rdx       # 0x5887
movq %rax, %rcx
callq 0x2390
leaq 0x171a3(%rip), %rax     # 0x1c688
cmpl $0x2, 0x10(%rax)
jne 0x5523
cmpb $0x0, 0x1713e(%rip)     # 0x1c630
jne 0x54fd
cmpb $0x1, 0x17136(%rip)     # 0x1c631
jne 0x5523
movl $0x1, %esi
movl $0x1, %edx
leaq 0x31a8(%rip), %rdi      # 0x86b6
movq 0x20(%rsp), %rcx
callq 0x2460
cmpq $0x1, %rax
je 0x5523
callq 0x6f9b
movq 0x40(%rsp), %rbp
movq %rbp, %rdi
callq 0x2130
movq %rax, %r15
movl $0x1, %esi
movq %rbp, %rdi
movq %rax, %rdx
movq 0x20(%rsp), %rcx
callq 0x2460
cmpq %r15, %rax
je 0x5552
callq 0x6f9b
testq %r14, %r14
leaq 0x18(%rsp), %rbp
je 0x5657
movb $0x0, 0x1a(%rsp)
movw $0x0, 0x18(%rsp)
cmpq $0x3, %r14
movl $0x3, %r15d
cmovbq %r14, %r15
leaq 0x1713f(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
movl $0x1, %esi
movq %rbp, %rdi
movq %r15, %rdx
callq 0x20e0
cmpq %r15, %rax
je 0x55bf
leaq 0x17120(%rip), %rax     # 0x1c6c0
movq (%rax), %rdi
callq 0x20c0
testl %eax, %eax
je 0x55b3
callq 0x6f9b
jmp 0x55bf
movl $0xb, %edi
xorl %eax, %eax
callq 0x6e10
movb 0x18(%rsp), %al
movb 0x19(%rsp), %cl
movl %eax, %edx
shrb $0x2, %dl
movb %dl, 0xc(%rsp)
movl %ecx, %edx
shrb $0x4, %dl
shlb $0x4, %al
orb %dl, %al
andb $0x3f, %al
movb %al, 0xd(%rsp)
movb 0x1a(%rsp), %al
movl %eax, %edx
shrb $0x6, %dl
shlb $0x2, %cl
orb %dl, %cl
andb $0x3f, %cl
movb %cl, 0xe(%rsp)
andb $0x3f, %al
movb %al, 0xf(%rsp)
cmpq $0x1, %r15
je 0x5609
cmpq $0x2, %r15
je 0x560e
jmp 0x5613
movb $0x40, 0xe(%rsp)
movb $0x40, 0xf(%rsp)
xorl %eax, %eax
movzbl 0xc(%rsp,%rax), %ecx
movb (%rbx,%rcx), %cl
movb %cl, 0xc(%rsp,%rax)
incq %rax
cmpq $0x4, %rax
jne 0x5615
movl $0x1, %esi
movl $0x4, %edx
leaq 0xc(%rsp), %rdi
movq 0x20(%rsp), %rcx
callq 0x2460
cmpq $0x4, %rax
je 0x564e
callq 0x6f9b
subq %r15, %r14
jne 0x5560
leaq 0x1702a(%rip), %rax     # 0x1c688
cmpl $0x2, 0x10(%rax)
je 0x568d
movb $0xa, 0xc(%rsp)
movl $0x1, %esi
movl $0x1, %edx
leaq 0xc(%rsp), %rdi
movq 0x20(%rsp), %rcx
callq 0x2460
cmpq $0x1, %rax
je 0x568d
callq 0x6f9b
leaq 0x16ff4(%rip), %rax     # 0x1c688
cmpb $0x0, 0x15(%rax)
movq 0x38(%rsp), %r14
movb 0xb(%rsp), %bpl
jne 0x56ba
movq 0x20(%rsp), %rdi
callq 0x2120
movq 0x30(%rsp), %rdi
xorl %esi, %esi
callq 0x2490
movb $0x1, 0x16f70(%rip)     # 0x1c631
jmp 0x5488
leaq 0x16fbb(%rip), %rax     # 0x1c688
cmpl $0x1, (%rax)
je 0x587b
cmpb $0x0, 0x16f53(%rip)     # 0x1c630
jne 0x57a5
leaq 0x1700e(%rip), %rax     # 0x1c6f8
movq (%rax), %rdi
leaq 0x30(%rsp), %rbx
movq %rbx, %rsi
callq 0x2490
movq (%rbx), %rax
cmpq $0x0, 0x18(%rax)
je 0x5796
movl $0x1, %edi
movl $0x30, %esi
callq 0x2220
movq %rax, %rbx
callq 0x2230
movq %rax, (%rbx)
movb $0x1, 0x29(%rbx)
leaq 0x667b(%rip), %rax      # 0xbda8
movq (%rax), %r14
movq %r14, %rdi
callq 0x2130
movq %rax, %r15
movl %r15d, %edi
callq 0x6d2b
leaq 0x54(%rsp), %rdi
movl %eax, (%rdi)
movq (%rbx), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2460
movq (%rbx), %rcx
movl $0x1, %esi
movq %r14, %rdi
movq %r15, %rdx
callq 0x2460
addq $0x4, %r15
movq %r15, 0x10(%rbx)
leaq 0x50(%rsp), %rdi
movl $0x0, (%rdi)
movq (%rbx), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2460
jmp 0x5798
xorl %ebx, %ebx
movq 0x30(%rsp), %rsi
movq %rbx, %rdi
callq 0x4fcd
leaq 0x16f34(%rip), %rax     # 0x1c6e0
movq (%rax), %rcx
leaq 0x2948(%rip), %rdi      # 0x80fe
movl $0x1, %esi
movl $0x4, %edx
callq 0x2460
cmpq $0x4, %rax
je 0x57d0
callq 0x6f9b
leaq 0x16ef5(%rip), %rax     # 0x1c6cc
movl $0x4, (%rax)
leaq 0x16edc(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
leaq 0x6e42(%rip), %rdi      # 0xc630
movl $0x1, %esi
movl $0x10000, %edx          # imm = 0x10000
callq 0x20e0
testq %rax, %rax
je 0x5854
movq %rax, %r14
leaq 0x6e24(%rip), %rbx      # 0xc630
leaq 0x16ecd(%rip), %rax     # 0x1c6e0
movq (%rax), %rcx
movl $0x1, %esi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2460
cmpq %r14, %rax
je 0x5830
callq 0x6f9b
leaq 0x16e89(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
movl $0x1, %esi
movl $0x10000, %edx          # imm = 0x10000
movq %rbx, %rdi
callq 0x20e0
movq %rax, %r14
testq %rax, %rax
jne 0x580c
leaq 0x16e65(%rip), %rax     # 0x1c6c0
movq (%rax), %rdi
callq 0x20c0
testl %eax, %eax
je 0x586c
callq 0x6f9b
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x261c
xorl %edi, %edi
callq 0x2450