// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/xfer.c
// Function: do_ascii85_btoa
static void do_ascii85_btoa(deark *c, lctx *d, dbuf *f)
{
	i64 pos;
	i64 content_len;
	i64 total_len;
	u8 linebuf[1024];
	i64 linenum;

	pos = 0;
	d->cbuf_count = 0;
	linenum = 0;

	while(1) {
		if(!dbuf_find_line(c->infile, pos, &content_len, &total_len)) {
			de_err(c, "Bad Ascii85 format at line %d", (int)linenum);
			goto done;
		}
		linenum++;

		if(content_len > (i64)(sizeof(linebuf)-1)) {
			de_err(c, "Line %d too long", (int)linenum);
			goto done;
		}
		de_read(linebuf, pos, content_len);
		linebuf[content_len] = '\0'; // NUL terminate, in case we run sscanf
		pos += total_len;

		if(content_len<1) continue;

		if(linebuf[0]=='x') {
			if(content_len>=7 && !de_memcmp(linebuf, "xbtoa5 ", 7)) {
				de_dbg(c, "btoa new format header at line %d", (int)linenum);
				d->ascii85_fmt = ASCII85_FMT_BTOA_NEW;
			}
			else if(content_len>=11 && !de_memcmp(linebuf, "xbtoa Begin", 11)) {
				de_dbg(c, "btoa old format header at line %d", (int)linenum);
			}
			else if(content_len>=9 && !de_memcmp(linebuf, "xbtoa End", 9)) {
				if(!do_ascii85_read_btoa_end_line(c, d, linenum, linebuf, content_len)) {
					goto done;
				}
				break;
			}

			continue;
		}

		do_ascii85_data_line(c, d, f, linenum, linebuf, content_len);
	}

	do_ascii85_flush(c, d, f);

	if(d->output_filesize_known && (d->bytes_written != d->output_filesize)) {
		de_err(c, "Expected output file size=%d, actual size=%d", (int)d->output_filesize,
			(int)d->bytes_written);
	}

done:
	;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x440, %rsp            # imm = 0x440
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x438(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
leaq -0x28(%rbp), %rdx
leaq -0x30(%rbp), %rcx
callq 0x169640
cmpl $0x0, %eax
jne 0x146a42
movq -0x8(%rbp), %rdi
movq -0x438(%rbp), %rax
movl %eax, %edx
leaq 0x882dc(%rip), %rsi     # 0x1ced12
movb $0x0, %al
callq 0x15bfb0
jmp 0x146c33
movq -0x438(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x438(%rbp)
cmpq $0x3ff, -0x28(%rbp)     # imm = 0x3FF
jle 0x146a7e
movq -0x8(%rbp), %rdi
movq -0x438(%rbp), %rax
movl %eax, %edx
leaq 0x882be(%rip), %rsi     # 0x1ced30
movb $0x0, %al
callq 0x15bfb0
jmp 0x146c33
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x430(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x164d10
movq -0x28(%rbp), %rax
movb $0x0, -0x430(%rbp,%rax)
movq -0x30(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x1, -0x28(%rbp)
jge 0x146abe
jmp 0x146a04
movzbl -0x430(%rbp), %eax
cmpl $0x78, %eax
jne 0x146bb6
cmpq $0x7, -0x28(%rbp)
jl 0x146b1d
leaq -0x430(%rbp), %rdi
leaq 0x88224(%rip), %rsi     # 0x1ced07
movl $0x7, %edx
callq 0x19170
cmpl $0x0, %eax
jne 0x146b1d
movq -0x8(%rbp), %rdi
movq -0x438(%rbp), %rax
movl %eax, %edx
leaq 0x8823b(%rip), %rsi     # 0x1ced41
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movl $0x16, 0x10(%rax)
jmp 0x146bb1
cmpq $0xb, -0x28(%rbp)
jl 0x146b5e
leaq -0x430(%rbp), %rdi
leaq 0x881c9(%rip), %rsi     # 0x1cecfb
movl $0xb, %edx
callq 0x19170
cmpl $0x0, %eax
jne 0x146b5e
movq -0x8(%rbp), %rdi
movq -0x438(%rbp), %rax
movl %eax, %edx
leaq 0x8820e(%rip), %rsi     # 0x1ced63
movb $0x0, %al
callq 0x15b0d0
jmp 0x146baf
cmpq $0x9, -0x28(%rbp)
jl 0x146bad
leaq -0x430(%rbp), %rdi
leaq 0x88212(%rip), %rsi     # 0x1ced85
movl $0x9, %edx
callq 0x19170
cmpl $0x0, %eax
jne 0x146bad
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x438(%rbp), %rdx
leaq -0x430(%rbp), %rcx
movq -0x28(%rbp), %r8
callq 0x146ce0
cmpl $0x0, %eax
jne 0x146bab
jmp 0x146c33
jmp 0x146bde
jmp 0x146baf
jmp 0x146bb1
jmp 0x146a04
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x438(%rbp), %rcx
leaq -0x430(%rbp), %r8
movq -0x28(%rbp), %r9
callq 0x146da0
jmp 0x146a04
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x146e40
movq -0x10(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x146c31
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x20(%rcx), %rax
je 0x146c31
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl %eax, %edx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, %ecx
leaq 0x88165(%rip), %rsi     # 0x1ced8f
movb $0x0, %al
callq 0x15bfb0
jmp 0x146c33
addq $0x440, %rsp            # imm = 0x440
popq %rbp
retq
nopl (%rax)