// File: /workspace/github_c_makefile_star2_O2/aerospike[P]aerospike-common/src/main/aerospike/as_msgpack.c
// Function: as_unpack_uint64
int
as_unpack_uint64(as_unpacker *pk, uint64_t *i)
{
	if (pk->offset >= pk->length) {
		return -1;
	}

	uint8_t type = pk->buffer[pk->offset++];
	uint32_t size = pk->length - pk->offset;

	switch (type) {
	case 0xd0: // signed 8 bit integer
		if (size < 1) {
			return -1;
		}
		*i = (uint64_t)(int8_t)pk->buffer[pk->offset++];
		break;
	case 0xcc: // unsigned 8 bit integer
		if (size < 1) {
			return -2;
		}
		*i = (uint64_t)pk->buffer[pk->offset++];
		break;

	case 0xd1: // signed 16 bit integer
		if (size < 2) {
			return -3;
		}
		*i = (uint64_t)(int16_t)extract_uint16(pk);
		break;
	case 0xcd: // unsigned 16 bit integer
		if (size < 2) {
			return -4;
		}
		*i = (uint64_t)extract_uint16(pk);
		break;

	case 0xd2: // signed 32 bit integer
		if (size < 4) {
			return -5;
		}
		*i = (uint64_t)(int32_t)extract_uint32(pk);
		break;
	case 0xce: // unsigned 32 bit integer
		if (size < 4) {
			return -6;
		}
		*i = (uint64_t)extract_uint32(pk);
		break;

	case 0xd3: // signed 64 bit integer
	case 0xcf: // unsigned 64 bit integer
		if (size < 8) {
			return -7;
		}
		*i = extract_uint64(pk);
		break;

	default:
		if (type < 0x80) { // 8 bit combined unsigned integer
			*i = type;
			break;
		}

		if (type >= 0xe0) { // 8 bit combined signed integer
			*i = (uint64_t)(type & 0x1f) - 32;
			break;
		}

		return -8;
	}

	return 0;
}

// Assembly:
movl 0x8(%rdi), %ecx
movl 0xc(%rdi), %r10d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %r10d, %ecx
jae 0xbf5d
pushq %rbx
movq (%rdi), %rdx
leaq 0x1(%rcx), %r9
movl %r9d, 0x8(%rdi)
movzbl (%rdx,%rcx), %r8d
leal -0xcc(%r8), %r11d
cmpl $0x7, %r11d
ja 0xbef0
leaq 0x9459(%rip), %rbx      # 0x152ac
movl %r10d, %r8d
movslq (%rbx,%r11,4), %r11
subl %r9d, %r8d
addq %rbx, %r11
jmpq *%r11
cmpl $0x8, %r8d
jae 0xbeaa
movl $0xfffffff9, %eax       # imm = 0xFFFFFFF9
jmp 0xbf5c
cmpl $0x4, %r8d
jae 0xbf01
movl $0xfffffffa, %eax       # imm = 0xFFFFFFFA
jmp 0xbf5c
cmpl %r9d, %r10d
jne 0xbf10
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
jmp 0xbf5c
cmpl $0x2, %r8d
jae 0xbf1e
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
jmp 0xbf5c
movq 0x1(%rdx,%rcx), %r8
leal 0x9(%rcx), %eax
movl %eax, 0x8(%rdi)
bswapq %r8
jmp 0xbf57
cmpl $0x4, %r8d
jae 0xbf33
movl $0xfffffffb, %eax       # imm = 0xFFFFFFFB
jmp 0xbf5c
cmpl %r9d, %r10d
je 0xbf5c
leal 0x2(%rcx), %eax
movl %eax, 0x8(%rdi)
movsbq (%rdx,%r9), %r8
jmp 0xbf57
cmpl $0x2, %r8d
jae 0xbf44
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jmp 0xbf5c
testb %r8b, %r8b
jns 0xbf57
cmpb $-0x20, %r8b
jb 0xbf5e
orq $-0x20, %r8
jmp 0xbf57
movl (%rdx,%r9), %r8d
leal 0x5(%rcx), %eax
movl %eax, 0x8(%rdi)
bswapl %r8d
jmp 0xbf57
leal 0x2(%rcx), %eax
movl %eax, 0x8(%rdi)
movzbl 0x1(%rdx,%rcx), %r8d
jmp 0xbf57
movzwl 0x1(%rdx,%rcx), %eax
addl $0x3, %ecx
movl %ecx, 0x8(%rdi)
rolw $0x8, %ax
movzwl %ax, %r8d
jmp 0xbf57
movl 0x1(%rdx,%rcx), %eax
addl $0x5, %ecx
movl %ecx, 0x8(%rdi)
bswapl %eax
movslq %eax, %r8
jmp 0xbf57
movzwl (%rdx,%r9), %eax
addl $0x3, %ecx
movl %ecx, 0x8(%rdi)
rolw $0x8, %ax
movswq %ax, %r8
xorl %eax, %eax
movq %r8, (%rsi)
popq %rbx
retq
movl $0xfffffff8, %eax       # imm = 0xFFFFFFF8
jmp 0xbf5c