// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jb 0x104ac
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1068e
movq -0x10(%rbp), %rdx
movq (%rdx), %rax
movl 0x8(%rdx), %ecx
movl %ecx, %esi
incl %esi
movl %esi, 0x8(%rdx)
movb (%rax,%rcx), %al
movb %al, -0x19(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
movl 0xc(%rax), %eax
subl %ecx, %eax
movl %eax, -0x20(%rbp)
movzbl -0x19(%rbp), %eax
addl $0xffffff34, %eax       # imm = 0xFFFFFF34
movl %eax, %ecx
movq %rcx, -0x28(%rbp)
subl $0x7, %eax
ja 0x10642
movq -0x28(%rbp), %rax
leaq 0x16d9b(%rip), %rcx     # 0x27290
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x1, -0x20(%rbp)
jae 0x10510
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x1068e
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rdx
movl 0x8(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x8(%rdx)
movl %ecx, %ecx
movsbq (%rax,%rcx), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x10687
cmpl $0x1, -0x20(%rbp)
jae 0x1054b
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x1068e
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rdx
movl 0x8(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x8(%rdx)
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x10687
cmpl $0x2, -0x20(%rbp)
jae 0x10587
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x1068e
movq -0x10(%rbp), %rdi
callq 0xe6a0
movswq %ax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x10687
cmpl $0x2, -0x20(%rbp)
jae 0x105b2
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x1068e
movq -0x10(%rbp), %rdi
callq 0xe6a0
movzwl %ax, %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x10687
cmpl $0x4, -0x20(%rbp)
jae 0x105de
movl $0xfffffffb, -0x4(%rbp) # imm = 0xFFFFFFFB
jmp 0x1068e
movq -0x10(%rbp), %rdi
callq 0xe6f0
movslq %eax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x10687
cmpl $0x4, -0x20(%rbp)
jae 0x10608
movl $0xfffffffa, -0x4(%rbp) # imm = 0xFFFFFFFA
jmp 0x1068e
movq -0x10(%rbp), %rdi
callq 0xe6f0
movl %eax, %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x10687
cmpl $0x8, -0x20(%rbp)
jae 0x1062d
movl $0xfffffff9, -0x4(%rbp) # imm = 0xFFFFFFF9
jmp 0x1068e
movq -0x10(%rbp), %rdi
callq 0xe740
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x10687
movzbl -0x19(%rbp), %eax
cmpl $0x80, %eax
jge 0x1065c
movzbl -0x19(%rbp), %eax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x10687
movzbl -0x19(%rbp), %eax
cmpl $0xe0, %eax
jl 0x1067e
movzbl -0x19(%rbp), %eax
andl $0x1f, %eax
movslq %eax, %rcx
subq $0x20, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
jmp 0x10687
movl $0xfffffff8, -0x4(%rbp) # imm = 0xFFFFFFF8
jmp 0x1068e
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)