// File: /workspace/github_c_makefile_star2_O1/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 0xd1a9
pushq %rbx
movq (%rdi), %rdx
leal 0x1(%rcx), %r8d
movl %r8d, 0x8(%rdi)
movzbl (%rdx,%rcx), %r9d
leal -0xcc(%r9), %r11d
cmpl $0x7, %r11d
ja 0xd18f
movl %r10d, %r9d
subl %r8d, %r9d
leaq 0xb205(%rip), %rbx      # 0x182ac
movslq (%rbx,%r11,4), %r11
addq %rbx, %r11
jmpq *%r11
movl $0xfffffff9, %eax       # imm = 0xFFFFFFF9
cmpl $0x8, %r9d
jb 0xd1a8
movl %r8d, %eax
movq (%rdx,%rax), %r9
bswapq %r9
addl $0x9, %ecx
jmp 0xd0eb
movl $0xfffffffa, %eax       # imm = 0xFFFFFFFA
cmpl $0x4, %r9d
jb 0xd1a8
movl %r8d, %eax
movl (%rdx,%rax), %r9d
bswapl %r9d
addl $0x5, %ecx
movl %ecx, 0x8(%rdi)
jmp 0xd1a3
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmpl %r8d, %r10d
je 0xd1a8
addl $0x2, %ecx
movl %ecx, 0x8(%rdi)
movl %r8d, %eax
movzbl (%rdx,%rax), %r9d
jmp 0xd1a3
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
cmpl $0x2, %r9d
jb 0xd1a8
movl %r8d, %eax
movzwl (%rdx,%rax), %eax
rolw $0x8, %ax
addl $0x3, %ecx
movl %ecx, 0x8(%rdi)
movzwl %ax, %r9d
jmp 0xd1a3
movl $0xfffffffb, %eax       # imm = 0xFFFFFFFB
cmpl $0x4, %r9d
jb 0xd1a8
movl %r8d, %eax
movl (%rdx,%rax), %eax
bswapl %eax
addl $0x5, %ecx
movl %ecx, 0x8(%rdi)
movslq %eax, %r9
jmp 0xd1a3
cmpl %r8d, %r10d
je 0xd1a8
addl $0x2, %ecx
movl %ecx, 0x8(%rdi)
movl %r8d, %eax
movsbq (%rdx,%rax), %r9
jmp 0xd1a3
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
cmpl $0x2, %r9d
jb 0xd1a8
movl %r8d, %eax
movzwl (%rdx,%rax), %eax
rolw $0x8, %ax
addl $0x3, %ecx
movl %ecx, 0x8(%rdi)
movswq %ax, %r9
jmp 0xd1a3
testb %r9b, %r9b
jns 0xd1a3
movl $0xfffffff8, %eax       # imm = 0xFFFFFFF8
cmpb $-0x20, %r9b
jb 0xd1a8
orq $-0x20, %r9
movq %r9, (%rsi)
xorl %eax, %eax
popq %rbx
retq