// File: /workspace/github_c_makefile_star2_O3/hcmiya[P]opuscomment/src/retrieve-tags.c
// Function: rtcopy_write
static bool rtcopy_write(FILE *packet_input, void *fptag_) {
	FILE *fptag = fptag_;
	uint32_t len = rtchunk(packet_input);
	uint8_t buf[STACK_BUF_LEN];
	bool first = true;
	bool field = true;
	bool copy;
	while (len) {
		size_t rl = rtfill(buf, len, STACK_BUF_LEN, packet_input);
		if (first) {
			first = false;
			
			switch (O.edit) {
			case EDIT_WRITE:
				copy = O.tag_ignore_picture && test_mbp(buf, len);
				break;
			case EDIT_APPEND:
				copy = true;
				break;
			}
			if (copy) {
				uint8_t chunk[4];
				*(uint32_t*)chunk = oi32(len);
				fwrite(chunk, 4, 1, fptag);
				check_tagpacket_length(4);
			}
		}
		if (copy) {
			if (O.tag_toupper && field) {
				for (uint8_t *p = buf, *endp = buf + rl; p < endp; p++) {
					if (*p >= 0x61 && *p <= 0x7a) {
						*p -= 32;
					}
					if (*p == 0x3d) {
						field = false;
						break;
					}
				}
			}
			fwrite(buf, 1, rl, fptag);
			check_tagpacket_length(rl);
		}
		len -= rl;
	}
	return copy;
}

// 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
leaq 0x10(%rsp), %rbx
movl $0x4, %esi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x609d
movl (%rbx), %edi
callq 0x6ce7
testl %eax, %eax
je 0x6733
movl %eax, %ebp
leaq 0x57e0(%rip), %rax      # 0xbd98
movq (%rax), %rbx
movb $0x1, %r15b
movb $0x1, %al
movl %eax, (%rsp)
movl $0x1000, %eax           # imm = 0x1000
cmpl %eax, %ebp
movl $0x1000, %r13d          # imm = 0x1000
cmovbl %ebp, %r13d
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x609d
testb $0x1, %r15b
je 0x669b
leaq 0x16093(%rip), %rax     # 0x1c688
movl (%rax), %eax
cmpl $0x3, %eax
je 0x664d
cmpl $0x2, %eax
jne 0x6652
xorl %r12d, %r12d
cmpl $0x17, %ebp
jb 0x6725
leaq 0x16074(%rip), %rax     # 0x1c688
cmpb $0x0, 0xe(%rax)
je 0x6725
xorl %eax, %eax
movb (%rbx,%rax), %cl
testb %cl, %cl
je 0x664d
movzbl 0x10(%rsp,%rax), %edx
leal -0x61(%rdx), %esi
leal -0x20(%rdx), %edi
cmpb $0x1a, %sil
movzbl %dil, %esi
cmovael %edx, %esi
incq %rax
cmpb %sil, %cl
je 0x6620
xorl %r12d, %r12d
jmp 0x6725
movb $0x1, %r12b
jmp 0x6658
testb $0x1, %r12b
je 0x669b
movl %ebp, %edi
callq 0x6ce7
movl %eax, 0x4(%rsp)
movl $0x4, %esi
movl $0x1, %edx
leaq 0x4(%rsp), %rdi
movq 0x8(%rsp), %rcx
callq 0x2460
movq 0x15fb5(%rip), %rax     # 0x1c638
addq $0x4, %rax
movq %rax, 0x15faa(%rip)     # 0x1c638
cmpq $0x2800001, %rax        # imm = 0x2800001
jb 0x669b
callq 0x7166
testb $0x1, %r12b
je 0x6725
leaq 0x15fdc(%rip), %rax     # 0x1c688
movb 0x16(%rax), %al
andb (%rsp), %al
cmpb $0x1, %al
jne 0x66f0
leaq (%rsp,%r13), %rax
addq $0x10, %rax
leaq 0x10(%rsp), %rcx
movb (%rcx), %dl
leal -0x61(%rdx), %esi
cmpb $0x19, %sil
ja 0x66d5
addb $-0x20, %dl
movb %dl, (%rcx)
jmp 0x66da
cmpb $0x3d, %dl
je 0x66e9
incq %rcx
cmpq %rax, %rcx
jb 0x66c3
movb $0x1, %al
movl %eax, (%rsp)
jmp 0x66f0
movl $0x0, (%rsp)
movl $0x1, %esi
leaq 0x10(%rsp), %rdi
movq %r13, %rdx
movq 0x8(%rsp), %rcx
callq 0x2460
movq 0x15f2a(%rip), %rax     # 0x1c638
addq %r13, %rax
movq %rax, 0x15f20(%rip)     # 0x1c638
cmpq $0x2800001, %rax        # imm = 0x2800001
jb 0x6725
callq 0x7166
xorl %r15d, %r15d
subl %r13d, %ebp
jne 0x65c3
jmp 0x6733
andb $0x1, %r12b
movl %r12d, %eax
addq $0x1018, %rsp           # imm = 0x1018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq