// File: /workspace/github_c_makefile_star2_O0/DeforaOS[P]libSystem/src/variable.c
// Function: variable_new_deserialize_type
Variable * variable_new_deserialize_type(VariableType type, size_t * size,
		char const * data)
{
	Variable * v;
	size_t s;
	uint32_t u32;
	uint64_t u64;
	float f;
	double d;
	Buffer * b;
	int res;
	unsigned char const * udata = (unsigned char const *)data;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s(%u, %lu, %p)\n", __func__, type, *size,
			(void *)data);
#endif
	/* estimate the size required */
	s = (type < sizeof(_variable_sizes) / sizeof(*_variable_sizes))
		? _variable_sizes[type] : 0;
	switch(type)
	{
		case VT_NULL:
		case VT_BOOL:
		case VT_INT8:
		case VT_UINT8:
		case VT_INT16:
		case VT_UINT16:
		case VT_INT32:
		case VT_UINT32:
		case VT_INT64:
		case VT_UINT64:
		case VT_POINTER:
			break;
		case VT_BUFFER:
			if(*size < s)
				break;
			memcpy(&u32, data, s);
			u32 = _bswap32(u32);
			s += u32;
			break;
		case VT_FLOAT:
		case VT_DOUBLE:
		case VT_STRING:
			for(s = 1; s <= *size && data[s - 1] != '\0'; s++);
			if(s < *size)
				break;
			/* fallthrough */
		default:
			error_set_code(1, "Unable to deserialize type %u",
					type);
			return NULL;
	}
	if(*size < s)
	{
		*size = s;
		error_set_code(1, "More data needed to deserialize type %u",
				type);
		return NULL;
	}
	*size = s;
	/* convert the data if necessary */
	switch(type)
	{
		case VT_NULL:
			v = variable_new(type);
			break;
		case VT_BOOL:
			if((data[0] & 0xfe) != 0x0)
			{
				error_set_code(1, "Invalid boolean value");
				return NULL;
			}
			v = variable_new(type, data[0]);
			break;
		case VT_INT8:
		case VT_UINT8:
			v = variable_new(type, data[0]);
			break;
		case VT_INT16:
		case VT_UINT16:
			v = variable_new(type, (uint32_t)udata[0] << 8
					| udata[1]);
			break;
		case VT_INT32:
		case VT_UINT32:
			v = variable_new(type, (uint32_t)udata[0] << 24
					| (uint32_t)udata[1] << 16
					| (uint32_t)udata[2] << 8
					| (uint32_t)udata[3]);
			break;
		case VT_FLOAT:
			res = sscanf(data, "%e", &f);
			if(res != 1)
			{
				error_set_code(1, "Invalid float value");
				return NULL;
			}
			v = variable_new(type, f);
			break;
		case VT_DOUBLE:
			res = sscanf(data, "%le", &d);
			if(res != 1)
			{
				error_set_code(1, "Invalid double value");
				return NULL;
			}
			v = variable_new(type, d);
			break;
		case VT_STRING:
			v = variable_new(type, data);
			break;
		case VT_INT64:
		case VT_UINT64:
			u64 = (uint64_t)udata[0] << 56
				| (uint64_t)udata[1] << 48
				| (uint64_t)udata[2] << 40
				| (uint64_t)udata[3] << 32
				| (uint64_t)udata[4] << 24
				| (uint64_t)udata[5] << 16
				| (uint64_t)udata[6] << 8
				| (uint64_t)udata[7];
			v = variable_new(type, u64);
			break;
		case VT_BUFFER:
			/* XXX avoid copying the buffer */
			if((b = buffer_new(s - sizeof(u32), &data[sizeof(u32)]))
					== NULL)
				return NULL;
			v = variable_new(type, b);
			buffer_delete(b);
			break;
		default:
			error_set_code(1, "Unable to deserialize type %u",
					type);
			return NULL;
	}
	return v;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0xc(%rbp), %eax
