// File: /workspace/github_c_makefile_star2_O3/hcmiya[P]opuscomment/src/retrieve-tags.c
// Function: rtcopy_delete
static bool rtcopy_delete(FILE *packet_input, void *fptag_) {
	static int idx = 1;
	FILE *fptag = fptag_;
	
	// -dの引数と一つずつ比較していくための準備として、レコード1つを一時ファイルrtcd_srcに書き出す
	rewind(rtcd_src);
	uint32_t srclen = rtchunk(packet_input);
	uint8_t buf[STACK_BUF_LEN];
	size_t len = srclen;
	while (len) {
		// フィールド名を大文字化する
		bool field = true;
		size_t rl = rtfill(buf, len, STACK_BUF_LEN, packet_input);
		test_tag_field(buf, rl, true, &field, &upcase_applied);
		fwrite(buf, 1, rl, rtcd_src);
		len -= rl;
		if (!field) break;
	}
	while (len) {
		// フィールド名を抜けた後のループ
		size_t rl = rtfill(buf, len, STACK_BUF_LEN, packet_input);
		fwrite(buf, 1, rl, rtcd_src);
		len -= rl;
	}
	
	// 削除リストのループ
	rewind(dellist_str); rewind(dellist_len);
	bool matched = false;
	while (fread(buf, 1, 5, dellist_len)) {
		uint32_t cmplen = *(uint32_t*)buf;
		bool field_only = buf[4];
		
		size_t const bufhalf = STACK_BUF_LEN / 2;
		uint8_t *cmp = buf + bufhalf;
		rewind(rtcd_src);
		// 比較
		if (field_only && srclen > cmplen || cmplen == srclen) {
			// フィールド名のみ比較でソースが削除指定より長い または
			// 全比較でソースと削除の長さが一致する時
			matched = true;
			while (cmplen) {
				size_t rl = fill_buffer(buf, cmplen, bufhalf, rtcd_src);
				fread(cmp, 1, rl, dellist_str);
				cmplen -= rl;
				if (memcmp(buf, cmp, rl) != 0) {
					matched = false;
					break;
				}
			}
			if (matched) {
				if (field_only) {
					fread(buf, 1, 1, rtcd_src);
					if (*buf == 0x3d) {
						goto MATCHED;
					}
					matched = false;
				}
				else {
					goto MATCHED;
				}
			}
		}
		// 次の削除チャンクに進む
		while (cmplen) {
			cmplen -= fill_buffer(buf, cmplen, STACK_BUF_LEN, dellist_str);
		}
	}
	// 削除するものと一致しなかったらfptagにコピー
	rewind(rtcd_src);
	*(uint32_t*)buf = oi32(srclen);
	fwrite(buf, 4, 1, fptag);
	check_tagpacket_length(4);
	while (srclen) {
		size_t rl = fill_buffer(buf, srclen, STACK_BUF_LEN, rtcd_src);
		fwrite(buf, 1, rl, fptag);
		srclen -= rl;
		check_tagpacket_length(rl);
	}
	idx++;
MATCHED:
	return !matched;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1018, %rsp           # imm = 0x1018
movq %rsi, 0x8(%rsp)
movq %rdi, %r14
movq 0x163ad(%rip), %rdi     # 0x1c648
callq 0x2150
leaq 0x10(%rsp), %r15
movl $0x4, %esi
movq %r15, %rdi
movq %r14, %rdx
callq 0x609d
movl (%r15), %edi
callq 0x6ce7
movl %eax, %ebp
movl %eax, %r12d
leaq 0x7(%rsp), %r13
testq %r12, %r12
je 0x6375
movb $0x1, 0x7(%rsp)
movl $0x1000, %eax           # imm = 0x1000
cmpq %rax, %r12
movl $0x1000, %ebx           # imm = 0x1000
cmovbq %r12, %rbx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x609d
movq %r15, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movq %r13, %rcx
leaq 0x1634f(%rip), %r8      # 0x1c658
callq 0x5978
movq 0x16333(%rip), %rcx     # 0x1c648
movl $0x1, %esi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x2460
subq %rbx, %r12
cmpb $0x0, 0x7(%rsp)
jne 0x62c7
testq %r12, %r12
je 0x6375
movl $0x1000, %r13d          # imm = 0x1000
leaq 0x10(%rsp), %r15
cmpq %r13, %r12
movl $0x1000, %ebx           # imm = 0x1000
cmovbq %r12, %rbx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x609d
movq 0x162e8(%rip), %rcx     # 0x1c648
movl $0x1, %esi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x2460
subq %rbx, %r12
jne 0x633f
movq 0x162c4(%rip), %rdi     # 0x1c640
callq 0x2150
movq 0x162c8(%rip), %rdi     # 0x1c650
callq 0x2150
movq 0x162bc(%rip), %rcx     # 0x1c650
leaq 0x10(%rsp), %rdi
movl $0x1, %esi
movl $0x5, %edx
callq 0x20e0
testq %rax, %rax
je 0x64ac
leaq 0x810(%rsp), %r14
leaq 0x10(%rsp), %r15
movl 0x10(%rsp), %r12d
movb 0x14(%rsp), %r13b
testb %r13b, %r13b
setne %bl
movq 0x16273(%rip), %rdi     # 0x1c648
callq 0x2150
cmpl %r12d, %ebp
seta %al
andb %bl, %al
cmpl %ebp, %r12d
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x643a
testl %r12d, %r12d
je 0x645d
movl %r12d, %esi
movq 0x1624a(%rip), %rcx     # 0x1c648
movl $0x800, %edx            # imm = 0x800
movq %r15, %rdi
callq 0x59f5
movq %rax, %rbx
movq 0x1622b(%rip), %rcx     # 0x1c640
movl $0x1, %esi
movq %r14, %rdi
movq %rax, %rdx
callq 0x20e0
subl %ebx, %r12d
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x2300
testl %eax, %eax
je 0x63ef
testl %r12d, %r12d
je 0x648a
movl %r12d, %esi
movq 0x161f7(%rip), %rcx     # 0x1c640
movl $0x1000, %edx           # imm = 0x1000
movq %r15, %rdi
callq 0x59f5
subl %eax, %r12d
jne 0x643f
jmp 0x648a
testb %r13b, %r13b
je 0x655e
movq 0x161db(%rip), %rcx     # 0x1c648
movl $0x1, %esi
movl $0x1, %edx
movq %r15, %rdi
callq 0x20e0
cmpb $0x3d, 0x10(%rsp)
je 0x655e
movq 0x161bf(%rip), %rcx     # 0x1c650
movl $0x1, %esi
movl $0x5, %edx
movq %r15, %rdi
callq 0x20e0
testq %rax, %rax
jne 0x63be
movq 0x16195(%rip), %rdi     # 0x1c648
callq 0x2150
movl %ebp, %edi
callq 0x6ce7
leaq 0x10(%rsp), %rdi
movl %eax, (%rdi)
movl $0x4, %esi
movl $0x1, %edx
movq 0x8(%rsp), %rbx
movq %rbx, %rcx
callq 0x2460
movq 0x16154(%rip), %rax     # 0x1c638
addq $0x4, %rax
movq %rax, 0x16149(%rip)     # 0x1c638
cmpq $0x2800001, %rax        # imm = 0x2800001
jb 0x64fc
callq 0x7166
testl %ebp, %ebp
je 0x6554
leaq 0x10(%rsp), %r14
movl %ebp, %esi
movq 0x1613a(%rip), %rcx     # 0x1c648
movl $0x1000, %edx           # imm = 0x1000
movq %r14, %rdi
callq 0x59f5
movq %rax, %r15
movl $0x1, %esi
movq %r14, %rdi
movq %rax, %rdx
movq %rbx, %rcx
callq 0x2460
movq 0x16100(%rip), %rax     # 0x1c638
addq %r15, %rax
movq %rax, 0x160f6(%rip)     # 0x1c638
cmpq $0x2800001, %rax        # imm = 0x2800001
jb 0x654f
callq 0x7166
subl %r15d, %ebp
jne 0x6505
incl 0x5d46(%rip)            # 0xc2a0
movb $0x1, %al
jmp 0x6560
xorl %eax, %eax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq