// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/hlp.c
// Function: do_topiclink_rectype_1_32
static void do_topiclink_rectype_1_32(deark *c, lctx *d,
	struct topic_ctx *tctx, struct topiclink_data *tld, dbuf *linkdata2)
{
	i64 pos;
	int in_string = 0;
	int string_count = 0;
	int byte_count = 0;

	if(!d->extract_text) goto done;
	ensure_text_output_file_open(c, d);

	do_topiclink_rectype_32_linkdata1(c, d, tctx, tld);

	// TODO: This is very quick & dirty.
	// The linkdata2 is a collection of NUL-terminated strings. We'd have to
	// interpret the command bytes from linkdata1 to know how to format them.

	pos = 0;
	dbuf_truncate(d->tmpdbuf1, 0); // A place to collect the current output string

	while(1) {
		u8 b;

		if(pos >= linkdata2->len) break;
		b = dbuf_getbyte_p(linkdata2, &pos);
		if(b==0x00) {
			if(in_string) {
				emit_slice(c, d, d->tmpdbuf1, 0, d->tmpdbuf1->len);
				dbuf_truncate(d->tmpdbuf1, 0);
				emit_raw_sz(c, d, "\n");
				string_count++;
				in_string = 0;
			}
		}
		else {
			dbuf_writebyte(d->tmpdbuf1, b);
			byte_count++;
			in_string = 1;
		}
	}
	if(in_string) {
		emit_slice(c, d, d->tmpdbuf1, 0, d->tmpdbuf1->len);
		dbuf_truncate(d->tmpdbuf1, 0);
		emit_raw_sz(c, d, "\n");
		string_count++;
	}
	de_dbg2(c, "[emitted %d strings, totaling %d bytes]", string_count, byte_count);

done:
	;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x7e230
jmp 0x7e3a8
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x7e480
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x7e5d0
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x168900
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jl 0x7e281
jmp 0x7e32e
movq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165170
movb %al, -0x3d(%rbp)
movzbl -0x3d(%rbp), %eax
cmpl $0x0, %eax
jne 0x7e305
cmpl $0x0, -0x34(%rbp)
je 0x7e303
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rax
movq 0x18(%rax), %r8
xorl %eax, %eax
movl %eax, %ecx
callq 0x7e7d0
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x168900
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq 0x11de95(%rip), %rdx    # 0x19c183
callq 0x7e890
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
jmp 0x7e329
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rdi
movzbl -0x3d(%rbp), %esi
callq 0x168380
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl $0x1, -0x34(%rbp)
jmp 0x7e26e
cmpl $0x0, -0x34(%rbp)
je 0x7e390
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rdx
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rax
movq 0x18(%rax), %r8
xorl %eax, %eax
movl %eax, %ecx
callq 0x7e7d0
movq -0x10(%rbp), %rax
movq 0xd0(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x168900
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq 0x11de01(%rip), %rdx    # 0x19c183
callq 0x7e890
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl -0x38(%rbp), %edx
movl -0x3c(%rbp), %ecx
leaq 0x12ef3c(%rip), %rsi    # 0x1ad2dd
movb $0x0, %al
callq 0x15b350
addq $0x40, %rsp
popq %rbp
retq
nop