// File: /workspace/github_c_makefile_star2_O3/jsummers[P]deark/modules/tiff.c
// Function: read_numeric_value
static void read_numeric_value(deark *c, lctx *d, const struct taginfo *tg,
	i64 value_index, struct numeric_value *nv, de_ucstring *dbgline)
{
	int ret;
	i64 offs;

	nv->isvalid = 0;
	nv->val_int64 = 0;
	nv->val_double = 0.0;

	// FIXME: This is recalculated in read_tag_value_as_int64.
	offs = tg->val_offset + value_index*tg->unit_size;

	switch(tg->datatype) {
	case DATATYPE_BYTE:
	case DATATYPE_SBYTE:
	case DATATYPE_UNDEF:
	case DATATYPE_ASCII:
	case DATATYPE_UTF8:
	case DATATYPE_UINT16:
	case DATATYPE_SINT16:
	case DATATYPE_UINT32:
	case DATATYPE_SINT32:
	case DATATYPE_IFD32:
	case DATATYPE_UINT64:
	case DATATYPE_SINT64:
	case DATATYPE_IFD64:
		ret = read_tag_value_as_int64(c, d, tg, value_index, &nv->val_int64);
		nv->val_double = (double)nv->val_int64;
		nv->isvalid = ret;
		if(dbgline) {
			if(nv->isvalid)
				ucstring_printf(dbgline, DE_ENCODING_LATIN1, "%" I64_FMT, nv->val_int64);
			else
				ucstring_append_sz(dbgline, "?", DE_ENCODING_LATIN1);
		}
		break;

	case DATATYPE_RATIONAL:
	case DATATYPE_SRATIONAL:
		{
			i64 num, den;

			if(tg->datatype==DATATYPE_SRATIONAL) {
				num = dbuf_geti32x(c->infile, offs, d->is_le);
				den = dbuf_geti32x(c->infile, offs+4, d->is_le);
			}
			else {
				num = dbuf_getu32x(c->infile, offs, d->is_le);
				den = dbuf_getu32x(c->infile, offs+4, d->is_le);
			}

			if(den==0) {
				nv->isvalid = 0;
				nv->val_double = 0.0;
				nv->val_int64 = 0;
				if(dbgline) {
					ucstring_printf(dbgline, DE_ENCODING_LATIN1, "%" I64_FMT "/%" I64_FMT, num, den);
				}

			}
			else {
				nv->isvalid = 1;
				nv->val_double = (double)num/(double)den;
				nv->val_int64 = (i64)nv->val_double;
				if(dbgline) {
					format_double(dbgline, nv->val_double);
				}
			}
		}
		break;

	case DATATYPE_FLOAT32:
	case DATATYPE_FLOAT64:
		if(tg->datatype==DATATYPE_FLOAT64) {
			nv->val_double = dbuf_getfloat64x(c->infile, offs, d->is_le);
		}
		else {
			nv->val_double = dbuf_getfloat32x(c->infile, offs, d->is_le);
		}
		nv->val_int64 = (i64)nv->val_double;
		nv->isvalid = 1;
		if(dbgline) {
			format_double(dbgline, nv->val_double);
		}
		break;

	default:
		if(dbgline) {
			ucstring_append_sz(dbgline, "?", DE_ENCODING_LATIN1);
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %rbx
movq %r8, %r14
movq %rsi, %r12
movq %rdi, %r13
movl $0x0, (%r8)
leaq 0x8(%r8), %r15
xorpd %xmm0, %xmm0
movupd %xmm0, 0x8(%r8)
movl 0xc(%rdx), %esi
leal -0x1(%rsi), %eax
cmpl $0x11, %eax
ja 0xcfd1b
movq 0x28(%rdx), %rbp
imulq %rcx, %rbp
addq 0x20(%rdx), %rbp
leaq 0x6cb9e(%rip), %rsi     # 0x13c85c
movslq (%rsi,%rax,4), %rax
addq %rsi, %rax
jmpq *%rax
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %r8
callq 0xcf7bf
movq 0x8(%r14), %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movsd %xmm0, 0x10(%r14)
movl %eax, (%r14)
testq %rbx, %rbx
je 0xcfe70
testl %eax, %eax
je 0xcfd2c
leaq 0x59ae3(%rip), %rdx     # 0x1297e1
movq %rbx, %rdi
movl $0x5, %esi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf6653
cmpl $0x81, %esi
je 0xcfcc7
testq %rbx, %rbx
je 0xcfe70
leaq 0x5c41e(%rip), %rsi     # 0x12c151
movq %rbx, %rdi
movl $0x5, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf65e3
movq 0x18(%r13), %rdi
movl (%r12), %edx
movq %rbp, %rsi
callq 0xef033
movq %rax, (%rsp)
movq 0x18(%r13), %rdi
addq $0x4, %rbp
movl (%r12), %edx
movq %rbp, %rsi
callq 0xef033
jmp 0xcfdb2
movq 0x18(%r13), %rdi
movl (%r12), %edx
movq %rbp, %rsi
callq 0xef39e
jmp 0xcfdf1
movq 0x18(%r13), %rdi
movl (%r12), %edx
movq %rbp, %rsi
callq 0xeeff3
movq %rax, (%rsp)
movq 0x18(%r13), %rdi
addq $0x4, %rbp
movl (%r12), %edx
movq %rbp, %rsi
callq 0xeeff3
testq %rax, %rax
je 0xcfe30
movl $0x1, (%r14)
xorps %xmm0, %xmm0
cvtsi2sdq (%rsp), %xmm0
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%r14)
cvttsd2si %xmm0, %rax
movq %rax, 0x8(%r14)
jmp 0xcfe07
movq 0x18(%r13), %rdi
movl (%r12), %edx
movq %rbp, %rsi
callq 0xef2fc
cvttsd2si %xmm0, %rax
movsd %xmm0, 0x10(%r14)
movq %rax, 0x8(%r14)
movl $0x1, (%r14)
testq %rbx, %rbx
je 0xcfe70
leaq 0x64727(%rip), %rdx     # 0x13453a
movq %rbx, %rdi
movl $0x5, %esi
movb $0x1, %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf6653
movl $0x0, (%r14)
xorpd %xmm0, %xmm0
movupd %xmm0, (%r15)
testq %rbx, %rbx
je 0xcfe70
leaq 0x6f1d9(%rip), %rdx     # 0x13f025
movq %rbx, %rdi
movl $0x5, %esi
movq (%rsp), %rcx
xorl %r8d, %r8d
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf6653
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq