// File: /workspace/github_c_makefile_star2_O1/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 0x163a7(%rip), %rdi     # 0x1c648
callq 0x2150
leaq 0x10(%rsp), %r15
movl $0x4, %esi
movq %r15, %rdi
movq %r14, %rdx
callq 0x608e
movl (%r15), %edi
callq 0x6d2b
movl %eax, 0x4(%rsp)
movl %eax, %ebp
leaq 0x16388(%rip), %r12     # 0x1c658
leaq 0x3(%rsp), %r13
testq %rbp, %rbp
je 0x6337
movb $0x1, 0x3(%rsp)
movl $0x1000, %eax           # imm = 0x1000
cmpq %rax, %rbp
movl $0x1000, %ebx           # imm = 0x1000
cmovbq %rbp, %rbx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x608e
movq %r15, %rdi
movq %rbx, %rsi
movl $0x1, %edx
movq %r13, %rcx
movq %r12, %r8
callq 0x5988
movq 0x1632d(%rip), %rcx     # 0x1c648
movl $0x1, %esi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x2460
subq %rbx, %rbp
cmpb $0x0, 0x3(%rsp)
jne 0x62d5
jmp 0x6339
xorl %ebp, %ebp
testq %rbp, %rbp
je 0x637f
movl $0x1000, %r12d          # imm = 0x1000
leaq 0x10(%rsp), %r15
cmpq %r12, %rbp
movl $0x1000, %ebx           # imm = 0x1000
cmovbq %rbp, %rbx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x608e
movq 0x162de(%rip), %rcx     # 0x1c648
movl $0x1, %esi
movq %r15, %rdi
movq %rbx, %rdx
callq 0x2460
subq %rbx, %rbp
jne 0x6349
movq 0x162ba(%rip), %rdi     # 0x1c640
callq 0x2150
movq 0x162be(%rip), %rdi     # 0x1c650
callq 0x2150
leaq 0x810(%rsp), %r15
leaq 0x10(%rsp), %r12
xorl %r14d, %r14d
movq 0x162a2(%rip), %rcx     # 0x1c650
movl $0x1, %esi
movl $0x5, %edx
movq %r12, %rdi
callq 0x20e0
testq %rax, %rax
je 0x64c4
movl 0x10(%rsp), %ebp
movb 0x14(%rsp), %r13b
testb %r13b, %r13b
setne %bl
movq 0x16269(%rip), %rdi     # 0x1c648
callq 0x2150
movl 0x4(%rsp), %ecx
cmpl %ebp, %ecx
seta %al
andb %bl, %al
cmpl %ecx, %ebp
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x648e
movb $0x1, %r14b
testl %ebp, %ebp
je 0x6459
movl %ebp, %esi
movq 0x16239(%rip), %rcx     # 0x1c648
movl $0x800, %edx            # imm = 0x800
movq %r12, %rdi
callq 0x5a09
movq %rax, %rbx
movq 0x1621a(%rip), %rcx     # 0x1c640
movl $0x1, %esi
movq %r15, %rdi
movq %rax, %rdx
callq 0x20e0
subl %ebx, %ebp
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x2300
movzbl %r14b, %r14d
testl %eax, %eax
movl $0x0, %eax
cmovnel %eax, %r14d
je 0x6402
jmp 0x645b
xorl %ebp, %ebp
testb $0x1, %r14b
je 0x648e
movl $0xa, %ebx
testb %r13b, %r13b
je 0x64ae
movq 0x161d6(%rip), %rcx     # 0x1c648
movl $0x1, %esi
movl $0x1, %edx
movq %r12, %rdi
callq 0x20e0
cmpb $0x3d, 0x10(%rsp)
je 0x64ae
xorl %r14d, %r14d
xorl %ebx, %ebx
testl %ebp, %ebp
je 0x64ae
movl %ebp, %esi
movq 0x161a3(%rip), %rcx     # 0x1c640
movl $0x1000, %edx           # imm = 0x1000
movq %r12, %rdi
callq 0x5a09
subl %eax, %ebp
jne 0x6494
testl %ebx, %ebx
je 0x63a7
cmpl $0xa, %ebx
je 0x6576
jmp 0x657a
movq 0x1617d(%rip), %rdi     # 0x1c648
callq 0x2150
movl 0x4(%rsp), %ebp
movl %ebp, %edi
callq 0x6d2b
leaq 0x10(%rsp), %rdi
movl %eax, (%rdi)
movl $0x4, %esi
movl $0x1, %edx
movq 0x8(%rsp), %rbx
movq %rbx, %rcx
callq 0x2460
movq 0x16138(%rip), %rax     # 0x1c638
addq $0x4, %rax
movq %rax, 0x1612d(%rip)     # 0x1c638
cmpq $0x2800001, %rax        # imm = 0x2800001
jb 0x6518
callq 0x71aa
testl %ebp, %ebp
je 0x6570
leaq 0x10(%rsp), %r15
movl %ebp, %esi
movq 0x1611e(%rip), %rcx     # 0x1c648
movl $0x1000, %edx           # imm = 0x1000
movq %r15, %rdi
callq 0x5a09
movq %rax, %r12
movl $0x1, %esi
movq %r15, %rdi
movq %rax, %rdx
movq %rbx, %rcx
callq 0x2460
movq 0x160e4(%rip), %rax     # 0x1c638
addq %r12, %rax
movq %rax, 0x160da(%rip)     # 0x1c638
cmpq $0x2800001, %rax        # imm = 0x2800001
jb 0x656b
callq 0x71aa
subl %r12d, %ebp
jne 0x6521
incl 0x5d2a(%rip)            # 0xc2a0
xorb $0x1, %r14b
andb $0x1, %r14b
movl %r14d, %eax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq