// File: /workspace/github_c_makefile_star2_O3/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 0x1758e(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
leaq 0x74f4(%rip), %rdi      # 0xc630
movl $0x1, %esi
movl $0x4, %edx
callq 0x20e0
cmpq $0x4, %rax
je 0x5168
cmpq $-0x1, %rax
jne 0x515c
callq 0x6f57
movl $0xf, %edi
xorl %eax, %eax
callq 0x6dcc
cmpl $0x43614c66, 0x74be(%rip) # imm = 0x43614C66
je 0x5180
movl $0xf, %edi
xorl %eax, %eax
callq 0x6dcc
leaq 0x17559(%rip), %rax     # 0x1c6e0
movq (%rax), %rcx
leaq 0x749f(%rip), %rdi      # 0xc630
movl $0x1, %esi
movl $0x4, %edx
callq 0x2460
cmpq $0x4, %rax
je 0x51ab
callq 0x6f57
leaq 0x6be6(%rip), %rax      # 0xbd98
movq (%rax), %rax
movq %rax, 0x38(%rsp)
leaq 0x6bdf(%rip), %rax      # 0xbda0
movq (%rax), %rbx
movl $0x10000, %r13d         # imm = 0x10000
leaq 0x745f(%rip), %r12      # 0xc630
xorl %r14d, %r14d
leaq 0x17(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x4f50
movl %eax, %r15d
movzbl 0x17(%rsp), %ebp
testl %ebp, %ebp
sete %al
testq %r14, %r14
setne %cl
testb %cl, %al
je 0x5353
movl $0xc, %edi
xorl %eax, %eax
callq 0x6dcc
leaq 0x17477(%rip), %rax     # 0x1c688
movl (%rax), %edx
cmpl $0x1, %edx
sete %al
cmpl $0x1, %ebp
sete %cl
cmpl $0x6, %ebp
movq %r14, 0x40(%rsp)
movb %r15b, 0x16(%rsp)
je 0x538d
cmpl $0x4, %ebp
jne 0x53e0
cmpl $0x1, %edx
jne 0x5281
leaq 0x17441(%rip), %rax     # 0x1c688
cmpl $0x2, 0x10(%rax)
jne 0x5281
cmpb $0x1, 0x173dd(%rip)     # 0x1c631
jne 0x5281
leaq 0x1748b(%rip), %rax     # 0x1c6e8
movq (%rax), %rcx
movl $0x1, %esi
movl $0x1, %edx
leaq 0x3445(%rip), %rdi      # 0x86b6
callq 0x2460
cmpq $0x1, %rax
je 0x5281
callq 0x6f57
movq 0x30(%rsp), %r15
leaq 0xc(%rsp), %rdi
callq 0x21e0
movl 0xc(%rsp), %edi
leaq 0x2de2(%rip), %rsi      # 0x807d
callq 0x2340
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
leaq 0x91a(%rip), %rdx       # 0x5bc8
movq %rax, %rcx
callq 0x2390
testq %r15, %r15
je 0x5300
cmpq %r13, %r15
movl $0x10000, %r14d         # imm = 0x10000
cmovbq %r15, %r14
leaq 0x173f1(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
movl $0x1, %esi
movq %r12, %rdi
movq %r14, %rdx
callq 0x20e0
cmpq %rax, %r14
je 0x52ec
callq 0x6f57
movl 0x10(%rsp), %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0x2100
subq %r14, %r15
jne 0x52bb
movl 0x10(%rsp), %edi
callq 0x21c0
movq 0x28(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x2490
leaq 0x17369(%rip), %rax     # 0x1c688
cmpl $0x1, (%rax)
je 0x5347
leaq 0x173cd(%rip), %rax     # 0x1c6f8
movq (%rax), %rdi
leaq 0x48(%rsp), %rsi
callq 0x2490
movq 0x18(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x4fc9
movb $0x1, 0x172e2(%rip)     # 0x1c630
jmp 0x547a
testl %ebp, %ebp
sete %al
cmpq $0x22, 0x30(%rsp)
setne %cl
cmpl $0x7f, %ebp
je 0x51fe
andb %cl, %al
jne 0x51fe
cmpl $0x4, %ebp
jne 0x520a
testb $0x1, 0x172ae(%rip)     # 0x1c630
jne 0x51fe
jmp 0x520a
cmpl $0x1, %edx
jne 0x53c9
leaq 0x172ef(%rip), %rdx     # 0x1c688
cmpb $0x0, 0xe(%rdx)
jne 0x53e0
movq 0x30(%rsp), %r14
leaq 0x172dd(%rip), %rax     # 0x1c688
cmpb $0x0, 0x15(%rax)
je 0x5492
leaq 0x1732c(%rip), %rax     # 0x1c6e8
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x54d7
cmpl $0x2, %edx
jne 0x53e0
movb $0x1, %r15b
leaq 0x172b0(%rip), %rax     # 0x1c688
cmpb $0x0, 0xe(%rax)
jne 0x53e7
jmp 0x5411
orb %al, %cl
movb $0x1, %r15b
jne 0x5411
leaq 0x172f2(%rip), %rax     # 0x1c6e0
movq (%rax), %rcx
movl $0x1, %esi
movl $0x4, %edx
movq %r12, %rdi
callq 0x2460
cmpq $0x4, %rax
je 0x540e
callq 0x6f57
xorl %r15d, %r15d
movq 0x30(%rsp), %rbp
testq %rbp, %rbp
je 0x547a
cmpq %r13, %rbp
movl $0x10000, %r14d         # imm = 0x10000
cmovbq %rbp, %r14
leaq 0x17291(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
movl $0x1, %esi
movq %r12, %rdi
movq %r14, %rdx
callq 0x20e0
cmpq %rax, %r14
je 0x544c
callq 0x6f57
testb %r15b, %r15b
jne 0x5475
leaq 0x17288(%rip), %rax     # 0x1c6e0
movq (%rax), %rcx
movl $0x1, %esi
movq %r12, %rdi
movq %r14, %rdx
callq 0x2460
cmpq %r14, %rax
je 0x5475
callq 0x6f57
subq %r14, %rbp
jne 0x541b
movq 0x40(%rsp), %r14
incq %r14
cmpb $0x0, 0x16(%rsp)
je 0x51d4
jmp 0x56b3
leaq 0xc(%rsp), %rdi
callq 0x21e0
movl 0x10(%rsp), %edi
leaq 0x2c31(%rip), %rsi      # 0x80d8
callq 0x2340
movq %rax, 0x20(%rsp)
movl 0xc(%rsp), %edi
leaq 0x2bc1(%rip), %rsi      # 0x807d
callq 0x2340
leaq 0x28(%rsp), %rdi
xorl %esi, %esi
leaq 0x3a8(%rip), %rdx       # 0x5877
movq %rax, %rcx
callq 0x2390
leaq 0x171aa(%rip), %rax     # 0x1c688
cmpl $0x2, 0x10(%rax)
jne 0x551c
cmpb $0x0, 0x17145(%rip)     # 0x1c630
jne 0x54f6
cmpb $0x1, 0x1713d(%rip)     # 0x1c631
jne 0x551c
movl $0x1, %esi
movl $0x1, %edx
leaq 0x31af(%rip), %rdi      # 0x86b6
movq 0x20(%rsp), %rcx
callq 0x2460
cmpq $0x1, %rax
je 0x551c
callq 0x6f57
movq 0x38(%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 0x554b
callq 0x6f57
testq %r14, %r14
leaq 0xc(%rsp), %rbp
je 0x5650
movb $0x0, 0x1a(%rsp)
movw $0x0, 0x18(%rsp)
cmpq $0x3, %r14
movl $0x3, %r15d
cmovbq %r14, %r15
leaq 0x17146(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
movl $0x1, %esi
leaq 0x18(%rsp), %rdi
movq %r15, %rdx
callq 0x20e0
cmpq %r15, %rax
je 0x55ba
leaq 0x17125(%rip), %rax     # 0x1c6c0
movq (%rax), %rdi
callq 0x20c0
testl %eax, %eax
je 0x55ae
callq 0x6f57
jmp 0x55ba
movl $0xb, %edi
xorl %eax, %eax
callq 0x6dcc
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 0x5604
cmpq $0x2, %r15
je 0x5609
jmp 0x560e
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 0x5610
movl $0x1, %esi
movl $0x4, %edx
movq %rbp, %rdi
movq 0x20(%rsp), %rcx
callq 0x2460
cmpq $0x4, %rax
je 0x5647
callq 0x6f57
subq %r15, %r14
jne 0x5559
leaq 0x17031(%rip), %rax     # 0x1c688
cmpl $0x2, 0x10(%rax)
je 0x5684
movb $0xa, 0xc(%rsp)
movl $0x1, %esi
movl $0x1, %edx
movq %rbp, %rdi
movq 0x20(%rsp), %rcx
callq 0x2460
cmpq $0x1, %rax
je 0x5684
callq 0x6f57
leaq 0x16ffd(%rip), %rax     # 0x1c688
cmpb $0x0, 0x15(%rax)
jne 0x56a7
movq 0x20(%rsp), %rdi
callq 0x2120
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x2490
movb $0x1, 0x16f83(%rip)     # 0x1c631
jmp 0x547a
leaq 0x16fce(%rip), %rax     # 0x1c688
cmpl $0x1, (%rax)
je 0x586b
cmpb $0x0, 0x16f66(%rip)     # 0x1c630
jne 0x5795
leaq 0x17021(%rip), %rax     # 0x1c6f8
movq (%rax), %rdi
leaq 0x28(%rsp), %rbx
movq %rbx, %rsi
callq 0x2490
movq (%rbx), %rsi
cmpq $0x0, 0x18(%rsi)
je 0x578b
movl $0x1, %edi
movl $0x30, %esi
callq 0x2220
movq %rax, %rbx
callq 0x2230
movq %rax, %r14
movq %rax, (%rbx)
movb $0x1, 0x29(%rbx)
leaq 0x668b(%rip), %rax      # 0xbda8
movq (%rax), %r15
movq %r15, %rdi
callq 0x2130
movq %rax, %r12
movl %r12d, %edi
callq 0x6ce7
leaq 0x54(%rsp), %rdi
movl %eax, (%rdi)
movl $0x4, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2460
movl $0x1, %esi
movq %r15, %rdi
movq %r12, %rdx
movq %r14, %rcx
callq 0x2460
addq $0x4, %r12
movq %r12, 0x10(%rbx)
leaq 0x50(%rsp), %rdi
movl $0x0, (%rdi)
movl $0x4, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x2460
movq 0x28(%rsp), %rsi
jmp 0x578d
xorl %ebx, %ebx
movq %rbx, %rdi
callq 0x4fc9
leaq 0x16f44(%rip), %rax     # 0x1c6e0
movq (%rax), %rcx
leaq 0x2956(%rip), %rdi      # 0x80fc
movl $0x1, %esi
movl $0x4, %edx
callq 0x2460
cmpq $0x4, %rax
je 0x57c0
callq 0x6f57
leaq 0x16f05(%rip), %rax     # 0x1c6cc
movl $0x4, (%rax)
leaq 0x16eec(%rip), %rax     # 0x1c6c0
movq (%rax), %rcx
leaq 0x6e52(%rip), %rdi      # 0xc630
movl $0x1, %esi
movl $0x10000, %edx          # imm = 0x10000
callq 0x20e0
testq %rax, %rax
je 0x5844
movq %rax, %r14
leaq 0x6e34(%rip), %rbx      # 0xc630
leaq 0x16edd(%rip), %rax     # 0x1c6e0
movq (%rax), %rcx
movl $0x1, %esi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2460
cmpq %r14, %rax
je 0x5820
callq 0x6f57
leaq 0x16e99(%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 0x57fc
leaq 0x16e75(%rip), %rax     # 0x1c6c0
movq (%rax), %rdi
callq 0x20c0
testl %eax, %eax
je 0x585c
callq 0x6f57
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x261c
xorl %edi, %edi
callq 0x2450