// File: /workspace/github_c_makefile_star2_O1/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 %rdi, %r14
movq 0x18(%rdx), %rbx
movl $0x0, (%rsi)
movb $0x1, %al
movl %eax, 0x4(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rsi, 0x8(%rsp)
movq 0x18(%r14), %rdi
cmpq 0x18(%rdi), %rbx
jge 0xdba82
incq %rbx
leaq -0x1(%rbx), %rsi
callq 0xef0d5
movl %eax, %r13d
movzbl %al, %esi
testb $0x1, %r15b
jne 0xdb986
cmpb $0xd, %r13b
je 0xdb93e
cmpl $0xa, %esi
jne 0xdb957
movq 0x18(%r14), %rdi
leaq 0x1(%rbx), %rax
xorl %r15d, %r15d
cmpq 0x18(%rdi), %rbx
movq %rax, %rbx
jl 0xdb91e
jmp 0xdba82
testb $0x1, %r15b
jne 0xdb986
movq 0x8(%rsp), %rdi
leaq 0x3(%rsp), %rdx
callq 0xdbbe7
testl %eax, %eax
je 0xdba71
movzbl 0x3(%rsp), %ebp
movb $0x1, %r15b
testq %rbp, %rbp
jne 0xdb90d
jmp 0xdba82
cmpb $0xd, %r13b
je 0xdb991
cmpl $0xa, %esi
jne 0xdb9ea
movq %rbp, %rdx
subq %r12, %rdx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xdb6c1
movq %rax, %r13
addq %r12, %r13
cmpq %rbp, %r13
je 0xdb9c7
movq %r14, %rdi
leaq 0x67280(%rip), %rsi     # 0x142c3b
movl %ebp, %edx
movl %r13d, %ecx
xorl %eax, %eax
callq 0xe9b27
cmpq %rbp, %r13
sete %al
cmpq $0x2d, %r13
setl %cl
xorl %r15d, %r15d
movl $0x0, %r12d
testb %al, %cl
je 0xdb90d
jmp 0xdba82
movq 0x8(%rsp), %r13
movq %r13, %rdi
leaq 0x3(%rsp), %rdx
callq 0xdbbe7
testl %eax, %eax
je 0xdba3b
movb 0x3(%rsp), %al
movl (%r13), %ecx
leal 0x1(%rcx), %edx
movl %edx, (%r13)
movb %al, 0x4(%r13,%rcx)
movb $0x1, %r15b
cmpl $0x4, %edx
jb 0xdb90d
movq %rbp, %rdx
subq %r12, %rdx
movq %r13, %rdi
movq 0x10(%rsp), %rsi
callq 0xdb6c1
addq %rax, %r12
jmp 0xdb90d
movb $0x1, %r15b
testb $0x1, 0x4(%rsp)
movl $0x0, 0x4(%rsp)
je 0xdb90d
movl $0x0, 0x4(%rsp)
movq %r14, %rdi
leaq 0x671fa(%rip), %rsi     # 0x142c5d
movl %ebx, %edx
xorl %eax, %eax
callq 0xe9b27
jmp 0xdb90d
cmpb $0x65, %r13b
jne 0xdba91
movq 0x8(%rsp), %rax
cmpl $0x2, 0xc(%rax)
jne 0xdba91
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x67184(%rip), %rsi     # 0x142c1c
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 0xe9df7