// File: /workspace/github_c_makefile_star2_O0/tvlabs[P]edge264/./edge264_bitstream.c
// Function: get_bytes
static inline size_t get_bytes(Edge264GetBits *gb, int nbytes)
{
	static const i8x16 shuf[8] = {
		{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1},
		{0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1},
		{0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1},
		{0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1},
		{0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1},
		{0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1},
		{0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1},
		{0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, -1},
	};
	
	// load 16 bytes without reading past aligned buffer boundaries
	const uint8_t *CPB = gb->CPB;
	const uint8_t *end = gb->end;
	intptr_t diff = CPB - end;
	u8x16 v;
	if (__builtin_expect(diff <= -14, 1)) {
		v = load128(CPB - 2);
	} else if (diff < 0) {
		const uint8_t *p = minp(CPB - 2, (uint8_t *)((uintptr_t)(end - 1) & -16));
		v = shrv128(shlv128(load128(p), p + 16 - end), min(14 + diff, 16));
	} else {
		gb->CPB = CPB + nbytes;
		return 0;
	}
	
	// make a bitmask for the positions of 00n escape sequences and iterate on it
	u8x16 eq0 = v == 0;
	u8x16 x = shr128(v, 2);
	#if defined(__SSE2__)
		unsigned esc = movemask(eq0 & shr128(eq0, 1) & (x <= 3));
		if (__builtin_expect(esc, 0)) {
			while (esc & ((1 << nbytes) - 1)) {
				int i = __builtin_ctz(esc);
				esc = (esc & (esc - 1)) >> 1;
				if (CPB[i] <3) { // delimiter sequence, set end to its first byte
					gb->end = CPB + i - 2;
					x &= ~shlv128(set8(-1), i);
					break; // we cannot iterate more since now x differs from esc
				}
				// otherwise this is an emulation_prevention_three_byte -> remove it
				x = shuffle(x, shuf[i]);
				CPB++;
			}
		}
	#elif defined(__ARM_NEON)
		uint64_t esc = (uint64_t)vshrn_n_u16(eq0 & shr128(eq0, 1) & (x <= 3), 4);
		if (__builtin_expect(esc, 0)) {
			esc &= 0x8888888888888888ULL;
			while (esc & ((1ULL << (nbytes << 2)) - 1)) {
				int i = __builtin_ctzll(esc) >> 2;
				esc = (esc & (esc - 1)) >> 4;
				if (CPB[i] <3) { // delimiter sequence, set end to its first byte
					gb->end = CPB + i - 2;
					x &= ~shlv128(set8(-1), i);
					break; // we cannot iterate more since now x differs from esc
				}
				// otherwise this is an emulation_prevention_three_byte -> remove it
				x = shuffle(x, shuf[i]);
				CPB++;
			}
		}
	#endif
	
	// increment CPB and return the requested bytes in upper part of the result
	gb->CPB = CPB + nbytes;
	#if SIZE_BIT == 32
		return big_endian32(((i32x4)x)[0]);
	#elif SIZE_BIT == 64
		return big_endian64(((i64x2)x)[0]);
	#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x190(%rbp)
movl %esi, -0x194(%rbp)
movq -0x190(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1a0(%rbp)
movq -0x190(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x1a8(%rbp)
movq -0x1a0(%rbp), %rax
movq -0x1a8(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x1b0(%rbp)
cmpq $-0xe, -0x1b0(%rbp)
setle %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x4c8e5
movq -0x1a0(%rbp), %rax
addq $-0x2, %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
vmovdqu (%rax), %xmm0
vmovdqa %xmm0, -0x1c0(%rbp)
jmp 0x4cad6
cmpq $0x0, -0x1b0(%rbp)
jge 0x4caa9
movq -0x1a0(%rbp), %rcx
addq $-0x2, %rcx
movq -0x1a8(%rbp), %rax
addq $-0x1, %rax
andq $-0x10, %rax
movq %rcx, -0xa8(%rbp)
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rax
movq -0xb0(%rbp), %rcx
subq %rcx, %rax
cmpq $0x0, %rax
jge 0x4c942
movq -0xa8(%rbp), %rax
movq %rax, -0x200(%rbp)
jmp 0x4c950
movq -0xb0(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x200(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movq -0x1c8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rax
vmovdqu (%rax), %xmm1
movq -0x1c8(%rbp), %rax
addq $0x10, %rax
movq -0x1a8(%rbp), %rcx
subq %rcx, %rax
xorl %ecx, %ecx
subq %rax, %rcx
leaq 0x7d398(%rip), %rax     # 0xc9d30
addq $0x10, %rax
addq %rcx, %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
vmovdqu (%rax), %xmm0
vmovdqa %xmm1, -0x100(%rbp)
vmovdqa %xmm0, -0x110(%rbp)
vmovdqa -0x100(%rbp), %xmm1
vmovdqa -0x110(%rbp), %xmm0
vmovdqa %xmm1, -0x70(%rbp)
vmovdqa %xmm0, -0x80(%rbp)
vmovdqa -0x70(%rbp), %xmm0
vmovdqa -0x80(%rbp), %xmm1
vpshufb %xmm1, %xmm0, %xmm0
vmovaps %xmm0, -0x210(%rbp)
movq -0x1b0(%rbp), %rax
addq $0xe, %rax
movl %eax, -0x178(%rbp)
movl $0x10, -0x17c(%rbp)
movl -0x178(%rbp), %eax
cmpl -0x17c(%rbp), %eax
jge 0x4ca29
movl -0x178(%rbp), %eax
movl %eax, -0x214(%rbp)
jmp 0x4ca35
movl -0x17c(%rbp), %eax
movl %eax, -0x214(%rbp)
vmovaps -0x210(%rbp), %xmm1
movl -0x214(%rbp), %eax
movslq %eax, %rcx
leaq 0x7d2e3(%rip), %rax     # 0xc9d30
addq $0x10, %rax
addq %rcx, %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
vmovdqu (%rax), %xmm0
vmovdqa %xmm1, -0x120(%rbp)
vmovdqa %xmm0, -0x130(%rbp)
vmovdqa -0x120(%rbp), %xmm1
vmovdqa -0x130(%rbp), %xmm0
vmovdqa %xmm1, -0x50(%rbp)
vmovdqa %xmm0, -0x60(%rbp)
vmovdqa -0x50(%rbp), %xmm0
vmovdqa -0x60(%rbp), %xmm1
vpshufb %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0x1c0(%rbp)
jmp 0x4cad4
movq -0x1a0(%rbp), %rcx
movslq -0x194(%rbp), %rax
addq %rax, %rcx
movq -0x190(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x188(%rbp)
jmp 0x4ce57
jmp 0x4cad6
vmovdqa -0x1c0(%rbp), %xmm0
vpxor %xmm1, %xmm1, %xmm1
vpcmpeqb %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0x1e0(%rbp)
vmovdqa -0x1c0(%rbp), %xmm0
vpsrldq $0x2, %xmm0, %xmm0      # xmm0 = xmm0[2,3,4,5,6,7,8,9,10,11,12,13,14,15],zero,zero
vmovdqa %xmm0, -0x1f0(%rbp)
vmovdqa -0x1e0(%rbp), %xmm0
vpsrldq $0x1, %xmm0, %xmm1      # xmm1 = xmm0[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15],zero
vpand %xmm1, %xmm0, %xmm0
vmovdqa -0x1f0(%rbp), %xmm1
vmovdqa 0x7ca8c(%rip), %xmm2    # 0xc95b0
vpcmpleub %xmm2, %xmm1, %k0
vpmovm2b %k0, %xmm1
vpand %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0xc0(%rbp)
vmovdqa -0xc0(%rbp), %xmm0
vpmovmskb %xmm0, %eax
movl %eax, -0x1f4(%rbp)
movl -0x1f4(%rbp), %eax
cmpq $0x0, %rax
je 0x4ce2b
jmp 0x4cb61
movl -0x1f4(%rbp), %eax
movl -0x194(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
subl $0x1, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x4ce29
movl -0x1f4(%rbp), %eax
tzcntl %eax, %eax
movl %eax, -0x1f8(%rbp)
movl -0x1f4(%rbp), %eax
movl -0x1f4(%rbp), %ecx
subl $0x1, %ecx
andl %ecx, %eax
shrl %eax
movl %eax, -0x1f4(%rbp)
movq -0x1a0(%rbp), %rax
movslq -0x1f8(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x3, %eax
jge 0x4cdb0
movq -0x1a0(%rbp), %rax
movslq -0x1f8(%rbp), %rcx
leaq -0x2(%rax,%rcx), %rcx
movq -0x190(%rbp), %rax
movq %rcx, 0x8(%rax)
movb $-0x1, -0x171(%rbp)
movb -0x171(%rbp), %al
movb %al, -0x215(%rbp)
movb %al, -0x81(%rbp)
movb %al, -0x82(%rbp)
movb %al, -0x83(%rbp)
movb %al, -0x84(%rbp)
movb %al, -0x85(%rbp)
movb %al, -0x86(%rbp)
movb %al, -0x87(%rbp)
movb %al, -0x88(%rbp)
movb %al, -0x89(%rbp)
movb %al, -0x8a(%rbp)
movb %al, -0x8b(%rbp)
movb %al, -0x8c(%rbp)
movb %al, -0x8d(%rbp)
movb %al, -0x8e(%rbp)
movb %al, -0x8f(%rbp)
movb %al, -0x90(%rbp)
movzbl -0x90(%rbp), %eax
vmovd %eax, %xmm0
movzbl -0x8f(%rbp), %eax
vpinsrb $0x1, %eax, %xmm0, %xmm0
movzbl -0x8e(%rbp), %eax
vpinsrb $0x2, %eax, %xmm0, %xmm0
movzbl -0x8d(%rbp), %eax
vpinsrb $0x3, %eax, %xmm0, %xmm0
movzbl -0x8c(%rbp), %eax
vpinsrb $0x4, %eax, %xmm0, %xmm0
movzbl -0x8b(%rbp), %eax
vpinsrb $0x5, %eax, %xmm0, %xmm0
movzbl -0x8a(%rbp), %eax
vpinsrb $0x6, %eax, %xmm0, %xmm0
movzbl -0x89(%rbp), %eax
vpinsrb $0x7, %eax, %xmm0, %xmm0
movzbl -0x88(%rbp), %eax
vpinsrb $0x8, %eax, %xmm0, %xmm0
movzbl -0x87(%rbp), %eax
vpinsrb $0x9, %eax, %xmm0, %xmm0
movzbl -0x86(%rbp), %eax
vpinsrb $0xa, %eax, %xmm0, %xmm0
movzbl -0x85(%rbp), %eax
vpinsrb $0xb, %eax, %xmm0, %xmm0
movzbl -0x84(%rbp), %eax
vpinsrb $0xc, %eax, %xmm0, %xmm0
movzbl -0x83(%rbp), %eax
vpinsrb $0xd, %eax, %xmm0, %xmm0
movzbl -0x82(%rbp), %eax
vpinsrb $0xe, %eax, %xmm0, %xmm0
movzbl -0x81(%rbp), %eax
vpinsrb $0xf, %eax, %xmm0, %xmm0
vmovdqa %xmm0, -0xa0(%rbp)
vmovdqa -0xa0(%rbp), %xmm1
movslq -0x1f8(%rbp), %rcx
leaq 0x7cfeb(%rip), %rax     # 0xc9d30
subq %rcx, %rax
addq $0x10, %rax
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
vmovdqu (%rax), %xmm0
vmovdqa %xmm1, -0x140(%rbp)
vmovdqa %xmm0, -0x150(%rbp)
vmovdqa -0x140(%rbp), %xmm1
vmovdqa -0x150(%rbp), %xmm0
vmovdqa %xmm1, -0x30(%rbp)
vmovdqa %xmm0, -0x40(%rbp)
vmovdqa -0x30(%rbp), %xmm0
vmovdqa -0x40(%rbp), %xmm1
vpshufb %xmm1, %xmm0, %xmm0
vpternlogq $0xf, %xmm0, %xmm0, %xmm0
vpand -0x1f0(%rbp), %xmm0, %xmm0
vmovdqa %xmm0, -0x1f0(%rbp)
jmp 0x4ce29
vmovdqa -0x1f0(%rbp), %xmm1
movslq -0x1f8(%rbp), %rcx
leaq 0x8002a(%rip), %rax     # 0xccdf0
shlq $0x4, %rcx
addq %rcx, %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm1, -0x160(%rbp)
vmovdqa %xmm0, -0x170(%rbp)
vmovdqa -0x160(%rbp), %xmm1
vmovdqa -0x170(%rbp), %xmm0
vmovdqa %xmm1, -0x10(%rbp)
vmovdqa %xmm0, -0x20(%rbp)
vmovdqa -0x10(%rbp), %xmm0
vmovdqa -0x20(%rbp), %xmm1
vpshufb %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0x1f0(%rbp)
movq -0x1a0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x1a0(%rbp)
jmp 0x4cb61
jmp 0x4ce2b
movq -0x1a0(%rbp), %rcx
movslq -0x194(%rbp), %rax
addq %rax, %rcx
movq -0x190(%rbp), %rax
movq %rcx, (%rax)
movq -0x1f0(%rbp), %rax
bswapq %rax
movq %rax, -0x188(%rbp)
movq -0x188(%rbp), %rax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopw (%rax,%rax)