// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/amigaicon.c
// Function: do_one_tooltype
static void do_one_tooltype(deark *c, lctx *d, i64 tpos, i64 tlen)
{
	int newicons_num;
	i64 n;
	struct de_stringreaderdata *ttstr = NULL;

	n = de_min_int(tlen, 64);
	ttstr = dbuf_read_string(c->infile, tpos, n, n, 0, DE_ENCODING_ASCII);
	de_dbg(c, "data: \"%s\"", ucstring_getpsz_d(ttstr->str));

	// The rest of this function is for identifying and recording NewIcons data.

	if(tlen<5) {
		// Too small to contain NewIcons data.
		goto done;
	}

	newicons_num = -1;

	if(ttstr->sz[0]=='I' && ttstr->sz[1]=='M' && ttstr->sz[3]=='=') {
		if(ttstr->sz[2]=='1') newicons_num = 0;
		else if(ttstr->sz[2]=='2') newicons_num = 1;
	}
	if(newicons_num == -1) {
		goto done;
	}

	d->has_newicons = 1;

	// Write NewIcons data to membufs, for later decoding.

	if(!d->newicons_data[newicons_num]) {
		de_dbg(c, "NewIcons data [%d] starts at %"I64_FMT, newicons_num, tpos);
		d->newicons_data[newicons_num] = dbuf_create_membuf(c, 2048, 0);
		// The data we copy includes the terminating NUL.
	}
	else {
		de_dbg2(c, "NewIcons data [%d] continues at %"I64_FMT, newicons_num, tpos);
	}
	dbuf_copy(c->infile, tpos+4, tlen-4, d->newicons_data[newicons_num]);

done:
	de_destroy_stringreaderdata(c, ttstr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x20(%rbp), %rdi
movl $0x40, %esi
callq 0x15ccf0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x30(%rbp), %rcx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x1664c0
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0x40(%rbp), %rdi
movq %rax, %rdx
leaq 0x18ca49(%rip), %rsi    # 0x1aba64
movb $0x0, %al
callq 0x15b0d0
cmpq $0x5, -0x20(%rbp)
jge 0x1f02e
jmp 0x1f141
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x49, %eax
jne 0x1f09d
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movsbl 0x1(%rax), %eax
cmpl $0x4d, %eax
jne 0x1f09d
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movsbl 0x3(%rax), %eax
cmpl $0x3d, %eax
jne 0x1f09d
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movsbl 0x2(%rax), %eax
cmpl $0x31, %eax
jne 0x1f081
movl $0x0, -0x24(%rbp)
jmp 0x1f09b
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movsbl 0x2(%rax), %eax
cmpl $0x32, %eax
jne 0x1f099
movl $0x1, -0x24(%rbp)
jmp 0x1f09b
jmp 0x1f09d
cmpl $-0x1, -0x24(%rbp)
jne 0x1f0a8
jmp 0x1f141
movq -0x10(%rbp), %rax
movl $0x1, 0x38(%rax)
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpq $0x0, 0x40(%rax,%rcx,8)
jne 0x1f0fe
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %edx
movq -0x18(%rbp), %rcx
leaq 0x17e651(%rip), %rsi    # 0x19d726
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x800, %esi            # imm = 0x800
xorl %edx, %edx
callq 0x168020
movq %rax, %rdx
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq %rdx, 0x40(%rax,%rcx,8)
jmp 0x1f117
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %edx
movq -0x18(%rbp), %rcx
leaq 0x17e637(%rip), %rsi    # 0x19d747
movb $0x0, %al
callq 0x15b350
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x4, %rsi
movq -0x20(%rbp), %rdx
subq $0x4, %rdx
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq 0x40(%rax,%rcx,8), %rcx
callq 0x166070
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x166830
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)