// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x1050, %rsp           # imm = 0x1050
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0x7360
movl %eax, -0x1c(%rbp)
movb $0x1, -0x1021(%rbp)
movb $0x1, -0x1022(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x7bcf
leaq -0x1020(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
movq -0x8(%rbp), %rcx
movl $0x1000, %edx           # imm = 0x1000
callq 0x7390
movq %rax, -0x1030(%rbp)
testb $0x1, -0x1021(%rbp)
je 0x7ad7
movb $0x0, -0x1021(%rbp)
leaq 0x15c8d(%rip), %rax     # 0x1d6c8
movl (%rax), %eax
movl %eax, -0x104c(%rbp)
subl $0x2, %eax
je 0x7a57
jmp 0x7a4a
movl -0x104c(%rbp), %eax
subl $0x3, %eax
je 0x7a93
jmp 0x7a9a
xorl %eax, %eax
leaq 0x15c68(%rip), %rcx     # 0x1d6c8
testb $0x1, 0xe(%rcx)
movb %al, -0x104d(%rbp)
je 0x7a83
leaq -0x1020(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0x7d90
movb %al, -0x104d(%rbp)
movb -0x104d(%rbp), %al
andb $0x1, %al
movb %al, -0x1023(%rbp)
jmp 0x7a9a
movb $0x1, -0x1023(%rbp)
testb $0x1, -0x1023(%rbp)
je 0x7ad5
movl -0x1c(%rbp), %edi
callq 0x84f0
movl %eax, -0x1034(%rbp)
leaq -0x1034(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x4, %esi
movl $0x1, %edx
callq 0x2490
movl $0x4, %edi
callq 0x6cf0
jmp 0x7ad7
testb $0x1, -0x1023(%rbp)
je 0x7bba
leaq 0x15bdd(%rip), %rax     # 0x1d6c8
testb $0x1, 0x16(%rax)
je 0x7b92
testb $0x1, -0x1022(%rbp)
je 0x7b92
leaq -0x1020(%rbp), %rax
movq %rax, -0x1040(%rbp)
leaq -0x1020(%rbp), %rax
addq -0x1030(%rbp), %rax
movq %rax, -0x1048(%rbp)
movq -0x1040(%rbp), %rax
cmpq -0x1048(%rbp), %rax
jae 0x7b90
movq -0x1040(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x61, %eax
jl 0x7b62
movq -0x1040(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x7a, %eax
jg 0x7b62
movq -0x1040(%rbp), %rax
movzbl (%rax), %ecx
subl $0x20, %ecx
movb %cl, (%rax)
movq -0x1040(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x3d, %eax
jne 0x7b7a
movb $0x0, -0x1022(%rbp)
jmp 0x7b90
jmp 0x7b7c
movq -0x1040(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1040(%rbp)
jmp 0x7b25
jmp 0x7b92
leaq -0x1020(%rbp), %rdi
movq -0x1030(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl $0x1, %esi
callq 0x2490
movq -0x1030(%rbp), %rdi
callq 0x6cf0
movq -0x1030(%rbp), %rcx
movl -0x1c(%rbp), %eax
subq %rcx, %rax
movl %eax, -0x1c(%rbp)
jmp 0x79f5
movb -0x1023(%rbp), %al
andb $0x1, %al
addq $0x1050, %rsp           # imm = 0x1050
popq %rbp
retq