// File: /workspace/github_c_makefile_star2_O1/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), %rax
movq %rax, 0x10(%rsp)
leaq 0x1c(%rsp), %rsi
callq 0xe958c
cmpq $0x14, 0x18(%r14)
jge 0x1ebcd
xorl %r12d, %r12d
jmp 0x1edfe
leaq 0x10(%rsp), %r15
addq $0x10, (%r15)
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
leaq 0xf3a78(%rip), %rsi     # 0x112661
movq %rbx, %rdi
movq %rax, 0x20(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0xef1ed
movq %rax, %r13
leaq 0xf3a64(%rip), %rsi     # 0x112674
movq %rbx, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
callq 0xf6870
movq %rax, %r12
testq %r13, %r13
jle 0x1ecf0
xorl %r15d, %r15d
movq 0x10(%rsp), %rcx
leaq 0x2(%rcx), %rax
movq 0x18(%r14), %rdx
addq 0x10(%r14), %rdx
cmpq %rdx, %rax
jg 0x1edfe
movq %rbx, %rdi
leaq 0xf3a34(%rip), %rsi     # 0x11268c
movl %r15d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %rsi
callq 0xef1ed
movq %rax, %rbp
movq %r12, %rdi
callq 0xf6883
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 0xf0203
movq %r12, %rdi
callq 0xf68c1
movq %r12, %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0x1038ab(%rip), %rsi    # 0x122573
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq %rbp, 0x10(%rsp)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
incq %r15
cmpq %r15, %r13
jne 0x1ec34
cmpq $0x0, 0x20(%rsp)
jle 0x1edfe
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 0x1edfe
movq %rbx, %rdi
leaq 0xf397c(%rip), %rsi     # 0x1126a4
movl %r13d, %edx
xorl %eax, %eax
callq 0xe9226
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe9585
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xef3a0
movq %rbx, %rdi
leaq 0xf3962(%rip), %rsi     # 0x1126b7
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xef1ed
movq %rbx, %rdi
leaq 0xf395c(%rip), %rsi     # 0x1126d0
movl %eax, %edx
xorl %eax, %eax
callq 0xe9226
movq 0x18(%rbx), %rdi
movq %rbp, %rsi
callq 0xef1ed
movq %rax, %r15
movq %r12, %rdi
callq 0xf6883
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 0xf0203
movq %r12, %rdi
callq 0xf68c1
movq %r12, %rdi
callq 0xf7557
movq %rbx, %rdi
leaq 0x10379f(%rip), %rsi    # 0x122573
movq %rax, %rdx
xorl %eax, %eax
callq 0xe9226
addq %r15, 0x10(%rsp)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe9585
incq %r13
cmpq %r13, 0x20(%rsp)
jne 0x1ed04
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xe9595
movq %r12, %rdi
callq 0xf6bb0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq