// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/sauce.c
// Function: sauce_read_comments
static void sauce_read_comments(deark *c, struct sauce_private_ctx *d, dbuf *inf,
	struct de_SAUCE_info *si)
{
	i64 cmnt_blk_start;
	i64 k;
	i64 cmnt_pos;
	i64 cmnt_len;
	u8 buf[64];
	de_ucstring *tmpcomment = NULL;

	if(d->num_comments<1) goto done;
	cmnt_blk_start = inf->len - 128 - (5 + d->num_comments*64);

	if(dbuf_memcmp(inf, cmnt_blk_start, "COMNT", 5)) {
		de_dbg(c, "invalid SAUCE comment, not found at %d", (int)cmnt_blk_start);
		d->num_comments = 0;
		goto done;
	}

	de_dbg(c, "SAUCE comment block at %d", (int)cmnt_blk_start);

	si->comment = ucstring_create(c);
	tmpcomment = ucstring_create(c);

	de_dbg_indent(c, 1);
	for(k=0; k<d->num_comments; k++) {
		int respect_trailing_spaces = 0;

		cmnt_pos = cmnt_blk_start+5+k*64;
		dbuf_read(inf, buf, cmnt_pos, 64);

		if(d->combine_comments && k!=(d->num_comments-1)) {
			respect_trailing_spaces = 1;
		}
		cmnt_len = sauce_get_string_length(buf, 64, respect_trailing_spaces);

		de_dbg(c, "comment at %d, len=%d", (int)cmnt_pos, (int)cmnt_len);
		de_dbg_indent(c, 1);

		ucstring_empty(tmpcomment);
		sauce_bytes_to_ucstring(c, buf, cmnt_len, tmpcomment, d->encoding_for_comments);
		ucstring_append_ucstring(si->comment, tmpcomment);
		if(!d->combine_comments && k!=(d->num_comments-1)) {
			ucstring_append_char(si->comment, 0x0a);
		}

		de_dbg(c, "comment: \"%s\"", ucstring_getpsz(tmpcomment));
		de_dbg_indent(c, -1);
	}

	sauce_strip_trailing_whitespace(si->comment);
	if(ucstring_isempty(si->comment)) {
		ucstring_destroy(si->comment);
		si->comment = NULL;
		goto done;
	}

	if(c->extract_level>=2) {
		dbuf *cmnt_outf = NULL;

		cmnt_outf = dbuf_create_output_file(c, "comment.txt", NULL, DE_CREATEFLAG_IS_AUX);
		ucstring_write_as_utf8(c, si->comment, cmnt_outf, 1);
		dbuf_puts(cmnt_outf, "\n");
		dbuf_close(cmnt_outf);
	}

	de_dbg_indent(c, -1);

done:
	ucstring_destroy(tmpcomment);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x1, 0x8(%rax)
jge 0x1451c6
jmp 0x1454b6
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
subq $0x80, %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
shlq $0x6, %rcx
addq $0x5, %rcx
subq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
leaq 0x8988b(%rip), %rdx     # 0x1cea85
movl $0x5, %ecx
callq 0x166ab0
cmpl $0x0, %eax
je 0x145232
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0x89871(%rip), %rsi     # 0x1cea8b
movb $0x0, %al
callq 0x15b0d0
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
jmp 0x1454b6
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
leaq 0x8986f(%rip), %rsi     # 0x1ceab2
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jge 0x1453f7
movl $0x0, -0x8c(%rbp)
movq -0x28(%rbp), %rax
addq $0x5, %rax
movq -0x30(%rbp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl $0x40, %ecx
callq 0x164d10
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1452f5
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0x1452f5
movl $0x1, -0x8c(%rbp)
leaq -0x80(%rbp), %rdi
movl -0x8c(%rbp), %edx
movl $0x40, %esi
callq 0x144c80
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %edx
movq -0x40(%rbp), %rax
movl %eax, %ecx
leaq 0x897a8(%rip), %rsi     # 0x1ceacc
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x88(%rbp), %rdi
callq 0x171210
movq -0x8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x88(%rbp), %rcx
movq -0x10(%rbp), %rax
movl 0x14(%rax), %r8d
callq 0x144d00
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x88(%rbp), %rsi
callq 0x171460
movq -0x10(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x1453a9
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
je 0x1453a9
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rdi
movl $0xa, %esi
callq 0x1714c0
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x88(%rbp), %rdi
callq 0x172500
movq -0xa0(%rbp), %rdi
movq %rax, %rdx
leaq 0x5b27b(%rip), %rsi     # 0x1a064c
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x145284
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x1454d0
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x1717b0
cmpl $0x0, %eax
je 0x145434
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0x171750
movq -0x20(%rbp), %rax
movq $0x0, 0x60(%rax)
jmp 0x1454b6
movq -0x8(%rbp), %rax
cmpl $0x2, 0x90(%rax)
jl 0x1454a8
movq $0x0, -0x98(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x5edf9(%rip), %rsi     # 0x1a4250
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
callq 0x166c60
movq %rax, -0x98(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rsi
movq -0x98(%rbp), %rdx
movl $0x1, %ecx
callq 0x172150
movq -0x98(%rbp), %rdi
leaq 0x56cec(%rip), %rsi     # 0x19c183
callq 0x168da0
movq -0x98(%rbp), %rdi
callq 0x1676a0
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movq -0x88(%rbp), %rdi
callq 0x171750
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)