// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x38
popq %rsi
callq 0xdecaf
movq %rax, %r14
movq %rbx, %rdi
callq 0xeac74
movq %rax, 0x28(%r14)
movq %rbx, %rdi
callq 0xeac74
movq %rax, 0x30(%r14)
pushq $0x9
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe08d2
movl %eax, (%r14)
leaq 0xb95b4(%rip), %rsi     # 0x11639a
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %edx
callq 0xdfae5
movb %al, 0x5(%r14)
leaq 0xb95b1(%rip), %rsi     # 0x1163af
movq %rbx, %rdi
xorl %edx, %edx
callq 0xdfae5
movb %al, 0x6(%r14)
leaq 0xb93ac(%rip), %rsi     # 0x1161bf
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
leaq 0x10(%rsp), %r15
movq $0x2, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
movl %eax, 0x8(%r14)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xe3fc4
movl %eax, 0xc(%r14)
cmpl $0x2, %eax
leaq 0xc6d8c(%rip), %rdx     # 0x123beb
leaq 0xc207b(%rip), %rcx     # 0x11eee1
cmovneq %rcx, %rdx
cmpl $0x1, %eax
leaq 0xb954b(%rip), %rcx     # 0x1163bf
cmovneq %rdx, %rcx
leaq 0xb9549(%rip), %rsi     # 0x1163c8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movl 0x8(%r14), %edx
movl 0xc(%r14), %eax
xorl $0x2, %eax
movl %edx, %esi
xorl $0x3, %esi
leaq 0xb9537(%rip), %rdi     # 0x1163d9
leaq 0xdadb7(%rip), %rcx     # 0x137c60
orl %eax, %esi
cmoveq %rdi, %rcx
leaq 0xb952a(%rip), %rsi     # 0x1163e0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xde896
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0xdeba7
movq %rbx, %rdi
callq 0xe0955
movq %rax, 0x10(%r14)
movq %r14, %rax
addq $0x20, %rax
movq %rax, 0x20(%rsp)
movq (%r15), %r15
leaq 0xc(%rsp), %r12
pushq $0x18
popq %r13
andq $0x0, 0x18(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0xdebae
movq %rbx, %rdi
movq %r13, %rsi
callq 0xdecaf
movq %rax, %rbp
movq %r15, 0x8(%rax)
andq $0x0, 0x18(%r14)
leaq 0x2(%r15), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jg 0x5d1bd
movq %r15, %rsi
callq 0xe3fa3
movl %eax, (%rbp)
leal -0x1(%rax), %ecx
cmpl $0xb, %ecx
ja 0x5cf5c
leaq 0xb937d(%rip), %rdx     # 0x1162c0
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
leaq 0xc1f90(%rip), %r8      # 0x11eee1
jmpq *%rcx
leaq 0xb9538(%rip), %r8      # 0x116492
jmp 0x5cfd4
leal -0x100(%rax), %ecx
leaq 0xc1f78(%rip), %r8      # 0x11eee1
cmpl $0x7, %ecx
ja 0x5cfd4
leaq 0xb937b(%rip), %rdx     # 0x1162f0
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
leaq 0xc1f5e(%rip), %r8      # 0x11eee1
jmpq *%rcx
leaq 0xb94fd(%rip), %r8      # 0x116489
jmp 0x5cfd4
leaq 0xb9508(%rip), %r8      # 0x11649d
jmp 0x5cfd4
leaq 0xb9473(%rip), %r8      # 0x116411
jmp 0x5cfd4
leaq 0xb948a(%rip), %r8      # 0x116431
jmp 0x5cfd4
leaq 0xb950c(%rip), %r8      # 0x1164bc
jmp 0x5cfd4
leaq 0xb9462(%rip), %r8      # 0x11641b
jmp 0x5cfd4
leaq 0xb9507(%rip), %r8      # 0x1164c9
jmp 0x5cfd4
leaq 0xb9461(%rip), %r8      # 0x11642c
jmp 0x5cfd4
leaq 0xb94db(%rip), %r8      # 0x1164af
movq 0x8(%rbp), %rdx
movq %rbx, %rdi
leaq 0xb9410(%rip), %rsi     # 0x1163f2
movl %eax, %ecx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movl (%rbp), %eax
leal -0x1(%rax), %ecx
cmpl $0xb, %ecx
ja 0x5d1fb
leaq 0xb9304(%rip), %rdx     # 0x116310
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq $0x4, 0x10(%rbp)
jmp 0x5d156
movq $0x2, 0x10(%rbp)
jmp 0x5d174
movq 0x18(%rbx), %rdi
movq 0x8(%rbp), %rsi
addq $0x2, %rsi
callq 0xe3fa3
imulq $0x19, %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x10(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
pushq $0x19
jmp 0x5d14d
movq 0x18(%rbx), %rdi
movq 0x8(%rbp), %rsi
addq $0x2, %rsi
callq 0xe3fa3
imulq $0x23, %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x10(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
pushq $0x23
jmp 0x5d14d
movq 0x18(%rbx), %rdi
movq 0x8(%rbp), %rsi
addq $0x2, %rsi
callq 0xe3fa3
imulq $0x2b, %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x10(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
pushq $0x2b
jmp 0x5d14d
movq 0x18(%rbx), %rdi
movq 0x8(%rbp), %rdx
addq $0x2, %rdx
movl $0x1000, %ecx           # imm = 0x1000
xorl %esi, %esi
leaq 0x18(%rsp), %r8
callq 0xe4b21
testl %eax, %eax
je 0x5d156
movq 0x18(%rsp), %rcx
movq 0x8(%rbp), %rdx
subq %rdx, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x10(%rbp)
addq $0x2, %rdx
decq %rcx
movq 0x28(%r14), %r8
movq %rbx, %rdi
movq %r14, %rsi
leaq 0xb930e(%rip), %r9      # 0x116411
callq 0x5d444
jmp 0x5d156
movq $0x6, 0x10(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
pushq $0x2
popq %rcx
callq 0x5d4b8
jmp 0x5d156
movq 0x18(%rbx), %rdi
movq 0x8(%rbp), %rsi
addq $0x2, %rsi
callq 0xe3fa3
imulq $0x21, %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x10(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
pushq $0x21
popq %rcx
movq %rax, %r8
callq 0x5d4f2
movq 0x10(%rbp), %rdx
cmpq $0x1, %rdx
jg 0x5d17b
movl (%rbp), %edx
movq %rbx, %rdi
leaq 0xb92e1(%rip), %rsi     # 0x11644e
xorl %eax, %eax
callq 0xdf2a5
movb $0x1, 0x4(%r14)
jmp 0x5d1bd
movq %rbx, %rdi
leaq 0xb7d21(%rip), %rsi     # 0x114ea6
xorl %eax, %eax
callq 0xde896
cmpl $0x3, (%rbx)
jl 0x5d1b5
movq 0x18(%rbx), %rsi
movq 0x8(%rbp), %rdx
movq 0x10(%rbp), %rcx
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %rbx, %rdi
xorl %r9d, %r9d
callq 0xded3a
movq 0x10(%rbp), %rax
movq %rax, 0x18(%r14)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0xded32
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
cmpb $0x0, 0x4(%r14)
jne 0x5d2f4
movq 0x18(%r14), %r15
testq %r15, %r15
je 0x5d2f4
addq 0x10(%rsp), %r15
movq %r15, 0x10(%rsp)
jmp 0x5ceef
andl $0xffffff00, %eax       # imm = 0xFFFFFF00
cmpl $0x100, %eax            # imm = 0x100
jne 0x5d156
movq 0x18(%rbx), %rdi
movq 0x8(%rbp), %rsi
addq $0x2, %rsi
callq 0xe3fa3
leaq 0x4(%rax), %rcx
movq %rcx, 0x10(%rbp)
movl (%rbp), %ecx
movl $0xffffff00, %edx       # imm = 0xFFFFFF00
addl %edx, %ecx
cmpl $0x7, %ecx
ja 0x5d156
leaq 0xb9102(%rip), %rdx     # 0x116340
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
pushq $0x4
jmp 0x5d11d
movq 0x8(%rbp), %rdx
addq $0x4, %rdx
movq 0x30(%r14), %r8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
leaq 0xb91a8(%rip), %r9      # 0x11641b
jmp 0x5d103
movq 0x18(%rbx), %rdi
movq 0x8(%rbp), %rsi
addq $0x4, %rsi
callq 0xe409f
movq %rax, %r15
movq 0x20(%rsp), %rdi
addq %rax, (%rdi)
callq 0xe10b1
movq %rbx, %rdi
leaq 0xb9193(%rip), %rsi     # 0x116436
movq %r15, %rdx
xorl %eax, %eax
callq 0xde896
jmp 0x5d156
movq 0x8(%rbp), %rdx
addq $0x4, %rdx
movq 0x30(%r14), %r8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
leaq 0xb915e(%rip), %r9      # 0x11642c
jmp 0x5d103
movq 0x8(%rbp), %rdx
addq $0x4, %rdx
movq 0x30(%r14), %r8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
leaq 0xb9142(%rip), %r9      # 0x116431
jmp 0x5d103
movq 0x28(%r14), %rdi
callq 0xeaf3c
movq 0x30(%r14), %rdi
callq 0xeaf3c
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0xe095f
movq %rbx, %rdi
movq %r14, %rsi
callq 0xded32
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq