// File: /workspace/github_c_makefile_star2_O0/aerospike[P]aerospike-common/src/main/aerospike/as_msgpack.c
// Function: as_unpack_ext
int
as_unpack_ext(as_unpacker *pk, as_msgpack_ext *ext)
{
	// Need at least 3 bytes.
	if (pk->length - pk->offset < 3) {
		return -1;
	}

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

	switch (type) {
	case 0xd4: // fixext 1
		ext->size = 1;
		break;
	case 0xd5: // fixext 2
		ext->size = 2;
		break;
	case 0xd6: // fixext 4
		ext->size = 4;
		break;
	case 0xd7: // fixext 8
		ext->size = 8;
		break;
	case 0xd8: // fixext 16
		ext->size = 16;
		break;
	case 0xc7: // ext 8
		ext->size = (uint32_t)pk->buffer[pk->offset++];
		break;
	case 0xc8: // ext 16
		ext->size = extract_uint16(pk);
		break;
	case 0xc9: // ext 32
		// Need at least 4 more bytes.
		if (pk->length - pk->offset < 4) {
			return -2;
		}
		ext->size = extract_uint32(pk);
		break;
	default:
		return -3;
	}

	if (pk->length - pk->offset < 1 + ext->size) {
		return -4;
	}

	ext->type_offset = pk->offset;
	ext->type = pk->buffer[pk->offset++];
	ext->data = pk->buffer + pk->offset;
	pk->offset += ext->size;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x8(%rcx), %eax
cmpl $0x3, %eax
jae 0x109df
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10b6d
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)
movzbl -0x19(%rbp), %eax
addl $0xffffff39, %eax       # imm = 0xFFFFFF39
movl %eax, %ecx
movq %rcx, -0x28(%rbp)
subl $0x11, %eax
ja 0x10adc
movq -0x28(%rbp), %rax
leaq 0x16897(%rip), %rcx     # 0x272b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
movl $0x1, 0x8(%rax)
jmp 0x10ae8
movq -0x18(%rbp), %rax
movl $0x2, 0x8(%rax)
jmp 0x10ae8
movq -0x18(%rbp), %rax
movl $0x4, 0x8(%rax)
jmp 0x10ae8
movq -0x18(%rbp), %rax
movl $0x8, 0x8(%rax)
jmp 0x10ae8
movq -0x18(%rbp), %rax
movl $0x10, 0x8(%rax)
jmp 0x10ae8
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), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x10ae8
movq -0x10(%rbp), %rdi
callq 0xe6a0
movzwl %ax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x10ae8
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x8(%rcx), %eax
cmpl $0x4, %eax
jae 0x10ac8
movl $0xfffffffe, -0x4(%rbp) # imm = 0xFFFFFFFE
jmp 0x10b6d
movq -0x10(%rbp), %rdi
callq 0xe6f0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x10ae8
movl $0xfffffffd, -0x4(%rbp) # imm = 0xFFFFFFFD
jmp 0x10b6d
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x8(%rcx), %eax
movq -0x18(%rbp), %rcx
movl 0x8(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jae 0x10b0d
movl $0xfffffffc, -0x4(%rbp) # imm = 0xFFFFFFFC
jmp 0x10b6d
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0xc(%rax)
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
movb (%rax,%rcx), %cl
movq -0x18(%rbp), %rax
movb %cl, 0x10(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
addq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x10(%rbp), %rax
addl 0x8(%rax), %ecx
movl %ecx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)