// File: /workspace/github_c_makefile_star2_O3/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
movl $0x38, %esi
callq 0xe8b2b
movq %rax, %r14
movq %rbx, %rdi
callq 0xf6410
movq %rax, 0x28(%r14)
movq %rbx, %rdi
callq 0xf6410
movq %rax, 0x30(%r14)
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0xeb220
movl %eax, (%r14)
leaq 0xc33d2(%rip), %rsi     # 0x12355a
movq %rbx, %rdi
movl $0x1, %edx
callq 0xe9bd0
movb %al, 0x5(%r14)
leaq 0xc33cf(%rip), %rsi     # 0x12356f
movq %rbx, %rdi
xorl %edx, %edx
callq 0xe9bd0
movb %al, 0x6(%r14)
leaq 0xc31ca(%rip), %rsi     # 0x12337f
movq %rbx, %rdi
xorl %edx, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
leaq 0x10(%rsp), %r12
movq $0x2, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movl %eax, 0x8(%r14)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movl %eax, 0xc(%r14)
cmpl $0x2, %eax
leaq 0xd0cc9(%rip), %rdx     # 0x130ece
leaq 0xcbf45(%rip), %rcx     # 0x12c151
cmovneq %rcx, %rdx
cmpl $0x1, %eax
leaq 0xc3365(%rip), %rcx     # 0x12357f
cmovneq %rdx, %rcx
leaq 0xc3363(%rip), %rsi     # 0x123588
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movl 0x8(%r14), %edx
movl 0xc(%r14), %eax
xorl $0x2, %eax
movl %edx, %esi
xorl $0x3, %esi
leaq 0xc3351(%rip), %rdi     # 0x123599
leaq 0xe4e61(%rip), %rcx     # 0x1450b0
orl %eax, %esi
cmoveq %rdi, %rcx
leaq 0xc3344(%rip), %rsi     # 0x1235a0
movq %rbx, %rdi
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
movq %rbx, %rdi
callq 0xeb2a9
movq %rax, 0x10(%r14)
movq %r14, %rax
addq $0x20, %rax
movq %rax, 0x20(%rsp)
movq (%r12), %r15
leaq 0xc(%rsp), %r12
movq %rbp, 0x18(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0xe8a1c
movl $0x18, %esi
movq %rbx, %rdi
callq 0xe8b2b
movq %rax, %r13
movq %r15, 0x8(%rax)
movq %rbp, 0x18(%r14)
leaq 0x2(%r15), %rax
movq 0x18(%rbx), %rdi
cmpq 0x18(%rdi), %rax
jg 0x6057c
movq %r15, %rsi
callq 0xeebc8
movl %eax, (%r13)
leal -0x1(%rax), %ecx
cmpl $0xb, %ecx
ja 0x60302
leaq 0xc3197(%rip), %rdx     # 0x123480
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
leaq 0xcbe5a(%rip), %r8      # 0x12c151
jmpq *%rcx
leaq 0xc3352(%rip), %r8      # 0x123652
jmp 0x6037a
leal -0x100(%rax), %ecx
leaq 0xcbe42(%rip), %r8      # 0x12c151
cmpl $0x7, %ecx
ja 0x6037a
leaq 0xc3195(%rip), %rdx     # 0x1234b0
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
leaq 0xcbe28(%rip), %r8      # 0x12c151
jmpq *%rcx
leaq 0xc3317(%rip), %r8      # 0x123649
jmp 0x6037a
leaq 0xc3322(%rip), %r8      # 0x12365d
jmp 0x6037a
leaq 0xc328d(%rip), %r8      # 0x1235d1
jmp 0x6037a
leaq 0xc32a4(%rip), %r8      # 0x1235f1
jmp 0x6037a
leaq 0xc3326(%rip), %r8      # 0x12367c
jmp 0x6037a
leaq 0xc327c(%rip), %r8      # 0x1235db
jmp 0x6037a
leaq 0xc3321(%rip), %r8      # 0x123689
jmp 0x6037a
leaq 0xc327b(%rip), %r8      # 0x1235ec
jmp 0x6037a
leaq 0xc32f5(%rip), %r8      # 0x12366f
movq 0x8(%r13), %rdx
movq %rbx, %rdi
leaq 0xc322a(%rip), %rsi     # 0x1235b2
movl %eax, %ecx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movl (%r13), %eax
leal -0x1(%rax), %ecx
cmpl $0xb, %ecx
ja 0x605ba
leaq 0xc311b(%rip), %rdx     # 0x1234d0
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movq $0x4, 0x10(%r13)
jmp 0x60514
movq $0x2, 0x10(%r13)
jmp 0x60533
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x2, %rsi
callq 0xeebc8
leaq (%rax,%rax,4), %rcx
leaq (%rcx,%rcx,4), %rcx
addq $0x4, %rcx
movq %rcx, 0x10(%r13)
movl $0x19, %ecx
jmp 0x60503
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x2, %rsi
callq 0xeebc8
imulq $0x23, %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x10(%r13)
movl $0x23, %ecx
jmp 0x60503
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x2, %rsi
callq 0xeebc8
imulq $0x2b, %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x10(%r13)
movl $0x2b, %ecx
jmp 0x60503
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rdx
addq $0x2, %rdx
movl $0x1000, %ecx           # imm = 0x1000
xorl %esi, %esi
leaq 0x18(%rsp), %r8
callq 0xefa77
testl %eax, %eax
je 0x60514
movq 0x18(%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 0xc312f(%rip), %r9      # 0x1235d1
callq 0x6080d
jmp 0x60514
movq $0x6, 0x10(%r13)
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x2, %rsi
callq 0xeed61
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rax, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x60924
jmp 0x60514
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x2, %rsi
callq 0xeebc8
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 0x60883
movq 0x10(%r13), %rdx
cmpq $0x1, %rdx
jg 0x6053a
movl (%r13), %edx
movq %rbx, %rdi
leaq 0xc30e2(%rip), %rsi     # 0x12360e
xorl %eax, %eax
callq 0xe9295
movb $0x1, 0x4(%r14)
jmp 0x6057c
movq %rbx, %rdi
leaq 0xc1b22(%rip), %rsi     # 0x122066
xorl %eax, %eax
callq 0xe8617
cmpl $0x3, (%rbx)
jl 0x60574
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 0xe8bea
movq 0x10(%r13), %rax
movq %rax, 0x18(%r14)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xe8be2
movl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
cmpb $0x0, 0x4(%r14)
jne 0x606b5
movq 0x18(%r14), %r15
testq %r15, %r15
je 0x606b5
addq 0x10(%rsp), %r15
movq %r15, 0x10(%rsp)
jmp 0x60294
andl $0xffffff00, %eax       # imm = 0xFFFFFF00
cmpl $0x100, %eax            # imm = 0x100
jne 0x60514
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x2, %rsi
callq 0xeebc8
leaq 0x4(%rax), %rcx
movq %rcx, 0x10(%r13)
movl (%r13), %ecx
movl $0xffffff00, %edx       # imm = 0xFFFFFF00
addl %edx, %ecx
cmpl $0x7, %ecx
ja 0x60514
leaq 0xc2f02(%rip), %rdx     # 0x123500
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x4, %rsi
jmp 0x604bd
movq 0x8(%r13), %rdx
addq $0x4, %rdx
movq 0x30(%r14), %r8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
leaq 0xc2fa7(%rip), %r9      # 0x1235db
jmp 0x604a2
movq 0x18(%rbx), %rdi
movq 0x8(%r13), %rsi
addq $0x4, %rsi
callq 0xeed61
movq %rax, %r15
movq 0x20(%rsp), %rdi
addq %rax, (%rdi)
callq 0xebad2
movq %rbx, %rdi
leaq 0xc2f92(%rip), %rsi     # 0x1235f6
movq %r15, %rdx
xorl %eax, %eax
callq 0xe8617
jmp 0x60514
movq 0x8(%r13), %rdx
addq $0x4, %rdx
movq 0x30(%r14), %r8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
leaq 0xc2f5d(%rip), %r9      # 0x1235ec
jmp 0x604a2
movq 0x8(%r13), %rdx
addq $0x4, %rdx
movq 0x30(%r14), %r8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rcx
leaq 0xc2f41(%rip), %r9      # 0x1235f1
jmp 0x604a2
movq 0x28(%r14), %rdi
callq 0xf6753
movq 0x30(%r14), %rdi
callq 0xf6753
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0xeb2b3
movq %rbx, %rdi
movq %r14, %rsi
callq 0xe8be2
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq