// File: /workspace/github_c_makefile_star2_O1/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 $0x1028, %rsp           # imm = 0x1028
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
leaq 0x20(%rsp), %r15
movl $0x4, %esi
movq %r15, %rdi
movq %r14, %rdx
callq 0x608e
movl (%r15), %edi
callq 0x6d2b
testl %eax, %eax
je 0x6755
movl %eax, %ebp
leaq 0x57be(%rip), %rax      # 0xbd98
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movb $0x1, %bl
movb $0x1, %al
movl %eax, 0x8(%rsp)
movl $0x1000, %eax           # imm = 0x1000
cmpl %eax, %ebp
movl $0x1000, %r13d          # imm = 0x1000
cmovbl %ebp, %r13d
movq %r15, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x608e
testb $0x1, %bl
je 0x66cb
leaq 0x1606f(%rip), %rax     # 0x1c688
movl (%rax), %eax
cmpl $0x3, %eax
je 0x667d
cmpl $0x2, %eax
jne 0x6680
xorl %r12d, %r12d
cmpl $0x17, %ebp
jb 0x6680
leaq 0x16054(%rip), %rax     # 0x1c688
cmpb $0x0, 0xe(%rax)
je 0x6680
movq 0x18(%rsp), %rax
movq %r15, %rcx
movb (%rax), %dl
testb %dl, %dl
je 0x6674
movzbl (%rcx), %esi
incq %rcx
leal -0x61(%rsi), %edi
leal -0x20(%rsi), %r8d
cmpb $0x1a, %dil
movzbl %r8b, %edi
cmovael %esi, %edi
incq %rax
cmpb %dil, %dl
je 0x6642
sete %cl
movzbl %cl, %ecx
addq %rcx, %rax
decq %rax
cmpb $0x0, (%rax)
sete %r12b
jmp 0x6680
movb $0x1, %r12b
testb $0x1, %r12b
je 0x66c9
movl %ebp, %edi
callq 0x6d2b
movl %eax, 0xc(%rsp)
movl $0x4, %esi
movl $0x1, %edx
leaq 0xc(%rsp), %rdi
movq 0x10(%rsp), %rcx
callq 0x2460
movq 0x15f87(%rip), %rax     # 0x1c638
addq $0x4, %rax
movq %rax, 0x15f7c(%rip)     # 0x1c638
cmpq $0x2800001, %rax        # imm = 0x2800001
jb 0x66c9
callq 0x71aa
xorl %ebx, %ebx
testb $0x1, %r12b
je 0x674a
leaq 0x15fb0(%rip), %rax     # 0x1c688
cmpb $0x1, 0x16(%rax)
jne 0x6717
testb $0x1, 0x8(%rsp)
je 0x6717
leaq (%rsp,%r13), %rax
addq $0x20, %rax
movq %r15, %rcx
movb (%rcx), %dl
leal -0x61(%rdx), %esi
cmpb $0x19, %sil
ja 0x6700
addb $-0x20, %dl
movb %dl, (%rcx)
cmpb $0x3d, (%rcx)
je 0x670f
incq %rcx
cmpq %rax, %rcx
jb 0x66f0
jmp 0x6717
movl $0x0, 0x8(%rsp)
movl $0x1, %esi
movq %r15, %rdi
movq %r13, %rdx
movq 0x10(%rsp), %rcx
callq 0x2460
movq 0x15f05(%rip), %rax     # 0x1c638
addq %r13, %rax
movq %rax, 0x15efb(%rip)     # 0x1c638
cmpq $0x2800001, %rax        # imm = 0x2800001
jb 0x674a
callq 0x71aa
subl %r13d, %ebp
jne 0x65ea
jmp 0x6755
andb $0x1, %r12b
movl %r12d, %eax
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq