// File: /workspace/github_c_makefile_star2_O0/jsummers[P]deark/modules/iso9660.c
// Function: do_volume_descriptor
static int do_volume_descriptor(deark *c, lctx *d, i64 secnum)
{
	u8 dtype;
	u8 dvers;
	int saved_indent_level;
	i64 pos1, pos;
	const char *vdtname;
	u8 is_hsf;
	u8 is_cdi = 0;
	int retval = 0;
	enum voldesctype_enum vdt = VOLDESCTYPE_UNKNOWN;
	struct de_stringreaderdata *standard_id = NULL;

	de_dbg_indent_save(c, &saved_indent_level);

	pos1 = sector_dpos(d, secnum);
	is_hsf = is_hsf_volume_descriptor(c, d, secnum, pos1);
	pos = pos1;

	if(is_hsf) pos = pos1+8;
	dtype = de_getbyte_p(&pos);
	standard_id = dbuf_read_string(c->infile, pos, 5, 5, 0, DE_ENCODING_ASCII);
	pos += 5;
	dvers = de_getbyte_p(&pos);

	if(!de_strcmp(standard_id->sz, g_sig_CD001)) {
		switch(dtype) {
		case 0: vdt = VOLDESCTYPE_CD_BOOT; break;
		case 1: vdt = VOLDESCTYPE_CD_PRIMARY; break;
		case 2: vdt = VOLDESCTYPE_CD_SUPPL; break;
		case 3: vdt = VOLDESCTYPE_CD_PARTDESCR; break;
		case 0xff: vdt = VOLDESCTYPE_CD_TERM; break;
		default: vdt = VOLDESCTYPE_OTHERVALID; break;
		}
	}
	else if(!de_strcmp(standard_id->sz, g_sig_CD_I)) {
		switch(dtype) {
		case 1: vdt = VOLDESCTYPE_CD_PRIMARY; is_cdi = 1; break;
		case 0xff: vdt = VOLDESCTYPE_CD_TERM; break;
		default: vdt = VOLDESCTYPE_OTHERVALID; break;
		}
		// TODO: 2 = Coded Character Set File Structure Vol. Descr.
	}
	else if(!de_strncmp(standard_id->sz, "NSR0", 4))
	{
		vdt = VOLDESCTYPE_NSR;
	}
	else if(!de_strncmp(standard_id->sz, "BEA0", 4)) {
		vdt = VOLDESCTYPE_BEA;
	}
	else if(!de_strncmp(standard_id->sz, "TEA0", 4)) {
		vdt = VOLDESCTYPE_TEA;
	}
	else if(!de_strncmp(standard_id->sz, "BOOT", 4) ||
		!de_strncmp(standard_id->sz, "CDW0", 4))
	{
		vdt = VOLDESCTYPE_OTHERVALID;
	}
	else if(!de_strcmp(standard_id->sz,g_sig_CDROM)) {
		switch(dtype) {
		case 1: vdt = VOLDESCTYPE_CD_PRIMARY_HSF; break;
		case 0xff: vdt = VOLDESCTYPE_CD_TERM; break;
		default: vdt = VOLDESCTYPE_OTHERVALID; break;
		}
	}

	if(vdt==VOLDESCTYPE_UNKNOWN) {
		de_warn(c, "Expected volume descriptor at %"I64_FMT" not found", pos1);
		goto done;
	}

	de_dbg(c, "volume descriptor at %"I64_FMT" (sector %d)", pos1, (int)secnum);
	de_dbg_indent(c, 1);

	de_dbg(c, "type: %u", (unsigned int)dtype);
	de_dbg(c, "standard id: \"%s\"", ucstring_getpsz_d(standard_id->str));
	de_dbg(c, "version: %u", (unsigned int)dvers);

	vdtname = get_vol_descr_type_name(vdt);
	de_dbg(c, "interpreted type: %s", vdtname);

	retval = 1;
	if(vdt==VOLDESCTYPE_TEA) {
		retval = 0;
	}
	else if(vdt==VOLDESCTYPE_CD_TERM) {
		// Minor hack: Peak ahead at the next sector. Unless it looks like a
		// BEA descriptor, signifying that there are extended descriptors,
		// assume this is the last descriptor.
		if(dbuf_memcmp(c->infile, sector_dpos(d, secnum+1)+1, "BEA0", 4)) {
			retval = 0;
		}
	}

	switch(vdt) {
	case VOLDESCTYPE_CD_BOOT:
		do_boot_volume_descr(c, d, pos1);
		break;
	case VOLDESCTYPE_CD_PRIMARY:
		do_primary_or_suppl_volume_descr(c, d, secnum, pos1, 1, is_cdi, 0);
		break;
	case VOLDESCTYPE_CD_PRIMARY_HSF:
		do_primary_or_suppl_volume_descr(c, d, secnum, pos1, 1, 0, 1);
		break;
	case VOLDESCTYPE_CD_SUPPL: // supplementary or enhanced
		do_primary_or_suppl_volume_descr(c, d, secnum, pos1, 0, is_cdi, 0);
		break;
	case VOLDESCTYPE_NSR:
		d->is_udf = 1;
		break;
	case VOLDESCTYPE_BEA:
	case VOLDESCTYPE_CD_TERM:
	case VOLDESCTYPE_TEA:
		break;
	default:
		de_dbg(c, "[disregarding this volume descriptor]");
	}

done:
	de_dbg_indent_restore(c, saved_indent_level);
	de_destroy_stringreaderdata(c, standard_id);
	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb $0x0, -0x3a(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x15b580
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xcd1e0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0xcd200
movb %al, -0x39(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpb $0x0, -0x39(%rbp)
je 0xcca81
movq -0x28(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165170
movb %al, -0x19(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x30(%rbp), %rsi
movl $0x5, %ecx
xorl %r8d, %r8d
movl $0x1, %r9d
movq %rcx, %rdx
callq 0x1664c0
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x30(%rbp), %rsi
callq 0x165170
movb %al, -0x1a(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x158ca6(%rip), %rsi    # 0x225790
callq 0x191a0
cmpl $0x0, %eax
jne 0xccb64
movzbl -0x19(%rbp), %eax
movl %eax, -0x54(%rbp)
testl %eax, %eax
je 0xccb2b
jmp 0xccb01
movl -0x54(%rbp), %eax
subl $0x1, %eax
je 0xccb34
jmp 0xccb0b
movl -0x54(%rbp), %eax
subl $0x2, %eax
je 0xccb3d
jmp 0xccb15
movl -0x54(%rbp), %eax
subl $0x3, %eax
je 0xccb46
jmp 0xccb1f
movl -0x54(%rbp), %eax
subl $0xff, %eax
je 0xccb4f
jmp 0xccb58
movl $0x5, -0x44(%rbp)
jmp 0xccb5f
movl $0x2, -0x44(%rbp)
jmp 0xccb5f
movl $0x4, -0x44(%rbp)
jmp 0xccb5f
movl $0x6, -0x44(%rbp)
jmp 0xccb5f
movl $0x7, -0x44(%rbp)
jmp 0xccb5f
movl $0x1, -0x44(%rbp)
jmp 0xcccd6
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x158c25(%rip), %rsi    # 0x225798
callq 0x191a0
cmpl $0x0, %eax
jne 0xccbb9
movzbl -0x19(%rbp), %eax
movl %eax, -0x58(%rbp)
subl $0x1, %eax
je 0xccb97
jmp 0xccb8b
movl -0x58(%rbp), %eax
subl $0xff, %eax
je 0xccba4
jmp 0xccbad
movl $0x2, -0x44(%rbp)
movb $0x1, -0x3a(%rbp)
jmp 0xccbb4
movl $0x7, -0x44(%rbp)
jmp 0xccbb4
movl $0x1, -0x44(%rbp)
jmp 0xcccd4
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xecb14(%rip), %rsi     # 0x1b96dc
movl $0x4, %edx
callq 0x19050
cmpl $0x0, %eax
jne 0xccbe3
movl $0xa, -0x44(%rbp)
jmp 0xcccd2
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xecaef(%rip), %rsi     # 0x1b96e1
movl $0x4, %edx
callq 0x19050
cmpl $0x0, %eax
jne 0xccc0d
movl $0x8, -0x44(%rbp)
jmp 0xcccd0
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xecaca(%rip), %rsi     # 0x1b96e6
movl $0x4, %edx
callq 0x19050
cmpl $0x0, %eax
jne 0xccc37
movl $0x9, -0x44(%rbp)
jmp 0xcccce
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xecaa5(%rip), %rsi     # 0x1b96eb
movl $0x4, %edx
callq 0x19050
cmpl $0x0, %eax
je 0xccc73
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
leaq 0xeca8c(%rip), %rsi     # 0x1b96f0
movl $0x4, %edx
callq 0x19050
cmpl $0x0, %eax
jne 0xccc7c
movl $0x1, -0x44(%rbp)
jmp 0xccccc
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x158b15(%rip), %rsi    # 0x2257a0
callq 0x191a0
cmpl $0x0, %eax
jne 0xcccca
movzbl -0x19(%rbp), %eax
movl %eax, -0x5c(%rbp)
subl $0x1, %eax
je 0xcccaf
jmp 0xccca3
movl -0x5c(%rbp), %eax
subl $0xff, %eax
je 0xcccb8
jmp 0xcccc1
movl $0x3, -0x44(%rbp)
jmp 0xcccc8
movl $0x7, -0x44(%rbp)
jmp 0xcccc8
movl $0x1, -0x44(%rbp)
jmp 0xcccca
jmp 0xccccc
jmp 0xcccce
jmp 0xcccd0
jmp 0xcccd2
jmp 0xcccd4
jmp 0xcccd6
cmpl $0x0, -0x44(%rbp)
jne 0xcccf7
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0xeca0a(%rip), %rsi     # 0x1b96f5
movb $0x0, %al
callq 0x15bc10
jmp 0xcced5
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x18(%rbp), %rax
movl %eax, %ecx
leaq 0xeca15(%rip), %rsi     # 0x1b9721
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x15b560
movq -0x8(%rbp), %rdi
movzbl -0x19(%rbp), %edx
leaq 0xf098a(%rip), %rsi     # 0x1bd6ba
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x172650
movq -0x68(%rbp), %rdi
movq %rax, %rdx
leaq 0xec9ec(%rip), %rsi     # 0x1b9746
movb $0x0, %al
callq 0x15b0d0
movq -0x8(%rbp), %rdi
movzbl -0x1a(%rbp), %edx
leaq 0xf5916(%rip), %rsi     # 0x1c2686
movb $0x0, %al
callq 0x15b0d0
movl -0x44(%rbp), %edi
callq 0xcd280
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0xec9c6(%rip), %rsi     # 0x1b9758
movb $0x0, %al
callq 0x15b0d0
movl $0x1, -0x40(%rbp)
cmpl $0x9, -0x44(%rbp)
jne 0xccdaf
movl $0x0, -0x40(%rbp)
jmp 0xccdfe
cmpl $0x7, -0x44(%rbp)
jne 0xccdfc
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x1, %rsi
callq 0xcd1e0
movq -0x70(%rbp), %rdi
movq %rax, %rsi
addq $0x1, %rsi
leaq 0xec8fd(%rip), %rdx     # 0x1b96e1
movl $0x4, %ecx
callq 0x166ab0
cmpl $0x0, %eax
je 0xccdfa
movl $0x0, -0x40(%rbp)
jmp 0xccdfc
jmp 0xccdfe
movl -0x44(%rbp), %eax
addl $-0x2, %eax
movl %eax, %ecx
movq %rcx, -0x78(%rbp)
subl $0x8, %eax
ja 0xccec1
movq -0x78(%rbp), %rax
leaq 0xec6ee(%rip), %rcx     # 0x1b950c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0xcd360
jmp 0xcced3
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x1, %r8d
xorl %eax, %eax
movzbl -0x3a(%rbp), %r9d
movl $0x0, (%rsp)
callq 0xcd490
jmp 0xcced3
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl $0x1, %r8d
xorl %r9d, %r9d
movl $0x1, (%rsp)
callq 0xcd490
jmp 0xcced3
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
xorl %r8d, %r8d
movzbl -0x3a(%rbp), %r9d
movl $0x0, (%rsp)
callq 0xcd490
jmp 0xcced3
movq -0x10(%rbp), %rax
movb $0x1, 0xb(%rax)
jmp 0xcced3
jmp 0xcced3
movq -0x8(%rbp), %rdi
leaq 0xec8a1(%rip), %rsi     # 0x1b976d
movb $0x0, %al
callq 0x15b0d0
jmp 0xcced5
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x15b5a0
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x166830
movl -0x40(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)