// File: /workspace/github_c_makefile_star2_O3/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 0x1c(%rsp), %rsi
callq 0xe8a1c
cmpq $0x40, 0x18(%r15)
jge 0x1f615
movl 0x1c(%rsp), %esi
movq %rbx, %rdi
callq 0xe8a25
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0xeef09
leaq 0xf3269(%rip), %rsi     # 0x112891
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
leaq 0x8(%r14), %rsi
movq 0x18(%rbx), %rdi
callq 0xeef09
leaq 0xf3258(%rip), %rsi     # 0x1128a1
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq $0x10, %r14
leaq 0x10(%rsp), %r12
movq %r14, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeed83
leaq 0xf323d(%rip), %rsi     # 0x1128b3
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeed83
leaq 0xf3233(%rip), %rsi     # 0x1128c8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeed83
leaq 0xf3228(%rip), %rsi     # 0x1128dc
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeed83
leaq 0xf31dc(%rip), %rsi     # 0x1128af
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeed83
leaq 0xf31d2(%rip), %rsi     # 0x1128c4
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeed83
leaq 0xf31c7(%rip), %rsi     # 0x1128d8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeed83
leaq 0xf31c8(%rip), %rsi     # 0x1128f8
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeed83
leaq 0x1070df(%rip), %rsi    # 0x12682e
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
leaq 0xf30bb(%rip), %rsi     # 0x112829
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
leaq 0xf317f(%rip), %rsi     # 0x11290c
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq (%r12), %rsi
callq 0xeef09
leaq 0xf3175(%rip), %rsi     # 0x112922
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xe8617
addq $0x8, (%r12)
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
movq %rax, %r14
leaq 0xf3169(%rip), %rsi     # 0x11293e
movq %rbx, %rdi
movl %r14d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r12, %rsi
callq 0xeebeb
leaq 0xf3158(%rip), %rsi     # 0x11294d
movq %rbx, %rdi
movq %rax, 0x20(%rsp)
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
testq %r14, %r14
jle 0x1f86a
leaq 0x10(%rsp), %r13
movq (%r13), %rax
leaq 0xf3150(%rip), %rbp     # 0x11296b
xorl %r12d, %r12d
leaq 0x4(%rax), %rcx
movq 0x18(%r15), %rdx
addq 0x10(%r15), %rdx
cmpq %rdx, %rcx
jg 0x1f5fa
movq %rbx, %rdi
movq %rbp, %rsi
movl %r12d, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe8617
addq $0x2, 0x10(%rsp)
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeebeb
addq 0x10(%rsp), %rax
movq %rax, 0x10(%rsp)
incq %r12
cmpq %r12, %r14
jne 0x1f81e
cmpq $0x0, 0x20(%rsp)
jle 0x1f9d5
leaq 0x10(%rsp), %r13
xorl %ebp, %ebp
movq 0x10(%rsp), %rcx
leaq 0x16(%rcx), %rax
movq 0x18(%r15), %rdx
addq 0x10(%r15), %rdx
cmpq %rdx, %rax
jg 0x1f5fa
movq %rbx, %rdi
leaq 0xf30da(%rip), %rsi     # 0x11297b
movl %ebp, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rdi
movq 0x10(%rsp), %rdx
leaq 0x30(%rsp), %r14
movq %r14, %rsi
leaq 0x40(%rsp), %r12
movq %r12, %rcx
callq 0x1e3cf
movq %r14, %rdi
callq 0x1fb9d
movq %rbx, %rdi
leaq 0xf30b3(%rip), %rsi     # 0x11299a
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xe8617
addq $0x10, 0x10(%rsp)
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeebeb
movq %rbx, %rdi
leaq 0xf30a4(%rip), %rsi     # 0x1129b4
movl %eax, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x18(%rbx), %rdi
movq %r13, %rsi
callq 0xeed83
movq %rax, %r14
movq %rbx, %rdi
leaq 0xf3095(%rip), %rsi     # 0x1129c7
movl %r14d, %edx
xorl %eax, %eax
callq 0xe8617
movq 0x10(%rsp), %rcx
leaq (%rcx,%r14), %rax
movq 0x18(%r15), %rdx
addq 0x10(%r15), %rdx
cmpq %rdx, %rax
jg 0x1f5fa
testq %r14, %r14
jle 0x1f9b5
movq %rbx, %rdi
leaq 0xf3086(%rip), %rsi     # 0x1129eb
movl %r14d, %edx
xorl %eax, %eax
callq 0xe8617
movq %rbx, %rdi
movl $0x1, %esi
callq 0xe8a15
movq 0x18(%rbx), %rsi
movq 0x10(%rsp), %rdx
movl $0x1, (%rsp)
movl $0x100, %r8d            # imm = 0x100
movq %rbx, %rdi
movq %r14, %rcx
xorl %r9d, %r9d
callq 0xe8bea
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
addq 0x10(%rsp), %r14
movq %r14, %rax
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xe8a15
incq %rbp
cmpq %rbp, 0x20(%rsp)
jne 0x1f87d
movq 0x18(%r15), %rcx
addq 0x10(%r15), %rcx
movq 0x10(%rsp), %rdx
subq %rdx, %rcx
cmpq $0x4f, %rcx
jl 0x1f5fa
movl 0x20(%r15), %r8d
incl %r8d
movq $0x1, (%rsp)
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
movl $0x1, %r9d
callq 0x1e0ff
jmp 0x1f5fa