// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/jbf.c
// Function: read_filename
static int read_filename(deark *c, lctx *d, struct page_ctx *pg, i64 pos1, i64 *bytes_consumed)
{
	int retval = 0;
	i64 pos = pos1;
	de_ucstring *fname_orig = NULL;

	fname_orig = ucstring_create(c);

	if(d->ver_combined>=0x010001) { // v1.1+
		i64 fnlen;
		fnlen = de_getu32le_p(&pos);
		de_dbg(c, "original filename len: %d", (int)fnlen);
		if(fnlen>1000) {
			de_err(c, "Bad filename length");
			goto done;
		}

		dbuf_read_to_ucstring(c->infile, pos, fnlen, fname_orig, 0, d->input_encoding);
		pos += fnlen;
	}
	else { // v1.0
		// File always has 13 bytes reserved for the filename.
		// The name is up to 12 bytes long, terminated by 0x00.
		dbuf_read_to_ucstring(c->infile, pos, 12, fname_orig, DE_CONVFLAG_STOP_AT_NUL,
			d->input_encoding);
		pos += 13;
	}

	de_dbg(c, "original filename: \"%s\"", ucstring_getpsz(fname_orig));

	if(c->filenames_from_file) {
		pg->fname = ucstring_clone(fname_orig);
		ucstring_append_sz(pg->fname, ".thumb.", DE_ENCODING_LATIN1);
		if(d->ver_major>=2)
			ucstring_append_sz(pg->fname, "jpg", DE_ENCODING_LATIN1);
		else
			ucstring_append_sz(pg->fname, "bmp", DE_ENCODING_LATIN1);
		de_finfo_set_name_from_ucstring(c, pg->fi, pg->fname, 0);
		pg->fi->original_filename_flag = 1;
	}
	else {
		if(d->ver_major>=2)
			pg->thumbnail_ext = "jpg";
		else
			pg->thumbnail_ext = "bmp";
	}

	retval = 1;
done:
	ucstring_destroy(fname_orig);
	*bytes_consumed = pos - pos1;
	return retval;
}

// 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)
movq %r8, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x10001, 0xc(%rax)     # imm = 0x10001
jb 0xba36c
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x165580
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rax
movl %eax, %edx
leaq 0xfbe01(%rip), %rsi     # 0x1b6114
movb $0x0, %al
callq 0x15b0d0
cmpq $0x3e8, -0x48(%rbp)     # imm = 0x3E8
jle 0xba33b
movq -0x8(%rbp), %rdi
leaq 0xfbdff(%rip), %rsi     # 0x1b612e
movb $0x0, %al
callq 0x15bfb0
jmp 0xba49b
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movl (%rax), %r9d
xorl %r8d, %r8d
callq 0x1669f0
movq -0x48(%rbp), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0xba39f
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rcx
movq -0x10(%rbp), %rax
movl (%rax), %r9d
movl $0xc, %edx
movl $0x1, %r8d
callq 0x1669f0
movq -0x38(%rbp), %rax
addq $0xd, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rdi
callq 0x172500
movq -0x50(%rbp), %rdi
movq %rax, %rdx
leaq 0xfbd84(%rip), %rsi     # 0x1b6142
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
cmpb $0x0, 0xd0(%rax)
je 0xba468
movq -0x40(%rbp), %rdi
callq 0x171700
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xfbd61(%rip), %rsi     # 0x1b615a
movl $0x5, %edx
callq 0x1715e0
movq -0x10(%rbp), %rax
cmpl $0x2, 0x4(%rax)
jb 0xba428
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0x104edd(%rip), %rsi    # 0x1bf2f9
movl $0x5, %edx
callq 0x1715e0
jmp 0xba441
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xf28d0(%rip), %rsi     # 0x1acd07
movl $0x5, %edx
callq 0x1715e0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq (%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
xorl %ecx, %ecx
callq 0x15d2c0
movq -0x18(%rbp), %rax
movq (%rax), %rax
movb $0x1, 0x8(%rax)
jmp 0xba494
movq -0x10(%rbp), %rax
cmpl $0x2, 0x4(%rax)
jb 0xba483
movq -0x18(%rbp), %rax
leaq 0x104e7c(%rip), %rcx    # 0x1bf2f9
movq %rcx, 0x10(%rax)
jmp 0xba492
movq -0x18(%rbp), %rax
leaq 0xf2879(%rip), %rcx     # 0x1acd07
movq %rcx, 0x10(%rax)
jmp 0xba494
movl $0x1, -0x2c(%rbp)
movq -0x40(%rbp), %rdi
callq 0x171750
movq -0x38(%rbp), %rcx
subq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl -0x2c(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)