// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/jpeg.c
// Function: handle_comment
static void handle_comment(deark *c, lctx *d, i64 pos, i64 comment_size,
   de_encoding encoding_base)
{
	de_ucstring *s = NULL;
	de_ext_encoding encoding_ext;
	int write_to_file;

	// If c->extract_level>=2, write the comment to a file;
	// otherwise if we have debugging output, write (at least part of) it
	// to the debug output;
	// otherwise do nothing.

	if(c->extract_level<2 && c->debug_level<1) return;
	if(comment_size<1) return;

	write_to_file = (c->extract_level>=2);

	if(write_to_file && encoding_base==DE_ENCODING_UNKNOWN) {
		// If we don't know the encoding, dump the raw bytes to a file.
		dbuf_create_file_from_slice(c->infile, pos, comment_size, "comment.txt",
			NULL, DE_CREATEFLAG_IS_AUX);
		goto done;
	}

	if(encoding_base==DE_ENCODING_UNKNOWN) {
		// In this case, we're printing the comment in the debug info.
		// If we don't know the encoding, pretend it's ASCII-like.
		encoding_ext = DE_EXTENC_MAKE(DE_ENCODING_ASCII, DE_ENCSUBTYPE_PRINTABLE);
	}
	else {
		encoding_ext = encoding_base;
	}

	s = ucstring_create(c);
	dbuf_read_to_ucstring(c->infile, pos, comment_size, s, 0, encoding_ext);

	if(write_to_file) {
		dbuf *outf = NULL;
		outf = dbuf_create_output_file(c, "comment.txt", NULL, DE_CREATEFLAG_IS_AUX);
		ucstring_write_as_utf8(c, s, outf, 1);
		dbuf_close(outf);
	}
	else {
		de_dbg(c, "comment: \"%s\"", ucstring_getpsz_d(s));
	}

done:
	ucstring_destroy(s);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x2, 0x90(%rax)
jge 0xbdf5f
movq -0x8(%rbp), %rax
cmpl $0x1, (%rax)
jge 0xbdf5f
jmp 0xbe078
cmpq $0x1, -0x20(%rbp)
jge 0xbdf6b
jmp 0xbe078
movq -0x8(%rbp), %rax
cmpl $0x2, 0x90(%rax)
setge %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0xbdfb9
cmpl $0x0, -0x24(%rbp)
jne 0xbdfb9
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq 0xe62ac(%rip), %rcx     # 0x1a4250
xorl %eax, %eax
movl %eax, %r8d
movl $0x1, %r9d
callq 0x166be0
jmp 0xbe06f
cmpl $0x0, -0x24(%rbp)
jne 0xbdfc8
movl $0x401, -0x34(%rbp)     # imm = 0x401
jmp 0xbdfce
movl -0x24(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
movl -0x34(%rbp), %r9d
xorl %r8d, %r8d
callq 0x1669f0
cmpl $0x0, -0x38(%rbp)
je 0xbe047
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq 0xe623c(%rip), %rsi     # 0x1a4250
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %ecx
callq 0x166c60
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl $0x1, %ecx
callq 0x172150
movq -0x40(%rbp), %rdi
callq 0x1676a0
jmp 0xbe06d
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
callq 0x172650
movq -0x48(%rbp), %rdi
movq %rax, %rdx
leaq 0xe25e6(%rip), %rsi     # 0x1a064c
movb $0x0, %al
callq 0x15b0d0
jmp 0xbe06f
movq -0x30(%rbp), %rdi
callq 0x171750
addq $0x50, %rsp
popq %rbp
retq
nop