// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
leaq 0x1776e(%rip), %rax     # 0x1d700
movq (%rax), %rcx
leaq 0x76d4(%rip), %rdi      # 0xd670
movl $0x1, %esi
movl $0x4, %edx
callq 0x20e0
movq %rax, -0x8(%rbp)
cmpq $-0x1, -0x8(%rbp)
jne 0x5fbb
callq 0x8880
cmpq $0x4, -0x8(%rbp)
je 0x5fce
movl $0xf, %edi
movb $0x0, %al
callq 0x8690
movl 0x769c(%rip), %eax      # 0xd670
subl $0x43614c66, %eax       # imm = 0x43614C66
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x5ff0
movl $0xf, %edi
movb $0x0, %al
callq 0x8690
leaq 0x17729(%rip), %rax     # 0x1d720
movq (%rax), %rdx
leaq 0x766f(%rip), %rdi      # 0xd670
movl $0x4, %esi
callq 0x5f30
movb $0x0, -0x9(%rbp)
movq $0x0, -0x18(%rbp)
movb -0x9(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x6025
jmp 0x6220
leaq -0x19(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x5d60
andb $0x1, %al
movb %al, -0x9(%rbp)
movzbl -0x19(%rbp), %eax
cmpl $0x0, %eax
jne 0x6047
cmpq $0x0, -0x18(%rbp)
jne 0x6072
movzbl -0x19(%rbp), %eax
cmpl $0x0, %eax
jne 0x6057
cmpq $0x22, -0x28(%rbp)
jne 0x6072
movzbl -0x19(%rbp), %eax
cmpl $0x7f, %eax
je 0x6072
testb $0x1, 0x17609(%rip)     # 0x1d670
je 0x607e
movzbl -0x19(%rbp), %eax
cmpl $0x4, %eax
jne 0x607e
movl $0xc, %edi
movb $0x0, %al
callq 0x8690
leaq 0x17643(%rip), %rax     # 0x1d6c8
cmpl $0x1, (%rax)
sete %al
andb $0x1, %al
movb %al, -0x29(%rbp)
movzbl -0x19(%rbp), %eax
cmpl $0x1, %eax
jne 0x609d
movb $0x1, -0x29(%rbp)
movzbl -0x19(%rbp), %eax
movl %eax, -0x6c(%rbp)
subl $0x4, %eax
je 0x60b8
jmp 0x60ab
movl -0x6c(%rbp), %eax
subl $0x6, %eax
je 0x610a
jmp 0x6154
leaq 0x17609(%rip), %rax     # 0x1d6c8
cmpl $0x1, (%rax)
jne 0x60f5
leaq 0x175fd(%rip), %rax     # 0x1d6c8
cmpl $0x2, 0x10(%rax)
jne 0x60f5
testb $0x1, 0x17599(%rip)     # 0x1d671
je 0x60f5
leaq 0x17647(%rip), %rax     # 0x1d728
movq (%rax), %rdx
leaq 0x4647(%rip), %rdi      # 0xa732
movl $0x1, %esi
callq 0x5f30
movq -0x28(%rbp), %rdi
callq 0x63e0
movb $0x1, 0x1756b(%rip)     # 0x1d670
jmp 0x620f
leaq 0x175b7(%rip), %rax     # 0x1d6c8
cmpl $0x1, (%rax)
jne 0x6133
leaq 0x175ab(%rip), %rax     # 0x1d6c8
testb $0x1, 0xe(%rax)
jne 0x6131
movq -0x28(%rbp), %rdi
callq 0x64f0
jmp 0x620f
jmp 0x6152
leaq 0x1758e(%rip), %rax     # 0x1d6c8
cmpl $0x2, (%rax)
jne 0x6150
leaq 0x17582(%rip), %rax     # 0x1d6c8
movb 0xe(%rax), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x29(%rbp)
jmp 0x6152
jmp 0x6154
testb $0x1, -0x29(%rbp)
jne 0x6175
leaq 0x175bf(%rip), %rax     # 0x1d720
movq (%rax), %rdx
leaq 0x7505(%rip), %rdi      # 0xd670
movl $0x4, %esi
callq 0x5f30
jmp 0x6177
cmpq $0x0, -0x28(%rbp)
je 0x620d
cmpq $0x10000, -0x28(%rbp)   # imm = 0x10000
jbe 0x6197
movl $0x10000, %eax          # imm = 0x10000
movq %rax, -0x78(%rbp)
jmp 0x619f
movq -0x28(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdx
leaq 0x1754e(%rip), %rax     # 0x1d700
movq (%rax), %rcx
leaq 0x74b4(%rip), %rdi      # 0xd670
movl $0x1, %esi
callq 0x20e0
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0x61d9
callq 0x8880
testb $0x1, -0x29(%rbp)
jne 0x61f9
movq -0x38(%rbp), %rsi
leaq 0x17536(%rip), %rax     # 0x1d720
movq (%rax), %rdx
leaq 0x747c(%rip), %rdi      # 0xd670
callq 0x5f30
movq -0x38(%rbp), %rcx
movq -0x28(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x28(%rbp)
jmp 0x6177
jmp 0x620f
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x6017
leaq 0x174a1(%rip), %rax     # 0x1d6c8
cmpl $0x1, (%rax)
jne 0x6238
callq 0x2620
xorl %edi, %edi
callq 0x2480
testb $0x1, 0x17431(%rip)     # 0x1d670
jne 0x6331
leaq 0x174ec(%rip), %rax     # 0x1d738
movq (%rax), %rdi
leaq -0x48(%rbp), %rsi
callq 0x24c0
movq $0x0, -0x50(%rbp)
movq -0x48(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x6324
movl $0x1, %edi
movl $0x30, %esi
callq 0x2250
movq %rax, -0x50(%rbp)
callq 0x2260
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, (%rax)
movq -0x50(%rbp), %rax
movb $0x1, 0x29(%rax)
leaq 0x6b08(%rip), %rax      # 0xcda8
movq (%rax), %rdi
callq 0x2130
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl %eax, %edi
callq 0x84f0
movl %eax, -0x5c(%rbp)
leaq -0x5c(%rbp), %rdi
movq -0x50(%rbp), %rax
movq (%rax), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2490
leaq 0x6acd(%rip), %rax      # 0xcda8
movq (%rax), %rdi
movq -0x58(%rbp), %rdx
movq -0x50(%rbp), %rax
movq (%rax), %rcx
movl $0x1, %esi
callq 0x2490
movq -0x58(%rbp), %rcx
addq $0x4, %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x60(%rbp)
leaq -0x60(%rbp), %rdi
movq -0x50(%rbp), %rax
movq (%rax), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2490
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x5e10
leaq 0x173e8(%rip), %rax     # 0x1d720
movq (%rax), %rdx
leaq 0x3dc1(%rip), %rdi      # 0xa103
movl $0x4, %esi
callq 0x5f30
leaq 0x173b9(%rip), %rax     # 0x1d70c
movl $0x4, (%rax)
leaq 0x173a0(%rip), %rax     # 0x1d700
movq (%rax), %rcx
leaq 0x7306(%rip), %rdi      # 0xd670
movl $0x1, %esi
movl $0x10000, %edx          # imm = 0x10000
callq 0x20e0
movq %rax, -0x8(%rbp)
cmpq $0x0, %rax
je 0x63b7
movq -0x8(%rbp), %rdx
leaq 0x17392(%rip), %rax     # 0x1d720
movq (%rax), %rcx
leaq 0x72d8(%rip), %rdi      # 0xd670
movl $0x1, %esi
callq 0x2490
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x8(%rbp), %rax
je 0x63b5
callq 0x8880
jmp 0x6359
leaq 0x17342(%rip), %rax     # 0x1d700
movq (%rax), %rdi
callq 0x20c0
cmpl $0x0, %eax
je 0x63d0
callq 0x8880
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)