// File: /workspace/github_c_makefile_star2_O3/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 %rdx, %rbx
movq %rdi, %r14
movl $0x0, (%rsi)
movb $0x1, %al
movl %eax, 0x4(%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
movq %rsi, 0x8(%rsp)
movq 0x18(%r14), %rdi
cmpq 0x18(%rdi), %rbx
jge 0xdb0d9
incq %rbx
leaq -0x1(%rbx), %rsi
callq 0xeead3
movl %eax, %ebp
testb $0x1, %r12b
jne 0xdafa2
cmpb $0xd, %bpl
je 0xdaf89
movzbl %bpl, %esi
cmpl $0xa, %esi
jne 0xdb00e
movq 0x18(%r14), %rdi
leaq 0x1(%rbx), %rax
xorl %r12d, %r12d
cmpq 0x18(%rdi), %rbx
movq %rax, %rbx
jl 0xdaf65
jmp 0xdb0d9
cmpb $0xd, %bpl
je 0xdafb5
movzbl %bpl, %esi
cmpl $0xa, %esi
jne 0xdb043
movq %r13, %rdx
subq %r15, %rdx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0xdacc2
movq %rax, %rbp
addq %r15, %rbp
cmpq %r13, %rbp
je 0xdafeb
movq %r14, %rdi
leaq 0x6813c(%rip), %rsi     # 0x14311b
movl %r13d, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe8faa
cmpq %r13, %rbp
sete %al
cmpq $0x2d, %rbp
setl %cl
xorl %r12d, %r12d
movl $0x0, %r15d
testb %al, %cl
je 0xdaf54
jmp 0xdb0d9
movq 0x8(%rsp), %rax
movl 0xc(%rax), %r13d
movl %r13d, %edi
leaq 0x3(%rsp), %rdx
callq 0xdb23c
testl %eax, %eax
je 0xdb0c7
movzbl 0x3(%rsp), %r13d
movb $0x1, %r12b
testq %r13, %r13
jne 0xdaf54
jmp 0xdb0d9
movq 0x8(%rsp), %rbp
movl 0xc(%rbp), %edi
leaq 0x3(%rsp), %rdx
callq 0xdb23c
testl %eax, %eax
je 0xdb091
movb 0x3(%rsp), %al
movl (%rbp), %ecx
leal 0x1(%rcx), %edx
movl %edx, (%rbp)
movb %al, 0x4(%rbp,%rcx)
movb $0x1, %r12b
cmpl $0x4, %edx
jb 0xdaf54
movq %r13, %rdx
subq %r15, %rdx
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
callq 0xdacc2
addq %rax, %r15
jmp 0xdaf54
movb $0x1, %r12b
testb $0x1, 0x4(%rsp)
movl $0x0, 0x4(%rsp)
je 0xdaf54
movl $0x0, 0x4(%rsp)
movq %r14, %rdi
leaq 0x68084(%rip), %rsi     # 0x14313d
movl %ebx, %edx
xorl %eax, %eax
callq 0xe8faa
jmp 0xdaf54
cmpb $0x65, %bpl
sete %al
cmpl $0x2, %r13d
sete %cl
testb %cl, %al
je 0xdb0e8
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6800d(%rip), %rsi     # 0x1430fc
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 0xe9295