// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x1, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpq 0x18(%rcx), %rax
jge 0x146543
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
callq 0x165060
movb %al, -0x2d(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x1463b5
movzbl -0x2d(%rbp), %eax
cmpl $0xa, %eax
je 0x1463b3
movzbl -0x2d(%rbp), %eax
cmpl $0xd, %eax
jne 0x1463b5
jmp 0x146366
cmpl $0x0, -0x38(%rbp)
je 0x14642e
movl $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x2e(%rbp), %rcx
movzbl -0x2d(%rbp), %edx
callq 0x146750
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x146415
movzbl -0x2d(%rbp), %eax
cmpl $0x65, %eax
jne 0x1463f8
movq -0x10(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jne 0x1463f8
jmp 0x146545
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0x8885f(%rip), %rsi     # 0x1cec68
movb $0x0, %al
callq 0x15bfb0
jmp 0x146545
movzbl -0x2e(%rbp), %eax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x146429
jmp 0x146545
jmp 0x146366
movzbl -0x2d(%rbp), %eax
cmpl $0xa, %eax
je 0x146440
movzbl -0x2d(%rbp), %eax
cmpl $0xd, %eax
jne 0x1464b3
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x48(%rbp), %rcx
subq -0x40(%rbp), %rcx
callq 0x145ff0
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x146489
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
movq -0x40(%rbp), %rax
movl %eax, %ecx
leaq 0x88805(%rip), %rsi     # 0x1cec87
movb $0x0, %al
callq 0x15bc10
cmpq $0x2d, -0x40(%rbp)
jge 0x14649f
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jne 0x14649f
jmp 0x146545
movq $0x0, -0x40(%rbp)
movl $0x1, -0x38(%rbp)
jmp 0x146366
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x2e(%rbp), %rcx
movzbl -0x2d(%rbp), %edx
callq 0x146750
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x146517
movb -0x2e(%rbp), %dl
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rsi
movl (%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, (%rsi)
movl %ecx, %ecx
movb %dl, 0x4(%rax,%rcx)
movq -0x10(%rbp), %rax
cmpl $0x4, (%rax)
jb 0x146515
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x48(%rbp), %rcx
subq -0x40(%rbp), %rcx
callq 0x145ff0
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x14653e
cmpl $0x0, -0x34(%rbp)
jne 0x14653c
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0x8877b(%rip), %rsi     # 0x1ceca9
movb $0x0, %al
callq 0x15bc10
movl $0x1, -0x34(%rbp)
jmp 0x14653e
jmp 0x146366
jmp 0x146545
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)