// File: /workspace/github_cpp_makefile_star2_O1/nmmmnu[P]HM3/test/test_blobref.cc
// Function: test_blobref()
int test_blobref(){
	constexpr size_t SIZE = 256;
	char mem[SIZE];

	for(size_t i = 0; i < SIZE; ++i)
		mem[i] = (char) i;

	BlobRef br{ mem };

	assert(*br.as<uint16_t>(0x00) == htobe16(0x0001)	);
	assert(*br.as<uint16_t>(0x0E) == htobe16(0x0E0F)	);
	assert(*br.as<uint32_t>(0x10) == htobe32(0x10111213)	);

	{
		const char *s = br.as<char>('a', 5);
		assert(strncmp(s, "abcde", 5) == 0);

		// relative
		assert(*br.as<char>(s + 5) == 'f');
	}

	{
		struct TestStruct{
			uint16_t	i;
			char		c;
			char		s[4];
		}__attribute__((__packed__));

		const TestStruct *st = br.as<TestStruct>(0x50);
		assert(st->i    == htobe16(0x5051)	);
		assert(st->c    == 0x52			);
		assert(st->s[0] == 0x53			);
		assert(st->s[1] == 0x54			);
		assert(st->s[2] == 0x55			);
		assert(st->s[3] == 0x56			);

		// relative
		const char *stc = (const char *) st;
		assert(*br.as<char>(stc + sizeof(TestStruct)) == 0x57);
	}

	{
		size_t const max = SIZE / sizeof(uint64_t);

		const uint64_t *u64 = br.as<uint64_t>(0, max);
		assert(u64 != nullptr	);
		assert(u64[      0] == htobe64(0x0001020304050607)	);
		assert(u64[max - 1] == htobe64(0xf8f9fafbFCFDFEFF)	);

		// relative
		const uint64_t *p = & u64[max - 2];
		assert(*br.as<uint64_t>(p + 1) == u64[max - 1]	);
	}

	{
		size_t const max = SIZE / sizeof(uint64_t) ;

		// after last
		assert(br.as<uint64_t>(0, max + 1 ) == nullptr		);
	}

	{
		size_t const max = SIZE / sizeof(uint64_t) ;

		const uint64_t *u64 = br.as<uint64_t>(0, max);

		// relative
		// after last
		const uint64_t *p = & u64[max - 1];
		assert(br.as<uint64_t>(p + 1) == nullptr	);
	}

	// zero size
	assert(br.as<char>(0x00, 0) == nullptr	);

	// nullptr
	assert(br.as<char>(nullptr) == nullptr	);

	return 0;
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movdqa 0xe75(%rip), %xmm0      # 0x2010
xorl %eax, %eax
movdqa 0xe7b(%rip), %xmm1      # 0x2020
movdqa %xmm0, (%rsp,%rax)
addq $0x10, %rax
paddb %xmm1, %xmm0
cmpq $0x100, %rax            # imm = 0x100
jne 0x11a5
cmpw $0x100, (%rsp)          # imm = 0x100
jne 0x128a
cmpw $0xf0e, 0xe(%rsp)       # imm = 0xF0E
jne 0x12a9
cmpl $0x13121110, 0x10(%rsp) # imm = 0x13121110
jne 0x12c8
movl $0x64636261, %eax       # imm = 0x64636261
xorl 0x61(%rsp), %eax
movzbl 0x65(%rsp), %ecx
xorl $0x65, %ecx
orl %eax, %ecx
jne 0x12e7
cmpb $0x66, 0x66(%rsp)
jne 0x1306
cmpw $0x5150, 0x50(%rsp)     # imm = 0x5150
jne 0x1325
cmpb $0x52, 0x52(%rsp)
jne 0x1344
cmpb $0x53, 0x53(%rsp)
jne 0x1363
cmpb $0x54, 0x54(%rsp)
jne 0x1382
cmpb $0x55, 0x55(%rsp)
jne 0x13a1
cmpb $0x56, 0x56(%rsp)
jne 0x13c0
cmpb $0x57, 0x57(%rsp)
jne 0x13df
movabsq $0x706050403020100, %rax # imm = 0x706050403020100
cmpq %rax, (%rsp)
jne 0x13fe
movabsq $-0x1020304050608, %rax # imm = 0xFFFEFDFCFBFAF9F8
cmpq %rax, 0xf8(%rsp)
jne 0x141d
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
retq
leaq 0xd9f(%rip), %rdi       # 0x2030
leaq 0xdc2(%rip), %rsi       # 0x205a
leaq 0xdd0(%rip), %rcx       # 0x206f
movl $0x15, %edx
callq 0x1030
leaq 0xdd2(%rip), %rdi       # 0x2082
leaq 0xda3(%rip), %rsi       # 0x205a
leaq 0xdb1(%rip), %rcx       # 0x206f
movl $0x16, %edx
callq 0x1030
leaq 0xddd(%rip), %rdi       # 0x20ac
leaq 0xd84(%rip), %rsi       # 0x205a
leaq 0xd92(%rip), %rcx       # 0x206f
movl $0x17, %edx
callq 0x1030
leaq 0xdf2(%rip), %rdi       # 0x20e0
leaq 0xd65(%rip), %rsi       # 0x205a
leaq 0xd73(%rip), %rcx       # 0x206f
movl $0x1b, %edx
callq 0x1030
leaq 0xdef(%rip), %rdi       # 0x20fc
leaq 0xd46(%rip), %rsi       # 0x205a
leaq 0xd54(%rip), %rcx       # 0x206f
movl $0x1e, %edx
callq 0x1030
leaq 0xdeb(%rip), %rdi       # 0x2117
leaq 0xd27(%rip), %rsi       # 0x205a
leaq 0xd35(%rip), %rcx       # 0x206f
movl $0x29, %edx
callq 0x1030
leaq 0xde5(%rip), %rdi       # 0x2130
leaq 0xd08(%rip), %rsi       # 0x205a
leaq 0xd16(%rip), %rcx       # 0x206f
movl $0x2a, %edx
callq 0x1030
leaq 0xdd4(%rip), %rdi       # 0x213e
leaq 0xce9(%rip), %rsi       # 0x205a
leaq 0xcf7(%rip), %rcx       # 0x206f
movl $0x2b, %edx
callq 0x1030
leaq 0xdc6(%rip), %rdi       # 0x214f
leaq 0xcca(%rip), %rsi       # 0x205a
leaq 0xcd8(%rip), %rcx       # 0x206f
movl $0x2c, %edx
callq 0x1030
leaq 0xdb8(%rip), %rdi       # 0x2160
leaq 0xcab(%rip), %rsi       # 0x205a
leaq 0xcb9(%rip), %rcx       # 0x206f
movl $0x2d, %edx
callq 0x1030
leaq 0xdaa(%rip), %rdi       # 0x2171
leaq 0xc8c(%rip), %rsi       # 0x205a
leaq 0xc9a(%rip), %rcx       # 0x206f
movl $0x2e, %edx
callq 0x1030
leaq 0xd9c(%rip), %rdi       # 0x2182
leaq 0xc6d(%rip), %rsi       # 0x205a
leaq 0xc7b(%rip), %rcx       # 0x206f
movl $0x32, %edx
callq 0x1030
leaq 0xdac(%rip), %rdi       # 0x21b1
leaq 0xc4e(%rip), %rsi       # 0x205a
leaq 0xc5c(%rip), %rcx       # 0x206f
movl $0x3a, %edx
callq 0x1030
leaq 0xdb4(%rip), %rdi       # 0x21d8
leaq 0xc2f(%rip), %rsi       # 0x205a
leaq 0xc3d(%rip), %rcx       # 0x206f
movl $0x3b, %edx
callq 0x1030