// File: /workspace/github_c_makefile_star2_O0/hcmiya[P]opuscomment/src/retrieve-tags.c
// Function: retrieve_tags
void *retrieve_tags(void *packet_input_) {
	// parse_header_border() からスレッド化された
	FILE *packet_input = packet_input_;
	uint8_t buf[STACK_BUF_LEN];
	
	struct rettag_st *rtn = calloc(1, sizeof(*rtn));
	
	FILE *fptag = rtn->tag = tmpfile();
	rtn->part_of_comment = true;
	uint32_t len;
	rtread(buf, codec->commagic_len, packet_input);
	if (memcmp(buf, codec->commagic, codec->commagic_len) != 0) {
		if (codec->type == CODEC_VP8 && buf[5] != 2) {
			len = codec->commagic_len;
			rtn->part_of_comment = false;
		}
		else opuserror(err_opus_bad_content);
	}
	fwrite(buf, 1, codec->commagic_len, fptag);
	if (!rtn->part_of_comment) {
		// コメントパケットが無かった時用
		if (O.edit == EDIT_LIST) exit(0);
		size_t vendorlen = strlen(new_vendor_string_ascii);
		fwrite((uint32_t[]){oi32(vendorlen)}, 4, 1, fptag);
		fwrite(new_vendor_string_ascii, 1, vendorlen, fptag);
		rtn->tagbegin = codec->commagic_len + vendorlen + 4;
		goto NOTCOMMENT;
	}
	
	// ベンダ文字列
	len = rtchunk(packet_input);
	*(uint32_t*)buf = oi32(len);
	fwrite(buf, 4, 1, fptag);
	check_tagpacket_length(codec->commagic_len + 4);
	while (len) {
		size_t rl = rtfill(buf, len, STACK_BUF_LEN, packet_input);
		fwrite(buf, 1, rl, fptag);
		check_tagpacket_length(rl);
		len -= rl;
	}
	rtn->tagbegin = tagpacket_total;
	
	// レコード数
	size_t recordnum = rtn->del = rtchunk(packet_input);
	fwrite(buf, 4, 1, fptag); // レコード数埋め(後でstore_tags()で書き換え)
	check_tagpacket_length(4);
	bool (*rtcopy)(FILE*, void*);
	int pfd[2];
	pthread_t putth;
	void *wh;
	if (O.edit == EDIT_LIST) {
		// タグ出力をスレッド化 put-tags.c へ
		pipe(pfd);
		FILE *fpput = fdopen(pfd[0], "r");
		pthread_create(&putth, NULL, put_tags, fpput);
		rtcopy = rtcopy_list;
		wh = pfd + 1;
	}
	else if (dellist_str) {
		rtcopy = rtcopy_delete;
		wh = fptag;
		rtcd_src = tmpfile();
	}
	else {
		rtcopy = rtcopy_write;
		wh = fptag;
	}
	
	while (recordnum) {
		rtn->num += rtcopy(packet_input, wh);
		recordnum--;
	}
	rtn->del -= rtn->num;
	
	if (O.edit == EDIT_LIST) {
		// タグ出力スレッド合流
		close(pfd[1]);
		pthread_join(putth, NULL);
		if (codec->type == CODEC_FLAC) return NULL;
		tag_output_close();
		exit(0);
	}
	
	len = fread(buf, 1, 1, packet_input);
	if (len && (codec->prog || (*buf & 1))) {
		// codec->prog ← opuscomment 以外は全部パディングを保存
	NOTCOMMENT: // ←VP8用
		rtn->padding = tmpfile();
		fwrite(buf, 1, len, rtn->padding);
		check_tagpacket_length(len);
		size_t n;
		while ((n = fread(buf, 1, STACK_BUF_LEN, packet_input))) {
			fwrite(buf, 1, n, rtn->padding);
			check_tagpacket_length(n);
		}
	}
	else {
		size_t n;
		while ((n = fread(buf, 1, STACK_BUF_LEN, packet_input))) {}
	}
	
	if (rtcd_src) {
		fclose(rtcd_src);
	}
	if (dellist_str) {
		fclose(dellist_str); fclose(dellist_len);
	}
	fclose(packet_input);
	rtn->upcase = upcase_applied;
	return rtn;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1090, %rsp           # imm = 0x1090
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movl $0x1, %edi
movl $0x30, %esi
callq 0x2250
movq %rax, -0x1028(%rbp)
callq 0x2260
movq -0x1028(%rbp), %rcx
movq %rax, (%rcx)
movq %rax, -0x1030(%rbp)
movq -0x1028(%rbp), %rax
movb $0x1, 0x29(%rax)
leaq -0x1020(%rbp), %rdi
leaq 0x16924(%rip), %rax     # 0x1d6b0
movq (%rax), %rax
movq 0x30(%rax), %rsi
movq -0x18(%rbp), %rdx
callq 0x7310
leaq -0x1020(%rbp), %rdi
leaq 0x16906(%rip), %rax     # 0x1d6b0
movq (%rax), %rax
movq 0x38(%rax), %rsi
leaq 0x168f8(%rip), %rax     # 0x1d6b0
movq (%rax), %rax
movq 0x30(%rax), %rdx
callq 0x2230
cmpl $0x0, %eax
je 0x6e13
leaq 0x168e0(%rip), %rax     # 0x1d6b0
movq (%rax), %rax
cmpl $0x3, (%rax)
jne 0x6e05
movzbl -0x101b(%rbp), %eax
cmpl $0x2, %eax
je 0x6e05
leaq 0x168c5(%rip), %rax     # 0x1d6b0
movq (%rax), %rax
movq 0x30(%rax), %rax
movl %eax, -0x1034(%rbp)
movq -0x1028(%rbp), %rax
movb $0x0, 0x29(%rax)
jmp 0x6e11
movl $0xc, %edi
movb $0x0, %al
callq 0x8690
jmp 0x6e13
leaq -0x1020(%rbp), %rdi
leaq 0x1688f(%rip), %rax     # 0x1d6b0
movq (%rax), %rax
movq 0x30(%rax), %rdx
movq -0x1030(%rbp), %rcx
movl $0x1, %esi
callq 0x2490
movq -0x1028(%rbp), %rax
testb $0x1, 0x29(%rax)
jne 0x6eef
leaq 0x16877(%rip), %rax     # 0x1d6c8
cmpl $0x1, (%rax)
jne 0x6e5d
xorl %edi, %edi
callq 0x2480
leaq 0x5f44(%rip), %rax      # 0xcda8
movq (%rax), %rdi
callq 0x2130
movq %rax, -0x1040(%rbp)
movq -0x1040(%rbp), %rax
movl %eax, %edi
callq 0x84f0
movl %eax, -0x1044(%rbp)
leaq -0x1044(%rbp), %rdi
movq -0x1030(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2490
leaq 0x5efd(%rip), %rax      # 0xcda8
movq (%rax), %rdi
movq -0x1040(%rbp), %rdx
movq -0x1030(%rbp), %rcx
movl $0x1, %esi
callq 0x2490
leaq 0x167e3(%rip), %rax     # 0x1d6b0
movq (%rax), %rax
movq 0x30(%rax), %rcx
addq -0x1040(%rbp), %rcx
addq $0x4, %rcx
movq -0x1028(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x71d3
movq -0x18(%rbp), %rdi
callq 0x7360
movl %eax, -0x1034(%rbp)
movl -0x1034(%rbp), %edi
callq 0x84f0
movl %eax, -0x1020(%rbp)
leaq -0x1020(%rbp), %rdi
movq -0x1030(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2490
leaq 0x1677d(%rip), %rax     # 0x1d6b0
movq (%rax), %rax
movq 0x30(%rax), %rdi
addq $0x4, %rdi
callq 0x6cf0
cmpl $0x0, -0x1034(%rbp)
je 0x6fb3
leaq -0x1020(%rbp), %rdi
movl -0x1034(%rbp), %eax
movl %eax, %esi
movq -0x18(%rbp), %rcx
movl $0x1000, %edx           # imm = 0x1000
callq 0x7390
movq %rax, -0x1050(%rbp)
leaq -0x1020(%rbp), %rdi
movq -0x1050(%rbp), %rdx
movq -0x1030(%rbp), %rcx
movl $0x1, %esi
callq 0x2490
movq -0x1050(%rbp), %rdi
callq 0x6cf0
movq -0x1050(%rbp), %rcx
movl -0x1034(%rbp), %eax
subq %rcx, %rax
movl %eax, -0x1034(%rbp)
jmp 0x6f43
movq 0x166be(%rip), %rcx     # 0x1d678
movq -0x1028(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rdi
callq 0x7360
movl %eax, %eax
movq -0x1028(%rbp), %rcx
movq %rax, 0x20(%rcx)
movq %rax, -0x1058(%rbp)
leaq -0x1020(%rbp), %rdi
movq -0x1030(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2490
movl $0x4, %edi
callq 0x6cf0
leaq 0x166b8(%rip), %rax     # 0x1d6c8
cmpl $0x1, (%rax)
jne 0x707a
leaq -0x1068(%rbp), %rdi
callq 0x2200
movl -0x1068(%rbp), %edi
leaq 0x3051(%rip), %rsi      # 0xa07f
callq 0x2360
movq %rax, -0x1080(%rbp)
movq -0x1080(%rbp), %rcx
leaq -0x1070(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq -0x4903(%rip), %rdx     # 0x2750
callq 0x23b0
leaq 0x391(%rip), %rax       # 0x73f0
movq %rax, -0x1060(%rbp)
leaq -0x1068(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x1078(%rbp)
jmp 0x70cc
cmpq $0x0, 0x165fe(%rip)     # 0x1d680
je 0x70ae
leaq 0x535(%rip), %rax       # 0x75c0
movq %rax, -0x1060(%rbp)
movq -0x1030(%rbp), %rax
movq %rax, -0x1078(%rbp)
callq 0x2260
movq %rax, 0x165dc(%rip)     # 0x1d688
jmp 0x70ca
leaq 0x90b(%rip), %rax       # 0x79c0
movq %rax, -0x1060(%rbp)
movq -0x1030(%rbp), %rax
movq %rax, -0x1078(%rbp)
jmp 0x70cc
jmp 0x70ce
cmpq $0x0, -0x1058(%rbp)
je 0x7116
movq -0x1060(%rbp), %rax
movq -0x18(%rbp), %rdi
movq -0x1078(%rbp), %rsi
callq *%rax
andb $0x1, %al
movzbl %al, %eax
movl %eax, %ecx
movq -0x1028(%rbp), %rax
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movq -0x1058(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x1058(%rbp)
jmp 0x70ce
movq -0x1028(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x1028(%rbp), %rax
movq 0x20(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x20(%rax)
leaq 0x1658e(%rip), %rax     # 0x1d6c8
cmpl $0x1, (%rax)
jne 0x7182
movl -0x1064(%rbp), %edi
callq 0x21e0
movq -0x1070(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x24c0
leaq 0x1654f(%rip), %rax     # 0x1d6b0
movq (%rax), %rax
cmpl $0x2, (%rax)
jne 0x7176
movq $0x0, -0x8(%rbp)
jmp 0x72fd
callq 0x2620
xorl %edi, %edi
callq 0x2480
leaq -0x1020(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x1, %edx
movq %rdx, %rsi
callq 0x20e0
movl %eax, -0x1034(%rbp)
cmpl $0x0, -0x1034(%rbp)
je 0x7271
leaq 0x164fc(%rip), %rax     # 0x1d6b0
movq (%rax), %rax
cmpq $0x0, 0x8(%rax)
jne 0x71d1
movzbl -0x1020(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x7271
jmp 0x71d3
callq 0x2260
movq %rax, %rcx
movq -0x1028(%rbp), %rax
movq %rcx, 0x8(%rax)
leaq -0x1020(%rbp), %rdi
movl -0x1034(%rbp), %eax
movl %eax, %edx
movq -0x1028(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %esi
callq 0x2490
movl -0x1034(%rbp), %eax
movl %eax, %edi
callq 0x6cf0
leaq -0x1020(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x20e0
movq %rax, -0x1088(%rbp)
cmpq $0x0, %rax
je 0x726f
leaq -0x1020(%rbp), %rdi
movq -0x1088(%rbp), %rdx
movq -0x1028(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x1, %esi
callq 0x2490
movq -0x1088(%rbp), %rdi
callq 0x6cf0
jmp 0x7217
jmp 0x729e
jmp 0x7273
leaq -0x1020(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x1, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x20e0
movq %rax, -0x1090(%rbp)
cmpq $0x0, %rax
je 0x729c
jmp 0x7273
jmp 0x729e
cmpq $0x0, 0x163e2(%rip)     # 0x1d688
je 0x72b4
movq 0x163d9(%rip), %rdi     # 0x1d688
callq 0x2120
cmpq $0x0, 0x163c4(%rip)     # 0x1d680
je 0x72d6
movq 0x163bb(%rip), %rdi     # 0x1d680
callq 0x2120
movq 0x163bf(%rip), %rdi     # 0x1d690
callq 0x2120
movq -0x18(%rbp), %rdi
callq 0x2120
movb 0x163b3(%rip), %cl      # 0x1d698
movq -0x1028(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x28(%rax)
movq -0x1028(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x1090, %rsp           # imm = 0x1090
popq %rbp
retq
nopw (%rax,%rax)