// File: /workspace/github_c_makefile_star2_O1/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:
cmpl $0x0, 0x8(%rsi)
je 0x5948b
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r15
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbx
callq 0x59571
movq 0x28(%r12), %rax
movq %rax, (%rsp)
movq 0x10(%r13), %r13
movzbl 0x20(%r12), %eax
cmpl $0x20, %eax
je 0x59241
cmpl $0x1, %eax
jne 0x59356
movq %rsp, %rsi
movq %r13, %rdi
callq 0xf9f83
leaq 0xc841a(%rip), %rsi     # 0x12166d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
cmpb $0x20, 0x20(%r12)
jne 0x59287
movq %rsp, %rsi
movq %r13, %rdi
callq 0xf9ec9
leaq 0xc8403(%rip), %rsi     # 0x12167d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
movq %rsp, %rbp
addq $0x2, (%rbp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0xef1ed
leaq 0xd5778(%rip), %rsi     # 0x12ea19
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq %r13, %rdi
movq %rbp, %rsi
callq 0xef1ed
movq %rax, %rbp
leaq 0xc83cd(%rip), %rsi     # 0x12168f
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xe9226
testb $0x1, %bpl
je 0x592df
movq %rsp, %rsi
movq %r13, %rdi
callq 0xf9f83
testb $0x2, %bpl
je 0x592f0
movq %rsp, %rsi
movq %r13, %rdi
callq 0xf9f03
testb $0x4, %bpl
je 0x59301
movq %rsp, %rsi
movq %r13, %rdi
callq 0xf9f03
testb $0x8, %bpl
je 0x59312
movq %rsp, %rsi
movq %r13, %rdi
callq 0xf9f03
testb $0x10, %bpl
je 0x59323
movq %rsp, %rsi
movq %r13, %rdi
callq 0xf9f03
testb $0x20, %bpl
je 0x59334
movq %rsp, %rsi
movq %r13, %rdi
callq 0xf9f03
testb $0x40, %bpl
je 0x59345
movq %rsp, %rsi
movq %r13, %rdi
callq 0xf9f03
testl $0x300, %ebp            # imm = 0x300
jne 0x59356
movq (%rsp), %rax
movq %rax, 0x50(%r12)
movq %rbx, 0x10(%rsp)
movq %rsp, %rax
movq $0x0, (%rax)
movq 0xd0(%r14), %rdi
movq $0x0, 0x8(%rsp)
xorl %esi, %esi
callq 0xf152a
xorl %ebp, %ebp
xorl %r13d, %r13d
movq (%rsp), %rbx
movq 0x18(%r15), %r12
cmpq %r12, %rbx
jge 0x59408
movq %r15, %rdi
movq %rsp, %rsi
callq 0xef14d
testb %al, %al
je 0x593b6
movq 0xd0(%r14), %rdi
movzbl %al, %esi
callq 0xf11be
incl %ebp
movl $0x1, %r13d
jmp 0x59408
testl %r13d, %r13d
je 0x59405
movq 0xd0(%r14), %rdx
movq 0x18(%rdx), %rcx
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x59668
movq 0xd0(%r14), %rdi
xorl %esi, %esi
callq 0xf152a
movq 0xc0(%r14), %rdi
testq %rdi, %rdi
je 0x593f9
leaq 0xb6da7(%rip), %rsi     # 0x11019b
callq 0xf16f0
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
cmpq %r12, %rbx
jl 0x59381
testl %r13d, %r13d
je 0x59460
movq 0xd0(%r14), %rdx
movq 0x18(%rdx), %rcx
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x59668
movq 0xd0(%r14), %rdi
xorl %esi, %esi
callq 0xf152a
movq 0xc0(%r14), %rdi
testq %rdi, %rdi
je 0x59457
leaq 0xb6d49(%rip), %rsi     # 0x11019b
callq 0xf16f0
movq 0x8(%rsp), %rdx
incl %edx
jmp 0x5946a
movq 0x10(%rsp), %rbx
movq 0x8(%rsp), %rdx
leaq 0xc81b7(%rip), %rsi     # 0x121628
movq %rbx, %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0xe93cf
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq