// File: /workspace/github_c_makefile_star2_O2/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 $0x1028, %rsp           # imm = 0x1028
movq %rsi, 0x10(%rsp)
movq %rdi, %rbx
movq 0x16a7a(%rip), %rdi     # 0x1c648
callq 0x2150
movq %rbx, %rdi
callq 0x5a19
movl %eax, 0xc(%rsp)
movl %eax, %ebp
leaq 0x20(%rsp), %r14
leaq 0xb(%rsp), %r13
pushq $0x1
popq %r15
testq %rbp, %rbp
je 0x5c52
movb $0x1, 0xb(%rsp)
movl $0x1000, %eax           # imm = 0x1000
cmpq %rax, %rbp
movl $0x1000, %r12d          # imm = 0x1000
cmovbq %rbp, %r12
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x59f5
movq %r14, %rdi
movq %r12, %rsi
pushq $0x1
popq %rdx
movq %r13, %rcx
leaq 0x16a2c(%rip), %r8      # 0x1c658
callq 0x53ec
movq 0x16a10(%rip), %rcx     # 0x1c648
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2460
subq %r12, %rbp
cmpb $0x0, 0xb(%rsp)
jne 0x5bef
jmp 0x5c54
xorl %ebp, %ebp
movl $0x1000, %r13d          # imm = 0x1000
leaq 0x20(%rsp), %r14
pushq $0x1
popq %r15
testq %rbp, %rbp
je 0x5c9d
cmpq %r13, %rbp
movl $0x1000, %r12d          # imm = 0x1000
cmovbq %rbp, %r12
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x59f5
movq 0x169be(%rip), %rcx     # 0x1c648
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2460
subq %r12, %rbp
jmp 0x5c63
movq 0x1699c(%rip), %rdi     # 0x1c640
callq 0x2150
movq 0x169a0(%rip), %rdi     # 0x1c650
callq 0x2150
leaq 0x820(%rsp), %r15
leaq 0x20(%rsp), %r12
pushq $0x1
popq %r13
movq 0x16983(%rip), %rcx     # 0x1c650
movq %r12, %rdi
movq %r13, %rsi
pushq $0x5
popq %rdx
callq 0x20e0
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x5db4
movl 0x20(%rsp), %ebp
movb 0x24(%rsp), %r14b
testb %r14b, %r14b
setne %bl
movq 0x16949(%rip), %rdi     # 0x1c648
callq 0x2150
movl 0xc(%rsp), %ecx
cmpl %ebp, %ecx
seta %al
andb %bl, %al
cmpl %ecx, %ebp
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x5dab
testl %ebp, %ebp
je 0x5d67
movl %ebp, %esi
movq 0x1691c(%rip), %rcx     # 0x1c648
movl $0x800, %edx            # imm = 0x800
movq %r12, %rdi
callq 0x5459
movq %rax, %rbx
movq 0x168fd(%rip), %rcx     # 0x1c640
movq %r15, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x20e0
subl %ebx, %ebp
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2300
testl %eax, %eax
je 0x5d1f
jmp 0x5dab
testb %r14b, %r14b
je 0x5e31
movq 0x168d1(%rip), %rcx     # 0x1c648
movq %r12, %rdi
movq %r13, %rsi
movq %r13, %rdx
callq 0x20e0
xorl %ebp, %ebp
cmpb $0x3d, 0x20(%rsp)
jne 0x5dab
jmp 0x5e31
movl %ebp, %esi
movq 0x168a4(%rip), %rcx     # 0x1c640
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rdi
callq 0x5459
subl %eax, %ebp
testl %ebp, %ebp
jne 0x5d93
jmp 0x5cc6
movq 0x1688d(%rip), %rdi     # 0x1c648
callq 0x2150
movl 0xc(%rsp), %ebp
movl %ebp, %edi
callq 0x651b
leaq 0x20(%rsp), %rbx
movl %eax, (%rbx)
pushq $0x4
popq %r12
pushq $0x1
popq %r15
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq 0x10(%rsp), %r14
movq %r14, %rcx
callq 0x2460
movq %r12, %rdi
callq 0x5600
testl %ebp, %ebp
je 0x5e2b
movl %ebp, %esi
movq 0x16843(%rip), %rcx     # 0x1c648
movl $0x1000, %edx           # imm = 0x1000
movq %rbx, %rdi
callq 0x5459
movq %rax, %r12
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
movq %r14, %rcx
callq 0x2460
subl %r12d, %ebp
jmp 0x5df0
incl 0x646f(%rip)            # 0xc2a0
cmpq $0x0, 0x18(%rsp)
sete %al
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq