// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/gws.c
// Function: de_run_gws_thn
static void de_run_gws_thn(deark *c, de_module_params *mparams)
{
	struct gws_thn_ctx *d = NULL;
	de_bitmap *img = NULL;
	u8 v1, v2;
	i64 w, h;
	i64 pos;
	de_ucstring *s = NULL;

	d = de_malloc(c, sizeof(struct gws_thn_ctx));

	// This code is based on reverse engineering, and may be incorrect.
	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_WINDOWS1252);
	pos = 4;
	v1 = de_getbyte_p(&pos);
	v2 = de_getbyte_p(&pos);
	de_dbg(c, "version?: 0x%02x 0x%02x", (UI)v1, (UI)v2);

	s = ucstring_create(c);
	// For the text fields, the field size appears to be 129, but the software
	// only properly supports up to 127 non-NUL bytes.
	dbuf_read_to_ucstring(c->infile, 6, 127, s, DE_CONVFLAG_STOP_AT_NUL, d->input_encoding);
	if(s->len>0) de_dbg(c, "comments: \"%s\"", ucstring_getpsz_d(s));
	ucstring_empty(s);
	dbuf_read_to_ucstring(c->infile, 135, 127, s, DE_CONVFLAG_STOP_AT_NUL, d->input_encoding);
	if(s->len>0) de_dbg(c, "key words: \"%s\"", ucstring_getpsz_d(s));

	pos = 264;
	de_dbg(c, "image at %"I64_FMT, pos);
	w = 96;
	h = 96;

	// Set up the palette. There are two possible fixed palettes.
	if(v1==0) {
		gwsthn_makepal_orig(c, d);
	}
	else {
		gwsthn_makepal_new(c, d);
	}

	img = de_bitmap_create(c, w, h, 3);
	de_convert_image_paletted(c->infile, pos, 8, w, d->pal, img, 0);
	de_bitmap_write_to_file(img, NULL, DE_CREATEFLAG_FLIP_IMAGE);

	de_bitmap_destroy(img);
	ucstring_destroy(s);
	de_free(c, d);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movl $0x404, %esi            # imm = 0x404
callq 0x15b780
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x9, %edx
callq 0x15e4a0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq $0x4, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x165170
movb %al, -0x21(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x40(%rbp), %rsi
callq 0x165170
movb %al, -0x22(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x21(%rbp), %edx
movzbl -0x22(%rbp), %ecx
leaq 0x11f977(%rip), %rsi    # 0x1afa1e
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
callq 0x1711d0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x48(%rbp), %rcx
movq -0x18(%rbp), %rax
movl (%rax), %r9d
movl $0x6, %esi
movl $0x7f, %edx
movl $0x1, %r8d
callq 0x1669f0
movq -0x48(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jle 0x90114
movq -0x8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
callq 0x172650
movq -0x50(%rbp), %rdi
movq %rax, %rdx
leaq 0x11f929(%rip), %rsi    # 0x1afa36
movb $0x0, %al
callq 0x15b0d0
movq -0x48(%rbp), %rdi
callq 0x171210
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x48(%rbp), %rcx
movq -0x18(%rbp), %rax
movl (%rax), %r9d
movl $0x87, %esi
movl $0x7f, %edx
movl $0x1, %r8d
callq 0x1669f0
movq -0x48(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jle 0x90176
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
callq 0x172650
movq -0x58(%rbp), %rdi
movq %rax, %rdx
leaq 0x11f8d6(%rip), %rsi    # 0x1afa45
movb $0x0, %al
callq 0x15b0d0
movq $0x108, -0x40(%rbp)     # imm = 0x108
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rdx
leaq 0x12a1a1(%rip), %rsi    # 0x1ba32e
movb $0x0, %al
callq 0x15b0d0
movq $0x60, -0x30(%rbp)
movq $0x60, -0x38(%rbp)
movzbl -0x21(%rbp), %eax
cmpl $0x0, %eax
jne 0x901bc
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x90c90
jmp 0x901c9
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x90d80
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl $0x3, %ecx
callq 0x16b750
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x40(%rbp), %rsi
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %r8
addq $0x4, %r8
movq -0x20(%rbp), %r9
movl $0x8, %edx
xorl %eax, %eax
movl $0x0, (%rsp)
callq 0x16c520
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x4, %edx
callq 0x16afd0
movq -0x20(%rbp), %rdi
callq 0x16af60
movq -0x48(%rbp), %rdi
callq 0x171750
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x15b820
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)