cmpq $0x11, %rax
jae 0xccfd
movl -0xc(%rbp), %eax
movl %eax, %ecx
leaq 0x376d(%rip), %rax      # 0x10460
movq (%rax,%rcx,8), %rax
movq %rax, -0x70(%rbp)
jmp 0xcd05
xorl %eax, %eax
movq %rax, -0x70(%rbp)
jmp 0xcd05
movq -0x70(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x74(%rbp)
subl $0xa, %eax
jb 0xcd49
jmp 0xcd1a
movl -0x74(%rbp), %eax
addl $-0xa, %eax
subl $0x2, %eax
jb 0xcd8c
jmp 0xcd27
movl -0x74(%rbp), %eax
subl $0xc, %eax
je 0xcd4e
jmp 0xcd31
movl -0x74(%rbp), %eax
subl $0xd, %eax
je 0xcd8c
jmp 0xcd3b
movl -0x74(%rbp), %eax
subl $0x10, %eax
jne 0xcde9
jmp 0xcd49
jmp 0xce0c
movq -0x18(%rbp), %rax
movq (%rax), %rax
cmpq -0x30(%rbp), %rax
jae 0xcd60
jmp 0xce0c
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rdx
leaq -0x34(%rbp), %rdi
callq 0x44b0
movl -0x34(%rbp), %edi
callq 0xd160
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0xce0c
movq $0x1, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rdx
xorl %eax, %eax
cmpq (%rdx), %rcx
movb %al, -0x75(%rbp)
ja 0xcdbf
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x75(%rbp)
movb -0x75(%rbp), %al
testb $0x1, %al
jne 0xcdc8
jmp 0xcdd8
jmp 0xcdca
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0xcd94
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0xcde7
jmp 0xce0c
jmp 0xcde9
movl -0xc(%rbp), %edx
movl $0x1, %edi
leaq 0x371e(%rip), %rsi      # 0x10516
movb $0x0, %al
callq 0x4630
movq $0x0, -0x8(%rbp)
jmp 0xd116
movq -0x18(%rbp), %rax
movq (%rax), %rax
cmpq -0x30(%rbp), %rax
jae 0xce47
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl -0xc(%rbp), %edx
movl $0x1, %edi
leaq 0x3701(%rip), %rsi      # 0x10534
movb $0x0, %al
callq 0x4630
movq $0x0, -0x8(%rbp)
jmp 0xd116
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl -0xc(%rbp), %eax
movq %rax, -0x80(%rbp)
subq $0xd, %rax
ja 0xd0ee
movq -0x80(%rbp), %rax
leaq 0x33da(%rip), %rcx      # 0x10248
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0xc(%rbp), %edi
movb $0x0, %al
callq 0x46e0
movq %rax, -0x28(%rbp)
jmp 0xd10e
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
andl $0xfe, %eax
cmpl $0x0, %eax
je 0xcebb
movl $0x1, %edi
leaq 0x36b5(%rip), %rsi      # 0x1055c
movb $0x0, %al
callq 0x4630
movq $0x0, -0x8(%rbp)
jmp 0xd116
movl -0xc(%rbp), %edi
movq -0x20(%rbp), %rax
movsbl (%rax), %esi
movb $0x0, %al
callq 0x46e0
movq %rax, -0x28(%rbp)
jmp 0xd10e
movl -0xc(%rbp), %edi
movq -0x20(%rbp), %rax
movsbl (%rax), %esi
movb $0x0, %al
callq 0x46e0
movq %rax, -0x28(%rbp)
jmp 0xd10e
movl -0xc(%rbp), %edi
movq -0x68(%rbp), %rax
movzbl (%rax), %esi
shll $0x8, %esi
movq -0x68(%rbp), %rax
movzbl 0x1(%rax), %eax
orl %eax, %esi
movb $0x0, %al
callq 0x46e0
movq %rax, -0x28(%rbp)
jmp 0xd10e
movl -0xc(%rbp), %edi
movq -0x68(%rbp), %rax
movzbl (%rax), %esi
shll $0x18, %esi
movq -0x68(%rbp), %rax
movzbl 0x1(%rax), %eax
shll $0x10, %eax
orl %eax, %esi
movq -0x68(%rbp), %rax
movzbl 0x2(%rax), %eax
shll $0x8, %eax
orl %eax, %esi
movq -0x68(%rbp), %rax
movzbl 0x3(%rax), %eax
orl %eax, %esi
movb $0x0, %al
callq 0x46e0
movq %rax, -0x28(%rbp)
jmp 0xd10e
movq -0x20(%rbp), %rdi
leaq 0x3610(%rip), %rsi      # 0x10572
leaq -0x44(%rbp), %rdx
movb $0x0, %al
callq 0x4560
movl %eax, -0x5c(%rbp)
cmpl $0x1, -0x5c(%rbp)
je 0xcf96
movl $0x1, %edi
leaq 0x35f3(%rip), %rsi      # 0x10575
movb $0x0, %al
callq 0x4630
movq $0x0, -0x8(%rbp)
jmp 0xd116
movl -0xc(%rbp), %edi
movss -0x44(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movb $0x1, %al
callq 0x46e0
movq %rax, -0x28(%rbp)
jmp 0xd10e
movq -0x20(%rbp), %rdi
leaq 0x35cc(%rip), %rsi      # 0x10589
leaq -0x50(%rbp), %rdx
movb $0x0, %al
callq 0x4560
movl %eax, -0x5c(%rbp)
cmpl $0x1, -0x5c(%rbp)
je 0xcff1
movl $0x1, %edi
leaq 0x35b0(%rip), %rsi      # 0x1058d
movb $0x0, %al
callq 0x4630
movq $0x0, -0x8(%rbp)
jmp 0xd116
movl -0xc(%rbp), %edi
movsd -0x50(%rbp), %xmm0
movb $0x1, %al
callq 0x46e0
movq %rax, -0x28(%rbp)
jmp 0xd10e
movl -0xc(%rbp), %edi
movq -0x20(%rbp), %rsi
movb $0x0, %al
callq 0x46e0
movq %rax, -0x28(%rbp)
jmp 0xd10e
movq -0x68(%rbp), %rax
movzbl (%rax), %eax
shlq $0x38, %rax
movq -0x68(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
shlq $0x30, %rcx
orq %rcx, %rax
movq -0x68(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
shlq $0x28, %rcx
orq %rcx, %rax
movq -0x68(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
shlq $0x20, %rcx
orq %rcx, %rax
movq -0x68(%rbp), %rcx
movzbl 0x4(%rcx), %ecx
shlq $0x18, %rcx
orq %rcx, %rax
movq -0x68(%rbp), %rcx
movzbl 0x5(%rcx), %ecx
shlq $0x10, %rcx
orq %rcx, %rax
movq -0x68(%rbp), %rcx
movzbl 0x6(%rcx), %ecx
shlq $0x8, %rcx
orq %rcx, %rax
movq -0x68(%rbp), %rcx
movzbl 0x7(%rcx), %ecx
orq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0xc(%rbp), %edi
movq -0x40(%rbp), %rsi
movb $0x0, %al
callq 0x46e0
movq %rax, -0x28(%rbp)
jmp 0xd10e
movq -0x30(%rbp), %rdi
subq $0x4, %rdi
movq -0x20(%rbp), %rsi
addq $0x4, %rsi
callq 0x4100
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
jne 0xd0d1
movq $0x0, -0x8(%rbp)
jmp 0xd116
movl -0xc(%rbp), %edi
movq -0x58(%rbp), %rsi
movb $0x0, %al
callq 0x46e0
movq %rax, -0x28(%rbp)
movq -0x58(%rbp), %rdi
callq 0x4690
jmp 0xd10e
movl -0xc(%rbp), %edx
movl $0x1, %edi
leaq 0x3419(%rip), %rsi      # 0x10516
movb $0x0, %al
callq 0x4630
movq $0x0, -0x8(%rbp)
jmp 0xd116
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)