// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/xfer.c
// Function: do_uudecode_internal
static void do_uudecode_internal(deark *c, lctx *d, struct uu_hdr_parser *uuhp,
	dbuf *outf)
{
	i64 pos;
	int ret;
	u8 b;
	u8 x;
	int bad_warned = 0;
	int start_of_line_flag;
	i64 decoded_bytes_this_line;
	i64 expected_decoded_bytes_this_line;

	pos = uuhp->data_startpos;
	d->cbuf_count = 0;
	decoded_bytes_this_line = 0;
	expected_decoded_bytes_this_line = 0;
	start_of_line_flag = 1;
	d->cbuf_count = 0;

	while(pos<c->infile->len) {
		b = de_getbyte(pos++);

		if(start_of_line_flag && (b==10 || b==13)) {
			// Multi-byte EOL sequence, or blank line
			continue;
		}

		if(start_of_line_flag) {
			start_of_line_flag = 0;

			ret = get_uu_byte_value(c, d, b, &x);
			if(!ret) {
				if(b=='e' && d->data_fmt==FMT_UUENCODE) {
					// Assume this is the "end" footer line.
					goto done;
				}
				de_err(c, "Bad uuencoded data (offset %d)", (int)pos);
				goto done;
			}

			expected_decoded_bytes_this_line = x;
			if(expected_decoded_bytes_this_line==0) {
				goto done;
			}
			continue;
		}

		if(b==10 || b==13) {
			// End of line
			decoded_bytes_this_line += do_base64_flush(c, d, outf,
				expected_decoded_bytes_this_line-decoded_bytes_this_line);

			if(decoded_bytes_this_line != expected_decoded_bytes_this_line) {
				de_warn(c, "Expected %d bytes on line, got %d",
					(int)expected_decoded_bytes_this_line, (int)decoded_bytes_this_line);
			}

			if(decoded_bytes_this_line<45 &&
				decoded_bytes_this_line==expected_decoded_bytes_this_line)
			{
				// Assume a short line means end of data.
				goto done;
			}

			decoded_bytes_this_line = 0;
			start_of_line_flag = 1;
			continue;
		}

		// Expecting a regular data byte
		ret = get_uu_byte_value(c, d, b, &x);
		if(ret) {
			d->cbuf[d->cbuf_count++] = x;
			if(d->cbuf_count>=4) {
				decoded_bytes_this_line += do_base64_flush(c, d, outf,
					expected_decoded_bytes_this_line-decoded_bytes_this_line);
			}
		}
		else {
			if(!bad_warned) {
				de_warn(c, "Bad uuencode character (offset %d)", (int)pos);
				bad_warned = 1;
			}
		}
	}

done:
	;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, 0x10(%rsp)
movq 0x18(%rdx), %rbx
movq %rsi, 0x8(%rsp)
andl $0x0, (%rsi)
movq %rdi, %r14
movb $0x1, %al
movl %eax, 0x4(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r13d, %r13d
incq %rbx
leaq -0x1(%rbx), %rsi
movq 0x18(%r14), %rdi
cmpq 0x18(%rdi), %rsi
jge 0xd1c05
callq 0xe3eb4
movl %eax, %ebp
movzbl %al, %esi
testb $0x1, %r15b
jne 0xd1ad9
cmpb $0xd, %bpl
je 0xd1ad1
cmpl $0xa, %esi
jne 0xd1b44
incq %rbx
xorl %r15d, %r15d
jmp 0xd1aa4
cmpb $0xd, %bpl
movq 0x8(%rsp), %r15
je 0xd1aed
cmpl $0xa, %esi
jne 0xd1b72
movq %r13, %rdx
subq %r12, %rdx
movq %r15, %rdi
movq 0x10(%rsp), %rsi
callq 0xd1858
movq %rax, %rbp
addq %r12, %rbp
cmpq %r13, %rbp
je 0xd1b21
movq %r14, %rdi
leaq 0x641b6(%rip), %rsi     # 0x135ccb
movl %r13d, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0xdf05a
cmpq %r13, %rbp
sete %al
cmpq $0x2d, %rbp
setl %cl
xorl %r15d, %r15d
movl $0x0, %r12d
testb %al, %cl
je 0xd1aa1
jmp 0xd1c05
movq 0x8(%rsp), %rdi
leaq 0x3(%rsp), %rdx
callq 0xd1d76
testl %eax, %eax
je 0xd1bf4
movzbl 0x3(%rsp), %r13d
movb $0x1, %r15b
testq %r13, %r13
jne 0xd1aa1
jmp 0xd1c05
movq %r15, %rdi
leaq 0x3(%rsp), %rdx
callq 0xd1d76
testl %eax, %eax
je 0xd1bbe
movb 0x3(%rsp), %al
movl (%r15), %ecx
leal 0x1(%rcx), %edx
movl %edx, (%r15)
movb %al, 0x4(%r15,%rcx)
movb $0x1, %r15b
cmpl $0x4, %edx
jb 0xd1aa1
movq %r13, %rdx
subq %r12, %rdx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xd1858
addq %rax, %r12
jmp 0xd1aa1
movb $0x1, %r15b
testb $0x1, 0x4(%rsp)
movl $0x0, 0x4(%rsp)
je 0xd1aa1
movl $0x0, 0x4(%rsp)
movq %r14, %rdi
leaq 0x64107(%rip), %rsi     # 0x135ced
movl %ebx, %edx
xorl %eax, %eax
callq 0xdf05a
jmp 0xd1aa1
cmpb $0x65, %bpl
jne 0xd1c14
movq 0x8(%rsp), %rax
cmpl $0x2, 0xc(%rax)
jne 0xd1c14
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x64091(%rip), %rsi     # 0x135cac
movq %r14, %rdi
movl %ebx, %edx
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xdf2a5