#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ int16_t;
typedef int /*<<< orphan*/ __m128i;

/* Variables and functions */
int /*<<< orphan*/ _mm_andnot_si128(int /*<<< orphan*/ const,
                                    int /*<<< orphan*/);
int /*<<< orphan*/ _mm_cmpeq_epi16(int /*<<< orphan*/,
                                   int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm_load_si128(int /*<<< orphan*/ const *);
int /*<<< orphan*/ _mm_max_epi16(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_sub_epi16(int /*<<< orphan*/, int /*<<< orphan*/ const);
__m128i scan_for_eob(__m128i *coeff0, __m128i *coeff1, const __m128i zbin_mask0,
                     const __m128i zbin_mask1, const int16_t *scan,
                     const int index, const __m128i zero) {
  const __m128i zero_coeff0 = _mm_cmpeq_epi16(*coeff0, zero);
  const __m128i zero_coeff1 = _mm_cmpeq_epi16(*coeff1, zero);
  __m128i scan0 = _mm_load_si128((const __m128i *)(scan + index));
  __m128i scan1 = _mm_load_si128((const __m128i *)(scan + index + 8));
  __m128i eob0, eob1;
  scan0 = _mm_sub_epi16(scan0, zbin_mask0);
  scan1 = _mm_sub_epi16(scan1, zbin_mask1);
  eob0 = _mm_andnot_si128(zero_coeff0, scan0);
  eob1 = _mm_andnot_si128(zero_coeff1, scan1);
  return _mm_max_epi16(eob0, eob1);
}


x86 assembly (clang, -O0):
<scan_for_eob>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x10(%rbp),%esi
call   1060 <_mm_cmpeq_epi16@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    0x10(%rbp),%esi
call   1060 <_mm_cmpeq_epi16@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1030 <_mm_load_si128@plt>
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
add    $0x20,%rdi
call   1030 <_mm_load_si128@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1040 <_mm_sub_epi16@plt>
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <_mm_sub_epi16@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1070 <_mm_andnot_si128@plt>
mov    %eax,-0x38(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1070 <_mm_andnot_si128@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x3c(%rbp),%esi
call   1050 <_mm_max_epi16@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_for_eob>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,%r14d
mov    %r8,%r15
mov    %ecx,0x4(%rsp)
mov    %edx,%r12d
mov    %rsi,%r13
mov    0x40(%rsp),%ebx
mov    (%rdi),%edi
mov    %ebx,%esi
call   1060 <_mm_cmpeq_epi16@plt>
mov    %eax,(%rsp)
mov    0x0(%r13),%edi
mov    %ebx,%esi
call   1060 <_mm_cmpeq_epi16@plt>
mov    %eax,%r13d
movslq %r14d,%rbp
lea    (%r15,%rbp,4),%rdi
call   1030 <_mm_load_si128@plt>
mov    %eax,%ebx
lea    (%r15,%rbp,4),%rdi
add    $0x20,%rdi
call   1030 <_mm_load_si128@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r12d,%esi
call   1040 <_mm_sub_epi16@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    0x4(%rsp),%esi
call   1040 <_mm_sub_epi16@plt>
mov    %eax,%ebp
mov    (%rsp),%edi
mov    %ebx,%esi
call   1070 <_mm_andnot_si128@plt>
mov    %eax,%ebx
mov    %r13d,%edi
mov    %ebp,%esi
call   1070 <_mm_andnot_si128@plt>
mov    %ebx,%edi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <_mm_max_epi16@plt>

LLVM IR (-O0):
define i32 @scan_for_eob(i32* %0, i32* %1, i32 %2, i32 %3, i32* %4, i32 %5, i32 %6) {
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
store i32* %0, i32** %8
store i32* %1, i32** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32* %4, i32** %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%21 = load i32*, i32** %8
%22 = load i32, i32* %21
%23 = load i32, i32* %14
%24 = call i32 @_mm_cmpeq_epi16(i32 %22, i32 %23)
store i32 %24, i32* %15
%25 = load i32*, i32** %9
%26 = load i32, i32* %25
%27 = load i32, i32* %14
%28 = call i32 @_mm_cmpeq_epi16(i32 %26, i32 %27)
store i32 %28, i32* %16
%29 = load i32*, i32** %12
%30 = load i32, i32* %13
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = call i32 @_mm_load_si128(i32* %32)
store i32 %33, i32* %17
%34 = load i32*, i32** %12
%35 = load i32, i32* %13
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
%38 = getelementptr inbounds i32, i32* %37, i64 8
%39 = call i32 @_mm_load_si128(i32* %38)
store i32 %39, i32* %18
%40 = load i32, i32* %17
%41 = load i32, i32* %10
%42 = call i32 @_mm_sub_epi16(i32 %40, i32 %41)
store i32 %42, i32* %17
%43 = load i32, i32* %18
%44 = load i32, i32* %11
%45 = call i32 @_mm_sub_epi16(i32 %43, i32 %44)
store i32 %45, i32* %18
%46 = load i32, i32* %15
%47 = load i32, i32* %17
%48 = call i32 @_mm_andnot_si128(i32 %46, i32 %47)
store i32 %48, i32* %19
%49 = load i32, i32* %16
%50 = load i32, i32* %18
%51 = call i32 @_mm_andnot_si128(i32 %49, i32 %50)
store i32 %51, i32* %20
%52 = load i32, i32* %19
%53 = load i32, i32* %20
%54 = call i32 @_mm_max_epi16(i32 %52, i32 %53)
ret i32 %54
}

LLVM IR (-O2):
define i32 @scan_for_eob(i32* nocapture %0, i32* nocapture %1, i32 %2, i32 %3, i32* %4, i32 %5, i32 %6) {
%8 = load i32, i32* %0
%9 = tail call i32 @_mm_cmpeq_epi16(i32 %8, i32 %6)
%10 = load i32, i32* %1
%11 = tail call i32 @_mm_cmpeq_epi16(i32 %10, i32 %6)
%12 = sext i32 %5 to i64
%13 = getelementptr inbounds i32, i32* %4, i64 %12
%14 = tail call i32 @_mm_load_si128(i32* %13)
%15 = getelementptr inbounds i32, i32* %13, i64 8
%16 = tail call i32 @_mm_load_si128(i32* %15)
%17 = tail call i32 @_mm_sub_epi16(i32 %14, i32 %2)
%18 = tail call i32 @_mm_sub_epi16(i32 %16, i32 %3)
%19 = tail call i32 @_mm_andnot_si128(i32 %9, i32 %17)
%20 = tail call i32 @_mm_andnot_si128(i32 %11, i32 %18)
%21 = tail call i32 @_mm_max_epi16(i32 %19, i32 %20)
ret i32 %21
}