// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/wpg.c
// Function: do_record
static int do_record(deark *c, lctx *d, i64 pos1, i64 *bytes_consumed)
{
	i64 pos = pos1;
	u8 rectype;
	i64 rec_dlen;
	int retval = 0;
	const char *name;
	const struct wpg_rectype_info *wri;

	rectype = de_getbyte(pos++);
	wri = find_wpg_rectype_info(rectype);
	if(wri) name = wri->name;
	else name="?";
	de_dbg(c, "record type 0x%02x (%s) at %d", (unsigned int)rectype, name, (int)pos1);
	de_dbg_indent(c, 1);

	rec_dlen = (i64)de_getbyte(pos++);

	// As far as I can tell, the variable-length integer works as follows.
	// An integer uses either 1, 3, or 5 bytes.

	// number = d c b a  (d = most-significant bits, ...)
	//  value           byte0    byte1    byte2    byte3    byte4
	//  --------------  -------- -------- -------- -------- --------
	//  (0-32767)     : 11111111 aaaaaaaa 0bbbbbbb
	//  (0-2147483647): 11111111 cccccccc 1ddddddd aaaaaaaa bbbbbbbb
	//  (0-254)       : aaaaaaaa [where the a's are not all 1's]

	if(rec_dlen==0xff) {
		// Not an 8-bit value. Could be 16-bit or 32-bit.
		rec_dlen = de_getu16le(pos);
		pos += 2;

		if(rec_dlen & 0x8000) { // A 32-bit value
			i64 n;

			n = de_getu16le(pos);
			pos += 2;
			rec_dlen = ((rec_dlen&0x7fff)<<16) | n;
		}
	}

	de_dbg(c, "rec dpos=%d, dlen=[%d]%d", (int)pos, (int)(pos-(pos1+1)), (int)rec_dlen);

	if(wri && wri->fn) {
		wri->fn(c, d, rectype, pos, rec_dlen);
	}

	*bytes_consumed = (pos-pos1) + rec_dlen;
	retval = 1;

	de_dbg_indent(c, -1);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x3c(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
callq 0x165060
movb %al, -0x29(%rbp)
movzbl -0x29(%rbp), %edi
callq 0x13af40
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x13add8
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x13ade3
leaq 0x7ce4e(%rip), %rax     # 0x1b7c2d
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movzbl -0x29(%rbp), %edx
movq -0x48(%rbp), %rcx
movq -0x18(%rbp), %rax
movl %eax, %r8d
leaq 0x920ec(%rip), %rsi     # 0x1ccee9
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
movq %rsi, %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
callq 0x165060
movzbl %al, %eax
movq %rax, -0x38(%rbp)
cmpq $0xff, -0x38(%rbp)
jne 0x13aea9
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165280
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rax
andq $0x8000, %rax           # imm = 0x8000
cmpq $0x0, %rax
je 0x13aea7
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x165280
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rax
andq $0x7fff, %rax           # imm = 0x7FFF
shlq $0x10, %rax
orq -0x58(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x13aea9
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl %eax, %edx
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
addq $0x1, %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %eax, %r8d
leaq 0x92035(%rip), %rsi     # 0x1ccf07
movb $0x0, %al
callq 0x15b0d0
cmpq $0x0, -0x50(%rbp)
je 0x13af0b
movq -0x50(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x13af0b
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movb -0x29(%rbp), %dl
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %r8
movzbl %dl, %edx
callq *%rax
movq -0x28(%rbp), %rcx
subq -0x18(%rbp), %rcx
addq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x15b560
movl -0x3c(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)