// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/asf.c
// Function: handler_ScriptCommand
static void handler_ScriptCommand(deark *c, lctx *d, struct handler_params *hp)
{
	i64 cmd_count, cmd_type_count;
	i64 pos = hp->dpos;
	i64 k;
	de_ucstring *s = NULL;
	int saved_indent_level;

	de_dbg_indent_save(c, &saved_indent_level);
	if(hp->dlen<20) goto done;
	pos += 16; // Reserved GUID

	cmd_count = de_getu16le_p(&pos);
	de_dbg(c, "commands count: %d", (int)cmd_count);

	cmd_type_count = de_getu16le_p(&pos);
	de_dbg(c, "command types count: %d", (int)cmd_type_count);

	s = ucstring_create(c);

	for(k=0; k<cmd_type_count; k++) {
		i64 type_name_len;

		if(pos+2 > hp->dpos+hp->dlen) goto done;
		de_dbg(c, "command type[%d] at %"I64_FMT, (int)k, pos);
		de_dbg_indent(c, 1);

		type_name_len = de_getu16le_p(&pos);

		ucstring_empty(s);
		dbuf_read_to_ucstring_n(c->infile, pos, type_name_len*2, DE_DBG_MAX_STRLEN*2, s,
			0, DE_ENCODING_UTF16LE);
		ucstring_truncate_at_NUL(s);
		de_dbg(c, "name: \"%s\"", ucstring_getpsz_d(s));
		pos += type_name_len*2;

		de_dbg_indent(c, -1);
	}

	for(k=0; k<cmd_count; k++) {
		i64 cmd_name_len;
		i64 n;

		if(pos+8 > hp->dpos+hp->dlen) goto done;
		de_dbg(c, "command[%d] at %"I64_FMT, (int)k, pos);
		de_dbg_indent(c, 1);

		n = de_getu32le_p(&pos);
		de_dbg(c, "presentation time: %u ms", (unsigned int)n);

		n = de_getu16le_p(&pos);
		de_dbg(c, "type index: %d", (int)n);
			
		cmd_name_len = de_getu16le_p(&pos);

		ucstring_empty(s);
		dbuf_read_to_ucstring_n(c->infile, pos, cmd_name_len*2, DE_DBG_MAX_STRLEN*2, s,
			0, DE_ENCODING_UTF16LE);
		ucstring_truncate_at_NUL(s);
		de_dbg(c, "name: \"%s\"", ucstring_getpsz_d(s));
		pos += cmd_name_len*2;

		de_dbg_indent(c, -1);
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
	ucstring_destroy(s);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r14
movq %rdi, %rbx
movq 0x10(%rdx), %r15
movq %r15, 0x10(%rsp)
leaq 0x24(%rsp), %rsi
callq 0xdebae
cmpq $0x14, 0x18(%r14)
jge 0x1e767
xorl %r12d, %r12d
movl 0x24(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
movq %r12, %rdi
callq 0xeaf3c
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq $0x10, %r15
leaq 0x10(%rsp), %r12
movq %r15, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3fc4
leaq 0xe6eca(%rip), %rsi     # 0x105651
xorl %r15d, %r15d
movq %rbx, %rdi
movq %rax, 0x18(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3fc4
movq %rax, %rbp
leaq 0xe6eb3(%rip), %rsi     # 0x105664
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
callq 0xeac74
movq %rax, %r12
testq %rbp, %rbp
cmovleq %r15, %rbp
xorl %r15d, %r15d
cmpq %r15, %rbp
je 0x1e88f
movq 0x10(%rsp), %rcx
leaq 0x2(%rcx), %rax
movq 0x18(%r14), %rdx
addq 0x10(%r14), %rdx
cmpq %rdx, %rax
jg 0x1e744
movq %rbx, %rdi
leaq 0xe6e7d(%rip), %rsi     # 0x10567c
movl %r15d, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0xe3fc4
movq %rax, %r13
movq %r12, %rdi
callq 0xeac85
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
addq %r13, %r13
movl $0x3, (%rsp)
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r13, %rdx
movq %r12, %r8
xorl %r9d, %r9d
callq 0xe4ced
movq %r12, %rdi
callq 0xeacc0
movq %r12, %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0xf6d4e(%rip), %rsi     # 0x1155bb
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq %r13, 0x10(%rsp)
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
incq %r15
jmp 0x1e7d2
xorl %eax, %eax
movq 0x18(%rsp), %rcx
testq %rcx, %rcx
cmovleq %rax, %rcx
movq %rcx, 0x18(%rsp)
leaq 0x10(%rsp), %r13
xorl %ebp, %ebp
cmpq %rbp, 0x18(%rsp)
je 0x1e744
movq 0x10(%rsp), %rcx
leaq 0x8(%rcx), %rax
movq 0x18(%r14), %rdx
addq 0x10(%r14), %rdx
cmpq %rdx, %rax
jg 0x1e744
movq %rbx, %rdi
leaq 0xe6dbc(%rip), %rsi     # 0x105694
movl %ebp, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe40bf
movq %rbx, %rdi
leaq 0xe6da5(%rip), %rsi     # 0x1056a7
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3fc4
movq %rbx, %rdi
leaq 0xe6d9f(%rip), %rsi     # 0x1056c0
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xe3fc4
movq %rax, %r15
movq %r12, %rdi
callq 0xeac85
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
addq %r15, %r15
movl $0x3, (%rsp)
movl $0x3e8, %ecx            # imm = 0x3E8
movq %r15, %rdx
movq %r12, %r8
xorl %r9d, %r9d
callq 0xe4ced
movq %r12, %rdi
callq 0xeacc0
movq %r12, %rdi
callq 0xeb877
movq %rbx, %rdi
leaq 0xf6c3a(%rip), %rsi     # 0x1155bb
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq %r15, 0x10(%rsp)
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0xdeba7
incq %rbp
jmp 0x1e8a9