// File: /workspace/github_c_makefile_star2_O3/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), %r12
movq %r12, 0x10(%rsp)
leaq 0x1c(%rsp), %rsi
callq 0xe8a1c
cmpq $0x14, 0x18(%r14)
jge 0x1eca8
xorl %r12d, %r12d
jmp 0x1eedc
addq $0x10, %r12
leaq 0x10(%rsp), %r15
movq %r12, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeebeb
leaq 0xf39aa(%rip), %rsi     # 0x112671
movq %rbx, %rdi
movq %rax, 0x20(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xeebeb
movq %rax, %r13
leaq 0xf3996(%rip), %rsi     # 0x112684
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
callq 0xf6410
movq %rax, %r12
testq %r13, %r13
jle 0x1edce
xorl %r15d, %r15d
movq 0x10(%rsp), %rcx
leaq 0x2(%rcx), %rax
movq 0x18(%r14), %rdx
addq 0x10(%r14), %rdx
cmpq %rdx, %rax
jg 0x1eedc
movq %rbx, %rdi
leaq 0xf3966(%rip), %rsi     # 0x11269c
movl %r15d, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0xeebeb
movq %rax, %rbp
movq %r12, %rdi
callq 0xf6423
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rsi
addq %rbp, %rbp
movl $0x3, (%rsp)
movl $0x3e8, %ecx            # imm = 0x3E8
movq %rbp, %rdx
movq %r12, %r8
xorl %r9d, %r9d
callq 0xefc2a
movq %r12, %rdi
callq 0xf6461
movq %r12, %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0x1039d5(%rip), %rsi    # 0x12277b
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq %rbp, 0x10(%rsp)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
incq %r15
cmpq %r15, %r13
jne 0x1ed12
cmpq $0x0, 0x20(%rsp)
jle 0x1eedc
leaq 0x10(%rsp), %rbp
xorl %r13d, %r13d
movq 0x10(%rsp), %rcx
leaq 0x8(%rcx), %rax
movq 0x18(%r14), %rdx
addq 0x10(%r14), %rdx
cmpq %rdx, %rax
jg 0x1eedc
movq %rbx, %rdi
leaq 0xf38ae(%rip), %rsi     # 0x1126b4
movl %r13d, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeed83
movq %rbx, %rdi
leaq 0xf3894(%rip), %rsi     # 0x1126c7
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeebeb
movq %rbx, %rdi
leaq 0xf388e(%rip), %rsi     # 0x1126e0
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xeebeb
movq %rax, %r15
movq %r12, %rdi
callq 0xf6423
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 0xefc2a
movq %r12, %rdi
callq 0xf6461
movq %r12, %rdi
callq 0xf70f6
movq %rbx, %rdi
leaq 0x1038c9(%rip), %rsi    # 0x12277b
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq %r15, 0x10(%rsp)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
incq %r13
cmpq %r13, 0x20(%rsp)
jne 0x1ede2
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
movq %r12, %rdi
callq 0xf6753
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq