// File: /workspace/github_c_makefile_star2_O1/jsummers[P]deark/modules/comicchat.c
// Function: de_run_comicchat
static void de_run_comicchat(deark *c, de_module_params *mparams)
{
	i64 pos = 0;
	lctx *d = NULL;
	const char *tstr;

	d = de_malloc(c, sizeof(lctx));
	d->char_name = ucstring_create(c);
	d->tmpstr = ucstring_create(c);
	d->input_encoding = de_get_input_encoding(c, NULL, DE_ENCODING_WINDOWS1252);
	d->opt_applymasks = de_get_ext_option_bool(c, "comicchat:applymasks", 1);
	d->prefer_bmp_output = (u8)de_get_ext_option_bool(c, "comicchat:tobmp", 0);

	de_dbg(c, "header at %"I64_FMT, pos);
	de_dbg_indent(c, 1);
	pos += 2;
	d->fmt_code = (UI)de_getu16le_p(&pos);
	d->major_ver = (UI)de_getu16le_p(&pos);
	if(d->major_ver==1) tstr = "v1.0-2.1";
	else if(d->major_ver==2) tstr = "v2.5";
	else tstr = "?";
	de_dbg(c, "fmt ver: %u (%s)", d->major_ver, tstr);
	if(d->major_ver==2 && d->fmt_code==3) tstr = " (BGB)";
	else tstr = "";
	de_dbg(c, "fmt subtype: %u%s", d->fmt_code, tstr);
	de_dbg_indent(c, -1);

	d->images_seen = de_inthashtable_create(c);
	while(1) {
		comicchat_read_chunk(c, d, pos);
		if(d->stopflag || d->last_chunklen==0) goto done;
		pos += d->last_chunklen;
	}

done:
	if(d) {
		ucstring_destroy(d->char_name);
		ucstring_destroy(d->tmpstr);
		de_inthashtable_destroy(c, d->images_seen);
		de_free(c, d);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x18(%rsp), %r12
movq $0x0, (%r12)
movl $0x38, %esi
callq 0xe969b
movq %rax, %r15
movq %rax, %r14
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0x28(%r15)
movq %rbx, %rdi
callq 0xf6870
movq %rax, 0x30(%r15)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0xeb7d1
movl %eax, (%r15)
leaq 0xc309c(%rip), %rsi     # 0x12337a
movq %rbx, %rdi
movl $0x1, %edx
callq 0xea727
movb %al, 0x5(%r15)
leaq 0xc3099(%rip), %rsi     # 0x12338f
movq %rbx, %rdi
xorl %edx, %edx
callq 0xea727
movb %al, 0x6(%r15)
movq (%r12), %rdx
leaq 0xc2e90(%rip), %rsi     # 0x12319f
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
addq $0x2, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef1ed
movl %eax, 0x8(%r15)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xef1ed
movl %eax, 0xc(%r15)
cmpl $0x2, %eax
leaq 0xd083e(%rip), %rdx     # 0x130b93
leaq 0xcbb0d(%rip), %rcx     # 0x12be69
cmovneq %rcx, %rdx
cmpl $0x1, %eax
leaq 0xc3035(%rip), %rcx     # 0x12339f
cmovneq %rdx, %rcx
leaq 0xc3033(%rip), %rsi     # 0x1233a8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
cmpl $0x2, 0xc(%r15)
jne 0x60398
cmpl $0x3, 0x8(%r14)
jne 0x60398
leaq 0xc3023(%rip), %rcx     # 0x1233b9
jmp 0x6039f
leaq 0xe4831(%rip), %rcx     # 0x144bd0
movl 0x8(%r14), %edx
leaq 0xc3016(%rip), %rsi     # 0x1233c0
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
movq %rbx, %rdi
callq 0xeb85a
movq %rax, 0x10(%r14)
addq $0x20, %r15
movq 0x18(%rsp), %rbp
movq %r12, 0x20(%rsp)
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0xe958c
movl $0x18, %esi
movq %rbx, %rdi
callq 0xe969b
movq %rax, %r13
movq %rbp, 0x8(%rax)
movq %r12, 0x18(%r14)
leaq 0x2(%rbp), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jg 0x606c3
movq %rbp, %rsi
callq 0xef1ca
movl %eax, (%r13)
leal -0x1(%rax), %ecx
cmpl $0xb, %ecx
ja 0x60449
leaq 0xc2e70(%rip), %rdx     # 0x1232a0
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
leaq 0xcba2b(%rip), %r8      # 0x12be69
jmpq *%rcx
leaq 0xc302b(%rip), %r8      # 0x123472
jmp 0x604c1
leal -0x100(%rax), %ecx
leaq 0xcba13(%rip), %r8      # 0x12be69
cmpl $0x7, %ecx
ja 0x604c1
leaq 0xc2e6e(%rip), %rdx     # 0x1232d0
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
leaq 0xcb9f9(%rip), %r8      # 0x12be69
jmpq *%rcx
leaq 0xc2ff0(%rip), %r8      # 0x123469
jmp 0x604c1
leaq 0xc2ffb(%rip), %r8      # 0x12347d
jmp 0x604c1
leaq 0xc2f66(%rip), %r8      # 0x1233f1
jmp 0x604c1
leaq 0xc2f7d(%rip), %r8      # 0x123411
jmp 0x604c1
leaq 0xc2fff(%rip), %r8      # 0x12349c
jmp 0x604c1
leaq 0xc2f55(%rip), %r8      # 0x1233fb
jmp 0x604c1
leaq 0xc2ffa(%rip), %r8      # 0x1234a9
jmp 0x604c1
leaq 0xc2f54(%rip), %r8      # 0x12340c
jmp 0x604c1
leaq 0xc2fce(%rip), %r8      # 0x12348f
movq 0x8(%r13), %rdx
movq %rbx, %rdi
leaq 0xc2f03(%rip), %rsi     # 0x1233d2
movl %eax, %ecx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movl (%r13), %eax
leal -0x1(%rax), %ecx
cmpl $0xb, %ecx
ja 0x606fc
leaq 0xc2df4(%rip), %rdx     # 0x1232f0
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq $0x4, 0x10(%r13)
jmp 0x6065b
movq $0x2, 0x10(%r13)
jmp 0x6067a
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x2, %rsi
callq 0xef1ca
leaq (%rax,%rax,4), %rcx
leaq (%rcx,%rcx,4), %rcx
addq $0x4, %rcx
movq %rcx, 0x10(%r13)
movl $0x19, %ecx
jmp 0x6064a
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x2, %rsi
callq 0xef1ca
imulq $0x23, %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x10(%r13)
movl $0x23, %ecx
jmp 0x6064a
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x2, %rsi
callq 0xef1ca
imulq $0x2b, %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x10(%r13)
movl $0x2b, %ecx
jmp 0x6064a
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rdx
addq $0x2, %rdx
movl $0x1000, %ecx           # imm = 0x1000
xorl %esi, %esi
leaq 0x20(%rsp), %r8
callq 0xf0057
testl %eax, %eax
je 0x6065b
movq 0x20(%rsp), %rcx
movq 0x8(%r13), %rdx
subq %rdx, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x10(%r13)
addq $0x2, %rdx
decq %rcx
movq 0x28(%r14), %r8
movq %rbx, %rdi
movq %r14, %rsi
leaq 0xc2e08(%rip), %r9      # 0x1233f1
callq 0x6094d
jmp 0x6065b
movq $0x6, 0x10(%r13)
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x2, %rsi
callq 0xef37e
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rax, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x60a64
jmp 0x6065b
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x2, %rsi
callq 0xef1ca
movq %rax, %rcx
shlq $0x5, %rcx
addq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x10(%r13)
movl $0x21, %ecx
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rax, %r8
callq 0x609c3
movq 0x10(%r13), %rdx
cmpq $0x1, %rdx
jg 0x60681
movl (%r13), %edx
movq %rbx, %rdi
leaq 0xc2dbb(%rip), %rsi     # 0x12342e
xorl %eax, %eax
callq 0xe9df7
movb $0x1, 0x4(%r14)
jmp 0x606c3
movq %rbx, %rdi
leaq 0xc17d3(%rip), %rsi     # 0x121e5e
xorl %eax, %eax
callq 0xe9226
cmpl $0x3, (%rbx)
jl 0x606bb
movq 0x18(%rbx), %rsi
movq 0x8(%r13), %rdx
movq 0x10(%r13), %rcx
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %rbx, %rdi
xorl %r9d, %r9d
callq 0xe975a
movq 0x10(%r13), %rax
movq %rax, 0x18(%r14)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe9752
movl 0x14(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
cmpb $0x0, 0x4(%r14)
jne 0x607f5
movq 0x18(%r14), %rax
testq %rax, %rax
je 0x607f5
addq %rax, 0x18(%rsp)
jmp 0x603d4
andl $0xffffff00, %eax       # imm = 0xFFFFFF00
cmpl $0x100, %eax            # imm = 0x100
jne 0x6065b
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x2, %rsi
callq 0xef1ca
leaq 0x4(%rax), %rcx
movq %rcx, 0x10(%r13)
movl (%r13), %ecx
movl $0xffffff00, %edx       # imm = 0xFFFFFF00
addl %edx, %ecx
cmpl $0x7, %ecx
ja 0x6065b
leaq 0xc2be0(%rip), %rdx     # 0x123320
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x4, %rsi
jmp 0x60604
movq 0x8(%r13), %rdx
addq $0x4, %rdx
movq 0x30(%r14), %r8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
leaq 0xc2c85(%rip), %r9      # 0x1233fb
jmp 0x605e9
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x4, %rsi
callq 0xef37e
movq %rax, %rbp
addq %rax, (%r15)
movq %r15, %rdi
callq 0xec0d1
movq %rbx, %rdi
leaq 0xc2c72(%rip), %rsi     # 0x123416
movq %rbp, %rdx
xorl %eax, %eax
callq 0xe9226
jmp 0x6065b
movq 0x8(%r13), %rdx
addq $0x4, %rdx
movq 0x30(%r14), %r8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
leaq 0xc2c3d(%rip), %r9      # 0x12340c
jmp 0x605e9
movq 0x8(%r13), %rdx
addq $0x4, %rdx
movq 0x30(%r14), %r8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
leaq 0xc2c21(%rip), %r9      # 0x123411
jmp 0x605e9
movq 0x28(%r14), %rdi
callq 0xf6bb0
movq 0x30(%r14), %rdi
callq 0xf6bb0
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0xeb864
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe9752
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq