// File: /workspace/github_c_makefile_star2_O2/jsummers[P]deark/modules/asf.c
// Function: handler_ESP
static void handler_ESP(deark *c, lctx *d, struct handler_params *hp)
{
	i64 pos = hp->dpos;
	i64 name_count, pes_count;
	i64 k;
	i64 x, xlen;
	i64 bytes_remaining;
	int saved_indent_level;
	u8 guid_raw[16];
	char guid_string[50];

	de_dbg_indent_save(c, &saved_indent_level);
	if(hp->dlen<64) goto done;

	x = de_geti64le(pos);
	de_dbg(c, "start time: %"I64_FMT, x);
	pos += 8;
	x = de_geti64le(pos);
	de_dbg(c, "end time: %"I64_FMT, x);
	pos += 8;

	x = de_getu32le_p(&pos);
	de_dbg(c, "data bitrate: %u", (unsigned int)x);
	x = de_getu32le_p(&pos);
	de_dbg(c, "buffer size: %u", (unsigned int)x);
	x = de_getu32le_p(&pos);
	de_dbg(c, "initial buffer fullness: %u", (unsigned int)x);
	x = de_getu32le_p(&pos);
	de_dbg(c, "alt data bitrate: %u", (unsigned int)x);
	x = de_getu32le_p(&pos);
	de_dbg(c, "alt buffer size: %u", (unsigned int)x);
	x = de_getu32le_p(&pos);
	de_dbg(c, "alt initial buffer fullness: %u", (unsigned int)x);
	x = de_getu32le_p(&pos);
	de_dbg(c, "max object size: %u", (unsigned int)x);
	x = de_getu32le_p(&pos);
	de_dbg(c, "flags: 0x%08x", (unsigned int)x);

	x = de_getu16le_p(&pos);
	de_dbg(c, "stream number: %d", (int)x);
	x = de_getu16le_p(&pos);
	de_dbg(c, "language id index: %d", (int)x);
	x = de_geti64le(pos);
	de_dbg(c, "average time per frame: %"I64_FMT, x);
	pos += 8;

	name_count = de_getu16le_p(&pos);
	de_dbg(c, "name count: %d", (int)name_count);
	pes_count = de_getu16le_p(&pos);
	de_dbg(c, "payload ext. system count: %d", (int)pes_count);

	// Stream names (TODO)
	for(k=0; k<name_count; k++) {
		if(pos+4 > hp->dpos+hp->dlen) goto done;
		de_dbg(c, "name[%d] at %"I64_FMT, (int)k, pos);
		pos += 2; // language id index
		xlen = de_getu16le_p(&pos);
		pos += xlen;
	}

	// Payload extension systems
	for(k=0; k<pes_count; k++) {
		if(pos+22 > hp->dpos+hp->dlen) {
			goto done;
		}
		de_dbg(c, "payload ext. system[%d] at %"I64_FMT, (int)k, pos);
		de_dbg_indent(c, 1);

		read_and_render_guid(c->infile, guid_raw, pos, guid_string, sizeof(guid_string));
		de_dbg(c, "ext. system id: {%s} (%s)", guid_string, get_uuid_name(guid_raw));
		pos += 16;

		x = de_getu16le_p(&pos);
		de_dbg(c, "ext. data size: %d", (int)x);

		xlen = de_getu32le_p(&pos);
		de_dbg(c, "payload ext. system info length: %d", (int)xlen);

		if(pos+xlen > hp->dpos+hp->dlen) {
			goto done;
		}
		if(xlen>0) {
			de_dbg(c, "[%d bytes of payload ext. system info at %"I64_FMT, (int)xlen, pos);
			de_dbg_indent(c, 1);
			de_dbg_hexdump(c, c->infile, pos, xlen, 256, NULL, 0x1);
			de_dbg_indent(c, -1);
		}
		pos += xlen;
		de_dbg_indent(c, -1);
	}

	bytes_remaining = hp->dpos + hp->dlen - pos;
	// There is an optional Stream Properties object here, but the spec seems
	// less than clear about how to tell whether it is present.
	if(bytes_remaining>24+54) {
		do_object_sequence(c, d, pos, bytes_remaining, hp->level+1, 1, 1);
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %r15
movq %rsi, 0x28(%rsp)
movq %rdi, %rbx
movq 0x10(%rdx), %r14
movq %r14, 0x10(%rsp)
leaq 0x24(%rsp), %rsi
callq 0xdebae
cmpq $0x40, 0x18(%r15)
jge 0x1f0d5
movl 0x24(%rsp), %esi
movq %rbx, %rdi
callq 0xdebb7
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xe418b
leaq 0xe6789(%rip), %rsi     # 0x105871
xorl %r13d, %r13d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
leaq 0x8(%r14), %rsi
movq 0x18(%rbx), %rdi
callq 0xe418b
leaq 0xe6775(%rip), %rsi     # 0x105881
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq $0x10, %r14
leaq 0x10(%rsp), %r12
movq %r14, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe40bf
leaq 0xe675a(%rip), %rsi     # 0x105893
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe40bf
leaq 0xe6750(%rip), %rsi     # 0x1058a8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe40bf
leaq 0xe6745(%rip), %rsi     # 0x1058bc
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe40bf
leaq 0xe66f9(%rip), %rsi     # 0x10588f
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe40bf
leaq 0xe66ef(%rip), %rsi     # 0x1058a4
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe40bf
leaq 0xe66e4(%rip), %rsi     # 0x1058b8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe40bf
leaq 0xe66e5(%rip), %rsi     # 0x1058d8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe40bf
leaq 0xfa41c(%rip), %rsi     # 0x11962e
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3fc4
leaq 0xe65d8(%rip), %rsi     # 0x105809
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3fc4
leaq 0xe669c(%rip), %rsi     # 0x1058ec
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq (%r12), %rsi
callq 0xe418b
leaq 0xe6692(%rip), %rsi     # 0x105902
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xde896
addq $0x8, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3fc4
movq %rax, %r14
leaq 0xe6686(%rip), %rsi     # 0x10591e
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3fc4
leaq 0xe6675(%rip), %rsi     # 0x10592d
movq %rbx, %rdi
movq %rax, 0x18(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
testq %r14, %r14
cmovleq %r13, %r14
leaq 0xe6674(%rip), %rbp     # 0x10594b
xorl %r13d, %r13d
cmpq %r13, %r14
je 0x1f325
movq 0x10(%rsp), %rcx
leaq 0x4(%rcx), %rax
movq 0x18(%r15), %rdx
addq 0x10(%r15), %rdx
cmpq %rdx, %rax
jg 0x1f0ba
movq %rbx, %rdi
movq %rbp, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0xde896
addq $0x2, 0x10(%rsp)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe3fc4
addq %rax, 0x10(%rsp)
incq %r13
jmp 0x1f2da
xorl %eax, %eax
movq 0x18(%rsp), %rcx
testq %rcx, %rcx
cmovleq %rax, %rcx
movq %rcx, 0x18(%rsp)
pushq $-0x1
popq %rbp
xorl %r13d, %r13d
cmpq %r13, 0x18(%rsp)
je 0x1f4a3
movq 0x10(%rsp), %rcx
leaq 0x16(%rcx), %rax
movq 0x18(%r15), %rdx
addq 0x10(%r15), %rdx
cmpq %rdx, %rax
jg 0x1f0ba
movq %rbx, %rdi
leaq 0xe65ee(%rip), %rsi     # 0x10595b
movl %r13d, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rdx
leaq 0x30(%rsp), %r12
movq %r12, %rsi
movq %r15, %r14
movl %ebp, %r15d
leaq 0x40(%rsp), %rbp
movq %rbp, %rcx
callq 0x1decd
movq %r12, %rdi
callq 0x1f682
movq %rbx, %rdi
leaq 0xe65c2(%rip), %rsi     # 0x10597a
movq %rbp, %rdx
movl %r15d, %ebp
movq %r14, %r15
movq %rax, %rcx
xorl %eax, %eax
callq 0xde896
addq $0x10, 0x10(%rsp)
movq 0x18(%rbx), %rdi
leaq 0x10(%rsp), %r12
movq %r12, %rsi
callq 0xe3fc4
movq %rbx, %rdi
leaq 0xe65a8(%rip), %rsi     # 0x105994
movl %eax, %edx
xorl %eax, %eax
callq 0xde896
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xe40bf
movq %rax, %r12
movq %rbx, %rdi
leaq 0xe6599(%rip), %rsi     # 0x1059a7
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
movq 0x10(%rsp), %rcx
leaq (%rcx,%r12), %rax
movq 0x18(%r14), %rdx
addq 0x10(%r14), %rdx
cmpq %rdx, %rax
jg 0x1f0ba
testq %r12, %r12
jle 0x1f48c
movq %rbx, %rdi
leaq 0xe658a(%rip), %rsi     # 0x1059cb
movl %r12d, %edx
xorl %eax, %eax
callq 0xde896
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0xdeba7
movq 0x18(%rbx), %rsi
movq 0x10(%rsp), %rdx
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %rbx, %rdi
movq %r12, %rcx
xorl %r9d, %r9d
callq 0xded3a
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
addq 0x10(%rsp), %r12
movq %r12, %rax
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
movl %ebp, %esi
callq 0xdeba7
incq %r13
jmp 0x1f33e
movq 0x18(%r15), %rcx
addq 0x10(%r15), %rcx
movq 0x10(%rsp), %rdx
subq %rdx, %rcx
cmpq $0x4f, %rcx
jl 0x1f0ba
movl 0x20(%r15), %r8d
incl %r8d
movq $0x1, (%rsp)
pushq $0x1
popq %r9
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0x1dc3a
jmp 0x1f0ba