// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/xfer.c
// Function: do_ascii85_flush
static void do_ascii85_flush(deark *c, lctx *d, dbuf *f)
{
	i64 i;
	u32 code;

	if(d->cbuf_count<1) return;

	code = (u32)d->cbuf[0];
	for(i=1; i<5; i++) {
		if(i<d->cbuf_count)
			code = code*85 + (u32)d->cbuf[i];
		else
			code = code*85 + 84; // (This shouldn't happen with btoa format)
	}

	// TODO: Simplify this code
	if(d->cbuf_count>=2) {
		dbuf_writebyte(f, (u8)((code>>24)&0xff));
		d->bytes_written++;
		if(d->output_filesize_known && d->bytes_written>=d->output_filesize) goto done;
	}
	if(d->cbuf_count>=3) {
		dbuf_writebyte(f, (u8)((code>>16)&0xff));
		d->bytes_written++;
		if(d->output_filesize_known && d->bytes_written>=d->output_filesize) goto done;
	}
	if(d->cbuf_count>=4) {
		dbuf_writebyte(f, (u8)((code>>8)&0xff));
		d->bytes_written++;
		if(d->output_filesize_known && d->bytes_written>=d->output_filesize) goto done;
	}
	if(d->cbuf_count>=5) {
		dbuf_writebyte(f, (u8)(code&0xff));
		d->bytes_written++;
		if(d->output_filesize_known && d->bytes_written>=d->output_filesize) goto done;
	}

done:
	d->cbuf_count = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x1, (%rax)
jae 0x146e62
jmp 0x14700c
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
movl %eax, -0x24(%rbp)
movq $0x1, -0x20(%rbp)
cmpq $0x5, -0x20(%rbp)
jge 0x146ebd
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
cmpq %rcx, %rax
jge 0x146ea3
imull $0x55, -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rdx
movzbl 0x4(%rcx,%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
jmp 0x146ead
imull $0x55, -0x24(%rbp), %eax
addl $0x54, %eax
movl %eax, -0x24(%rbp)
jmp 0x146eaf
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x146e75
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jb 0x146f10
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %eax
shrl $0x18, %eax
andl $0xff, %eax
movzbl %al, %esi
callq 0x168380
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x146f0e
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jl 0x146f0e
jmp 0x147002
jmp 0x146f10
movq -0x10(%rbp), %rax
cmpl $0x3, (%rax)
jb 0x146f63
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %eax
shrl $0x10, %eax
andl $0xff, %eax
movzbl %al, %esi
callq 0x168380
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x146f61
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jl 0x146f61
jmp 0x147002
jmp 0x146f63
movq -0x10(%rbp), %rax
cmpl $0x4, (%rax)
jb 0x146fb3
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
movzbl %al, %esi
callq 0x168380
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x146fb1
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jl 0x146fb1
jmp 0x147002
jmp 0x146fb3
movq -0x10(%rbp), %rax
cmpl $0x5, (%rax)
jb 0x147000
movq -0x18(%rbp), %rdi
movl -0x24(%rbp), %eax
andl $0xff, %eax
movzbl %al, %esi
callq 0x168380
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x146ffe
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jl 0x146ffe
jmp 0x147002
jmp 0x147000
jmp 0x147002
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)