// File: /workspace/github_c_makefile_star2_O0/tvlabs[P]edge264/edge264.c
// Function: edge264_find_start_code
const uint8_t *edge264_find_start_code(const uint8_t *buf, const uint8_t *end, int four_byte) {
	const i8x16 *p = (i8x16 *)((uintptr_t)buf & -16);
	four_byte = four_byte != 0;
	i8x16 zero = {};
	i8x16 c1 = set8(1);
	i8x16 lo0 = {};
	i8x16 v = *p;
	i8x16 hi0 = (v == zero) & shlv128(set8(-1), (uintptr_t)buf & 15);
	while (1) {
		#if defined(__SSE2__)
			unsigned m = movemask(shrd128(lo0, hi0, 14) & shrd128(lo0, hi0, 15) & (v == c1));
			if (m) {
				const uint8_t *res = (uint8_t *)p - 2 - four_byte + __builtin_ctz(m);
				if (*res == 0)
					return minp(res, end);
			}
		#elif defined(__ARM_NEON)
			uint64_t m = (uint64_t)vshrn_n_u16(shrd128(lo0, hi0, 14) & shrd128(lo0, hi0, 15) & (v == c1), 4);
			if (m) {
				const uint8_t *res = (uint8_t *)p - 2 - four_byte + (__builtin_ctzll(m) >> 2);
				if (*res == 0)
					return minp(res, end);
			}
		#endif
		if ((intptr_t)(end - (uint8_t *)++p) <= 0)
			return end;
		lo0 = hi0;
		hi0 = ((v = *p) == zero);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0xc8(%rbp)
movq %rsi, -0xd0(%rbp)
movl %edx, -0xd4(%rbp)
movq -0xc8(%rbp), %rax
andq $-0x10, %rax
movq %rax, -0xe0(%rbp)
movl -0xd4(%rbp), %eax
testl %eax, %eax
setne %al
movzbl %al, %eax
movl %eax, -0xd4(%rbp)
vpxor %xmm0, %xmm0, %xmm0
vmovdqa %xmm0, -0xf0(%rbp)
movb $0x1, -0xb1(%rbp)
movb -0xb1(%rbp), %al
movb %al, -0x142(%rbp)
movb %al, -0x41(%rbp)
movb %al, -0x42(%rbp)
movb %al, -0x43(%rbp)
movb %al, -0x44(%rbp)
movb %al, -0x45(%rbp)
movb %al, -0x46(%rbp)
movb %al, -0x47(%rbp)
movb %al, -0x48(%rbp)
movb %al, -0x49(%rbp)
movb %al, -0x4a(%rbp)
movb %al, -0x4b(%rbp)
movb %al, -0x4c(%rbp)
movb %al, -0x4d(%rbp)
movb %al, -0x4e(%rbp)
movb %al, -0x4f(%rbp)
movb %al, -0x50(%rbp)
movzbl -0x50(%rbp), %eax
vmovd %eax, %xmm1
movzbl -0x4f(%rbp), %eax
vpinsrb $0x1, %eax, %xmm1, %xmm1
movzbl -0x4e(%rbp), %eax
vpinsrb $0x2, %eax, %xmm1, %xmm1
movzbl -0x4d(%rbp), %eax
vpinsrb $0x3, %eax, %xmm1, %xmm1
movzbl -0x4c(%rbp), %eax
vpinsrb $0x4, %eax, %xmm1, %xmm1
movzbl -0x4b(%rbp), %eax
vpinsrb $0x5, %eax, %xmm1, %xmm1
movzbl -0x4a(%rbp), %eax
vpinsrb $0x6, %eax, %xmm1, %xmm1
movzbl -0x49(%rbp), %eax
vpinsrb $0x7, %eax, %xmm1, %xmm1
movzbl -0x48(%rbp), %eax
vpinsrb $0x8, %eax, %xmm1, %xmm1
movzbl -0x47(%rbp), %eax
vpinsrb $0x9, %eax, %xmm1, %xmm1
movzbl -0x46(%rbp), %eax
vpinsrb $0xa, %eax, %xmm1, %xmm1
movzbl -0x45(%rbp), %eax
vpinsrb $0xb, %eax, %xmm1, %xmm1
movzbl -0x44(%rbp), %eax
vpinsrb $0xc, %eax, %xmm1, %xmm1
movzbl -0x43(%rbp), %eax
vpinsrb $0xd, %eax, %xmm1, %xmm1
movzbl -0x42(%rbp), %eax
vpinsrb $0xe, %eax, %xmm1, %xmm1
movzbl -0x41(%rbp), %eax
vpinsrb $0xf, %eax, %xmm1, %xmm1
vmovdqa %xmm1, -0x60(%rbp)
vmovdqa -0x60(%rbp), %xmm1
vmovdqa %xmm1, -0x100(%rbp)
vmovdqa %xmm0, -0x110(%rbp)
movq -0xe0(%rbp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm0, -0x120(%rbp)
vmovdqa -0x120(%rbp), %xmm0
vmovdqa -0xf0(%rbp), %xmm1
vpcmpeqb %xmm1, %xmm0, %xmm0
movb $-0x1, -0xb2(%rbp)
movb -0xb2(%rbp), %al
movb %al, -0x141(%rbp)
movb %al, -0x21(%rbp)
movb %al, -0x22(%rbp)
movb %al, -0x23(%rbp)
movb %al, -0x24(%rbp)
movb %al, -0x25(%rbp)
movb %al, -0x26(%rbp)
movb %al, -0x27(%rbp)
movb %al, -0x28(%rbp)
movb %al, -0x29(%rbp)
movb %al, -0x2a(%rbp)
movb %al, -0x2b(%rbp)
movb %al, -0x2c(%rbp)
movb %al, -0x2d(%rbp)
movb %al, -0x2e(%rbp)
movb %al, -0x2f(%rbp)
movb %al, -0x30(%rbp)
movzbl -0x30(%rbp), %eax
vmovd %eax, %xmm1
movzbl -0x2f(%rbp), %eax
vpinsrb $0x1, %eax, %xmm1, %xmm1
movzbl -0x2e(%rbp), %eax
vpinsrb $0x2, %eax, %xmm1, %xmm1
movzbl -0x2d(%rbp), %eax
vpinsrb $0x3, %eax, %xmm1, %xmm1
movzbl -0x2c(%rbp), %eax
vpinsrb $0x4, %eax, %xmm1, %xmm1
movzbl -0x2b(%rbp), %eax
vpinsrb $0x5, %eax, %xmm1, %xmm1
movzbl -0x2a(%rbp), %eax
vpinsrb $0x6, %eax, %xmm1, %xmm1
movzbl -0x29(%rbp), %eax
vpinsrb $0x7, %eax, %xmm1, %xmm1
movzbl -0x28(%rbp), %eax
vpinsrb $0x8, %eax, %xmm1, %xmm1
movzbl -0x27(%rbp), %eax
vpinsrb $0x9, %eax, %xmm1, %xmm1
movzbl -0x26(%rbp), %eax
vpinsrb $0xa, %eax, %xmm1, %xmm1
movzbl -0x25(%rbp), %eax
vpinsrb $0xb, %eax, %xmm1, %xmm1
movzbl -0x24(%rbp), %eax
vpinsrb $0xc, %eax, %xmm1, %xmm1
movzbl -0x23(%rbp), %eax
vpinsrb $0xd, %eax, %xmm1, %xmm1
movzbl -0x22(%rbp), %eax
vpinsrb $0xe, %eax, %xmm1, %xmm1
movzbl -0x21(%rbp), %eax
vpinsrb $0xf, %eax, %xmm1, %xmm1
vmovdqa %xmm1, -0x40(%rbp)
vmovdqa -0x40(%rbp), %xmm2
movq -0xc8(%rbp), %rax
andq $0xf, %rax
xorl %ecx, %ecx
subq %rax, %rcx
leaq 0xae19b(%rip), %rax     # 0xc9d30
addq $0x10, %rax
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
vmovdqu (%rax), %xmm1
vmovdqa %xmm2, -0xa0(%rbp)
vmovdqa %xmm1, -0xb0(%rbp)
vmovdqa -0xa0(%rbp), %xmm2
vmovdqa -0xb0(%rbp), %xmm1
vmovdqa %xmm2, -0x10(%rbp)
vmovdqa %xmm1, -0x20(%rbp)
vmovdqa -0x10(%rbp), %xmm1
vmovdqa -0x20(%rbp), %xmm2
vpshufb %xmm2, %xmm1, %xmm1
vpand %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0x130(%rbp)
vmovdqa -0x130(%rbp), %xmm1
vmovdqa -0x110(%rbp), %xmm2
vpalignr $0xe, %xmm2, %xmm1, %xmm0 # xmm0 = xmm2[14,15],xmm1[0,1,2,3,4,5,6,7,8,9,10,11,12,13]
vpalignr $0xf, %xmm2, %xmm1, %xmm1 # xmm1 = xmm2[15],xmm1[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14]
vpand %xmm1, %xmm0, %xmm0
vmovdqa -0x120(%rbp), %xmm1
vmovdqa -0x100(%rbp), %xmm2
vpcmpeqb %xmm2, %xmm1, %k0
vpmovm2b %k0, %xmm1
vpand %xmm1, %xmm0, %xmm0
vmovdqa %xmm0, -0x80(%rbp)
vmovdqa -0x80(%rbp), %xmm0
vpmovmskb %xmm0, %eax
movl %eax, -0x134(%rbp)
cmpl $0x0, -0x134(%rbp)
je 0x1bce5
movq -0xe0(%rbp), %rax
addq $-0x2, %rax
movslq -0xd4(%rbp), %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movl -0x134(%rbp), %ecx
tzcntl %ecx, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x140(%rbp)
movq -0x140(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x1bce3
movq -0x140(%rbp), %rcx
movq -0xd0(%rbp), %rax
movq %rcx, -0x68(%rbp)
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
movq -0x70(%rbp), %rcx
subq %rcx, %rax
cmpq $0x0, %rax
jge 0x1bcc8
movq -0x68(%rbp), %rax
movq %rax, -0x150(%rbp)
jmp 0x1bcd3
movq -0x70(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x150(%rbp), %rax
movq %rax, -0xc0(%rbp)
jmp 0x1bd5b
jmp 0x1bce5
movq -0xd0(%rbp), %rax
movq -0xe0(%rbp), %rcx
addq $0x10, %rcx
movq %rcx, -0xe0(%rbp)
subq %rcx, %rax
cmpq $0x0, %rax
jg 0x1bd17
movq -0xd0(%rbp), %rax
movq %rax, -0xc0(%rbp)
jmp 0x1bd5b
vmovdqa -0x130(%rbp), %xmm0
vmovdqa %xmm0, -0x110(%rbp)
movq -0xe0(%rbp), %rax
vmovdqa (%rax), %xmm0
vmovdqa %xmm0, -0x120(%rbp)
vmovdqa -0xf0(%rbp), %xmm1
vpcmpeqb %xmm1, %xmm0, %k0
vpmovm2b %k0, %xmm0
vmovdqa %xmm0, -0x130(%rbp)
jmp 0x1bbf3
movq -0xc0(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax,%rax)