// File: /workspace/github_c_makefile_star2_O2/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 0x17a1e(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
leaq 0x7984(%rip), %rdi      # 0xc630
pushq $0x1
popq %rsi
pushq $0x4
popq %rdx
callq 0x20e0
cmpq $0x4, %rax
je 0x4cd2
cmpq $-0x1, %rax
jne 0x4cc8
callq 0x67b6
pushq $0xf
popq %rdi
xorl %eax, %eax
callq 0x6639
cmpl $0x43614c66, 0x7954(%rip) # imm = 0x43614C66
je 0x4ce8
pushq $0xf
popq %rdi
xorl %eax, %eax
callq 0x6639
leaq 0x179f1(%rip), %rax     # 0x1c6e0
movq (%rax), %rdx
leaq 0x7937(%rip), %rbx      # 0xc630
pushq $0x4
popq %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4c6e
leaq 0x7089(%rip), %rax      # 0xbd98
movq (%rax), %rax
movq %rax, 0x38(%rsp)
leaq 0x7082(%rip), %rax      # 0xbda0
movq (%rax), %r15
xorl %eax, %eax
pushq $0x1
popq %rbp
movq $0x0, 0x30(%rsp)
testb $0x1, %al
jne 0x519b
leaq 0xf(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x4b20
movl %eax, %r13d
movzbl 0xf(%rsp), %r14d
testl %r14d, %r14d
sete %al
cmpq $0x0, 0x30(%rsp)
setne %cl
testb %cl, %al
je 0x4e59
pushq $0xc
popq %rdi
xorl %eax, %eax
callq 0x6639
leaq 0x17911(%rip), %rax     # 0x1c688
movl (%rax), %edx
cmpl $0x1, %edx
sete %al
cmpl $0x1, %r14d
sete %cl
cmpl $0x6, %r14d
movq %r13, 0x40(%rsp)
je 0x4ef7
cmpl $0x4, %r14d
jne 0x4f4a
cmpl $0x1, %edx
jne 0x4dd3
leaq 0x178dd(%rip), %rax     # 0x1c688
cmpl $0x2, 0x10(%rax)
jne 0x4dd3
cmpb $0x1, 0x17879(%rip)     # 0x1c631
jne 0x4dd3
leaq 0x17927(%rip), %rax     # 0x1c6e8
movq (%rax), %rdx
leaq 0x38eb(%rip), %rdi      # 0x86b6
movq %rbp, %rsi
callq 0x4c6e
movq 0x28(%rsp), %r13
leaq 0x4(%rsp), %rdi
callq 0x21e0
movl 0x4(%rsp), %edi
leaq 0x3290(%rip), %rsi      # 0x807d
callq 0x2340
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
leaq 0x81c(%rip), %rdx       # 0x561c
movq %rax, %rcx
callq 0x2390
testq %r13, %r13
je 0x4e96
movl $0x10000, %eax          # imm = 0x10000
cmpq %rax, %r13
movl $0x10000, %r14d         # imm = 0x10000
cmovbq %r13, %r14
leaq 0x17896(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x20e0
cmpq %rax, %r14
je 0x4e45
callq 0x67b6
movl 0x8(%rsp), %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x2100
subq %r14, %r13
jmp 0x4e08
testl %r14d, %r14d
sete %al
cmpq $0x22, 0x28(%rsp)
setne %cl
cmpl $0x7f, %r14d
je 0x4d66
andb %cl, %al
jne 0x4d66
cmpl $0x4, %r14d
jne 0x4d70
testb $0x1, 0x177a5(%rip)     # 0x1c630
jne 0x4d66
jmp 0x4d70
movl 0x8(%rsp), %edi
callq 0x21c0
movq 0x20(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2490
leaq 0x177d3(%rip), %rax     # 0x1c688
cmpl $0x1, (%rax)
je 0x4edd
leaq 0x17837(%rip), %rax     # 0x1c6f8
movq (%rax), %rdi
leaq 0x48(%rsp), %rsi
callq 0x2490
movq 0x10(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x4b93
movb $0x1, 0x1774c(%rip)     # 0x1c630
incq 0x30(%rsp)
pushq $0x4
popq %r12
movq 0x40(%rsp), %rax
jmp 0x4d2f
cmpl $0x1, %edx
jne 0x4f33
leaq 0x17785(%rip), %rdx     # 0x1c688
cmpb $0x0, 0xe(%rdx)
jne 0x4f4a
movq 0x28(%rsp), %r14
leaq 0x17773(%rip), %rax     # 0x1c688
cmpb $0x0, 0x15(%rax)
je 0x4fca
leaq 0x177c2(%rip), %rax     # 0x1c6e8
movq (%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x500f
cmpl $0x2, %edx
jne 0x4f4a
movb $0x1, %r13b
leaq 0x17746(%rip), %rax     # 0x1c688
cmpb $0x0, 0xe(%rax)
jne 0x4f51
jmp 0x4f69
orb %al, %cl
movb $0x1, %r13b
jne 0x4f69
leaq 0x17788(%rip), %rax     # 0x1c6e0
movq (%rax), %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4c6e
xorl %r13d, %r13d
movq 0x28(%rsp), %r12
testq %r12, %r12
je 0x4ee4
movl $0x10000, %eax          # imm = 0x10000
cmpq %rax, %r12
movl $0x10000, %r14d         # imm = 0x10000
cmovbq %r12, %r14
leaq 0x17730(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x20e0
cmpq %rax, %r14
je 0x4fab
callq 0x67b6
testb %r13b, %r13b
jne 0x4fc5
leaq 0x17729(%rip), %rax     # 0x1c6e0
movq (%rax), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4c6e
subq %r14, %r12
jmp 0x4f6e
leaq 0x4(%rsp), %rdi
callq 0x21e0
movl 0x8(%rsp), %edi
leaq 0x30f9(%rip), %rsi      # 0x80d8
callq 0x2340
movq %rax, 0x18(%rsp)
movl 0x4(%rsp), %edi
leaq 0x3089(%rip), %rsi      # 0x807d
callq 0x2340
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
leaq 0x316(%rip), %rdx       # 0x531d
movq %rax, %rcx
callq 0x2390
leaq 0x17672(%rip), %rax     # 0x1c688
cmpl $0x2, 0x10(%rax)
jne 0x5042
cmpb $0x0, 0x1760d(%rip)     # 0x1c630
jne 0x502e
cmpb $0x1, 0x17605(%rip)     # 0x1c631
jne 0x5042
leaq 0x3681(%rip), %rdi      # 0x86b6
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
callq 0x4c6e
movq 0x38(%rsp), %r13
movq %r13, %rdi
callq 0x2130
movq %r13, %rdi
movq %rax, %rsi
movq 0x18(%rsp), %rdx
callq 0x4c6e
testq %r14, %r14
je 0x5148
movb $0x0, 0x12(%rsp)
andw $0x0, 0x10(%rsp)
cmpq $0x3, %r14
pushq $0x3
popq %r13
cmovbq %r14, %r13
leaq 0x1763a(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x20e0
cmpq %r13, %rax
je 0x50c2
leaq 0x1761b(%rip), %rax     # 0x1c6c0
movq (%rax), %rdi
callq 0x20c0
testl %eax, %eax
je 0x50b8
callq 0x67b6
jmp 0x50c2
pushq $0xb
popq %rdi
xorl %eax, %eax
callq 0x6639
movb 0x10(%rsp), %al
movb 0x11(%rsp), %cl
movl %eax, %edx
shrb $0x2, %dl
movb %dl, 0x4(%rsp)
movl %ecx, %edx
shrb $0x4, %dl
shlb $0x4, %al
orb %dl, %al
andb $0x3f, %al
movb %al, 0x5(%rsp)
movb 0x12(%rsp), %al
movl %eax, %edx
shrb $0x6, %dl
shlb $0x2, %cl
orb %dl, %cl
andb $0x3f, %cl
movb %cl, 0x6(%rsp)
andb $0x3f, %al
movb %al, 0x7(%rsp)
cmpq $0x2, %r13
je 0x510f
cmpq $0x1, %r13
jne 0x5114
movb $0x40, 0x6(%rsp)
movb $0x40, 0x7(%rsp)
xorl %eax, %eax
cmpq $0x4, %rax
je 0x512e
movzbl 0x4(%rsp,%rax), %ecx
movb (%r15,%rcx), %cl
movb %cl, 0x4(%rsp,%rax)
incq %rax
jmp 0x5116
leaq 0x4(%rsp), %rdi
movq %r12, %rsi
movq 0x18(%rsp), %rdx
callq 0x4c6e
subq %r13, %r14
jmp 0x505f
leaq 0x17539(%rip), %rax     # 0x1c688
cmpl $0x2, 0x10(%rax)
je 0x516c
movb $0xa, 0x4(%rsp)
leaq 0x4(%rsp), %rdi
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
callq 0x4c6e
leaq 0x17515(%rip), %rax     # 0x1c688
cmpb $0x0, 0x15(%rax)
jne 0x518f
movq 0x18(%rsp), %rdi
callq 0x2120
movq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x2490
movb $0x1, 0x1749b(%rip)     # 0x1c631
jmp 0x4ee4
leaq 0x174e6(%rip), %rax     # 0x1c688
cmpl $0x1, (%rax)
je 0x5311
cmpb $0x0, 0x1747e(%rip)     # 0x1c630
jne 0x5273
leaq 0x17539(%rip), %rax     # 0x1c6f8
movq (%rax), %rdi
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x2490
movq (%rbx), %rsi
cmpq $0x0, 0x18(%rsi)
je 0x5269
pushq $0x1
popq %r12
pushq $0x30
popq %rsi
movq %r12, %rdi
callq 0x2220
movq %rax, %rbx
callq 0x2230
movq %rax, %r15
movq %rax, (%rbx)
movb $0x1, 0x29(%rbx)
leaq 0x6ba3(%rip), %rax      # 0xbda8
movq (%rax), %r14
movq %r14, %rdi
callq 0x2130
movq %rax, %r13
movl %r13d, %edi
callq 0x651b
leaq 0x54(%rsp), %rdi
movl %eax, (%rdi)
pushq $0x4
popq %rbp
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x2460
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r15, %rcx
callq 0x2460
addq $0x4, %r13
movq %r13, 0x10(%rbx)
leaq 0x50(%rsp), %rdi
andl $0x0, (%rdi)
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x2460
movq 0x20(%rsp), %rsi
jmp 0x526b
xorl %ebx, %ebx
movq %rbx, %rdi
callq 0x4b93
leaq 0x17466(%rip), %rax     # 0x1c6e0
movq (%rax), %rdx
leaq 0x2e78(%rip), %rdi      # 0x80fc
pushq $0x4
popq %rsi
callq 0x4c6e
leaq 0x17439(%rip), %rax     # 0x1c6cc
movl $0x4, (%rax)
leaq 0x7390(%rip), %rbx      # 0xc630
pushq $0x1
popq %r14
leaq 0x17415(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
movl $0x10000, %edx          # imm = 0x10000
movq %rbx, %rdi
movq %r14, %rsi
callq 0x20e0
testq %rax, %rax
je 0x52ea
movq %rax, %r15
leaq 0x17413(%rip), %rax     # 0x1c6e0
movq (%rax), %rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2460
cmpq %r15, %rax
je 0x52a4
callq 0x67b6
jmp 0x52a4
leaq 0x173cf(%rip), %rax     # 0x1c6c0
movq (%rax), %rdi
callq 0x20c0
testl %eax, %eax
je 0x5302
callq 0x67b6
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x25dc
xorl %edi, %edi
callq 0x2450