#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_add_epi16(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_load_si128(int /*<<< orphan*/ const *);
int /*<<< orphan*/ _mm_srai_epi16(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm_store_si128(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_sub_epi16(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ aom_hadamard_8x8_sse2(int /*<<< orphan*/ const *, int,
                                         int /*<<< orphan*/ *);
void aom_hadamard_16x16_sse2(int16_t const *src_diff, int src_stride,
                             int16_t *coeff) {
  int idx;
  for (idx = 0; idx < 4; ++idx) {
    int16_t const *src_ptr =
        src_diff + (idx >> 1) * 8 * src_stride + (idx & 0x01) * 8;
    aom_hadamard_8x8_sse2(src_ptr, src_stride, coeff + idx * 64);
  }
  for (idx = 0; idx < 64; idx += 8) {
    __m128i coeff0 = _mm_load_si128((const __m128i *)coeff);
    __m128i coeff1 = _mm_load_si128((const __m128i *)(coeff + 64));
    __m128i coeff2 = _mm_load_si128((const __m128i *)(coeff + 128));
    __m128i coeff3 = _mm_load_si128((const __m128i *)(coeff + 192));
    __m128i b0 = _mm_add_epi16(coeff0, coeff1);
    __m128i b1 = _mm_sub_epi16(coeff0, coeff1);
    __m128i b2 = _mm_add_epi16(coeff2, coeff3);
    __m128i b3 = _mm_sub_epi16(coeff2, coeff3);
    b0 = _mm_srai_epi16(b0, 1);
    b1 = _mm_srai_epi16(b1, 1);
    b2 = _mm_srai_epi16(b2, 1);
    b3 = _mm_srai_epi16(b3, 1);
    coeff0 = _mm_add_epi16(b0, b2);
    coeff1 = _mm_add_epi16(b1, b3);
    _mm_store_si128((__m128i *)coeff, coeff0);
    _mm_store_si128((__m128i *)(coeff + 64), coeff1);
    coeff2 = _mm_sub_epi16(b0, b2);
    coeff3 = _mm_sub_epi16(b1, b3);
    _mm_store_si128((__m128i *)(coeff + 128), coeff2);
    _mm_store_si128((__m128i *)(coeff + 192), coeff3);
    coeff += 8;
  }
}


x86 assembly (clang, -O0):
<aom_hadamard_16x16_sse2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    11e3 <aom_hadamard_16x16_sse2+0x83>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sar    $0x1,%ecx
shl    $0x3,%ecx
imul   -0xc(%rbp),%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    -0x1c(%rbp),%ecx
and    $0x1,%ecx
shl    $0x3,%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%eax
shl    $0x6,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdx
call   1070 <aom_hadamard_8x8_sse2@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    117a <aom_hadamard_16x16_sse2+0x1a>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x40,-0x1c(%rbp)
jge    1348 <aom_hadamard_16x16_sse2+0x1e8>
mov    -0x18(%rbp),%rdi
call   1040 <_mm_load_si128@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x100,%rdi
call   1040 <_mm_load_si128@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x200,%rdi
call   1040 <_mm_load_si128@plt>
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x300,%rdi
call   1040 <_mm_load_si128@plt>
mov    %eax,-0x38(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1050 <_mm_sub_epi16@plt>
mov    %eax,-0x40(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x38(%rbp),%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,-0x44(%rbp)
mov    -0x34(%rbp),%edi
mov    -0x38(%rbp),%esi
call   1050 <_mm_sub_epi16@plt>
mov    %eax,-0x48(%rbp)
mov    -0x3c(%rbp),%edi
mov    $0x1,%esi
call   1080 <_mm_srai_epi16@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x40(%rbp),%edi
mov    $0x1,%esi
call   1080 <_mm_srai_epi16@plt>
mov    %eax,-0x40(%rbp)
mov    -0x44(%rbp),%edi
mov    $0x1,%esi
call   1080 <_mm_srai_epi16@plt>
mov    %eax,-0x44(%rbp)
mov    -0x48(%rbp),%edi
mov    $0x1,%esi
call   1080 <_mm_srai_epi16@plt>
mov    %eax,-0x48(%rbp)
mov    -0x3c(%rbp),%edi
mov    -0x44(%rbp),%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x48(%rbp),%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1060 <_mm_store_si128@plt>
mov    -0x18(%rbp),%rdi
add    $0x100,%rdi
mov    -0x30(%rbp),%esi
call   1060 <_mm_store_si128@plt>
mov    -0x3c(%rbp),%edi
mov    -0x44(%rbp),%esi
call   1050 <_mm_sub_epi16@plt>
mov    %eax,-0x34(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x48(%rbp),%esi
call   1050 <_mm_sub_epi16@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x200,%rdi
mov    -0x34(%rbp),%esi
call   1060 <_mm_store_si128@plt>
mov    -0x18(%rbp),%rdi
add    $0x300,%rdi
mov    -0x38(%rbp),%esi
call   1060 <_mm_store_si128@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ea <aom_hadamard_16x16_sse2+0x8a>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aom_hadamard_16x16_sse2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r12
mov    %esi,%ebp
mov    %rdi,%r14
call   1070 <aom_hadamard_8x8_sse2@plt>
lea    0x20(%r14),%rdi
lea    0x100(%r12),%rdx
mov    %ebp,%esi
call   1070 <aom_hadamard_8x8_sse2@plt>
lea    0x0(,%rbp,8),%eax
movslq %eax,%rbx
lea    (%r14,%rbx,4),%rdi
lea    0x200(%r12),%rdx
mov    %ebp,%esi
call   1070 <aom_hadamard_8x8_sse2@plt>
lea    (%r14,%rbx,4),%rdi
add    $0x20,%rdi
lea    0x300(%r12),%rdx
mov    %ebp,%esi
call   1070 <aom_hadamard_8x8_sse2@plt>
mov    $0xfffffff8,%eax
nopw   0x0(%rax,%rax,1)
mov    %eax,0xc(%rsp)
mov    %r12,%rdi
call   1040 <_mm_load_si128@plt>
mov    %eax,%r15d
lea    0x100(%r12),%rdi
mov    %rdi,0x10(%rsp)
call   1040 <_mm_load_si128@plt>
mov    %eax,%ebx
lea    0x200(%r12),%rdi
mov    %rdi,0x20(%rsp)
call   1040 <_mm_load_si128@plt>
mov    %eax,%r14d
lea    0x300(%r12),%rdi
mov    %rdi,0x18(%rsp)
call   1040 <_mm_load_si128@plt>
mov    %eax,%ebp
mov    %r15d,%edi
mov    %ebx,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%r13d
mov    %r15d,%edi
mov    %ebx,%esi
call   1050 <_mm_sub_epi16@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %ebp,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%r15d
mov    %r14d,%edi
mov    %ebp,%esi
call   1050 <_mm_sub_epi16@plt>
mov    %eax,0x4(%rsp)
mov    %r13d,%edi
mov    $0x1,%esi
call   1080 <_mm_srai_epi16@plt>
mov    %eax,%ebp
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
mov    $0x1,%esi
call   1080 <_mm_srai_epi16@plt>
mov    %eax,%r13d
mov    %r15d,%edi
mov    $0x1,%esi
call   1080 <_mm_srai_epi16@plt>
mov    %eax,%r14d
mov    0x4(%rsp),%edi
mov    $0x1,%esi
call   1080 <_mm_srai_epi16@plt>
mov    %eax,%r15d
mov    %ebp,%edi
mov    %r14d,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%ebx
mov    %r13d,%edi
mov    %r15d,%esi
call   1030 <_mm_add_epi16@plt>
mov    %eax,%ebp
mov    %r12,%rdi
mov    %ebx,%esi
call   1060 <_mm_store_si128@plt>
mov    0x10(%rsp),%rdi
mov    %ebp,%esi
call   1060 <_mm_store_si128@plt>
mov    0x8(%rsp),%edi
mov    %r14d,%esi
call   1050 <_mm_sub_epi16@plt>
mov    %eax,%ebx
mov    %r13d,%edi
mov    %r15d,%esi
call   1050 <_mm_sub_epi16@plt>
mov    %eax,%ebp
mov    0x20(%rsp),%rdi
mov    %ebx,%esi
call   1060 <_mm_store_si128@plt>
mov    0x18(%rsp),%rdi
mov    %ebp,%esi
call   1060 <_mm_store_si128@plt>
mov    0xc(%rsp),%eax
add    $0x8,%eax
add    $0x20,%r12
cmp    $0x38,%eax
jb     11d0 <aom_hadamard_16x16_sse2+0x70>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @aom_hadamard_16x16_sse2(i32* %0, i32 %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%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
store i32* %0, i32** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
store i32 0, i32* %7
br label %17
17: ; preds = %42, %3
%18 = load i32, i32* %7
%19 = icmp slt i32 %18, 4
br i1 %19, label %20, label %45
20: ; preds = %17
%21 = load i32*, i32** %4
%22 = load i32, i32* %7
%23 = ashr i32 %22, 1
%24 = mul nsw i32 %23, 8
%25 = load i32, i32* %5
%26 = mul nsw i32 %24, %25
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %21, i64 %27
%29 = load i32, i32* %7
%30 = and i32 %29, 1
%31 = mul nsw i32 %30, 8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %28, i64 %32
store i32* %33, i32** %8
%34 = load i32*, i32** %8
%35 = load i32, i32* %5
%36 = load i32*, i32** %6
%37 = load i32, i32* %7
%38 = mul nsw i32 %37, 64
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %36, i64 %39
%41 = call i32 @aom_hadamard_8x8_sse2(i32* %34, i32 %35, i32* %40)
br label %42
42: ; preds = %20
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %17
45: ; preds = %17
store i32 0, i32* %7
br label %46
46: ; preds = %110, %45
%47 = load i32, i32* %7
%48 = icmp slt i32 %47, 64
br i1 %48, label %49, label %113
49: ; preds = %46
%50 = load i32*, i32** %6
%51 = call i32 @_mm_load_si128(i32* %50)
store i32 %51, i32* %9
%52 = load i32*, i32** %6
%53 = getelementptr inbounds i32, i32* %52, i64 64
%54 = call i32 @_mm_load_si128(i32* %53)
store i32 %54, i32* %10
%55 = load i32*, i32** %6
%56 = getelementptr inbounds i32, i32* %55, i64 128
%57 = call i32 @_mm_load_si128(i32* %56)
store i32 %57, i32* %11
%58 = load i32*, i32** %6
%59 = getelementptr inbounds i32, i32* %58, i64 192
%60 = call i32 @_mm_load_si128(i32* %59)
store i32 %60, i32* %12
%61 = load i32, i32* %9
%62 = load i32, i32* %10
%63 = call i32 @_mm_add_epi16(i32 %61, i32 %62)
store i32 %63, i32* %13
%64 = load i32, i32* %9
%65 = load i32, i32* %10
%66 = call i32 @_mm_sub_epi16(i32 %64, i32 %65)
store i32 %66, i32* %14
%67 = load i32, i32* %11
%68 = load i32, i32* %12
%69 = call i32 @_mm_add_epi16(i32 %67, i32 %68)
store i32 %69, i32* %15
%70 = load i32, i32* %11
%71 = load i32, i32* %12
%72 = call i32 @_mm_sub_epi16(i32 %70, i32 %71)
store i32 %72, i32* %16
%73 = load i32, i32* %13
%74 = call i32 @_mm_srai_epi16(i32 %73, i32 1)
store i32 %74, i32* %13
%75 = load i32, i32* %14
%76 = call i32 @_mm_srai_epi16(i32 %75, i32 1)
store i32 %76, i32* %14
%77 = load i32, i32* %15
%78 = call i32 @_mm_srai_epi16(i32 %77, i32 1)
store i32 %78, i32* %15
%79 = load i32, i32* %16
%80 = call i32 @_mm_srai_epi16(i32 %79, i32 1)
store i32 %80, i32* %16
%81 = load i32, i32* %13
%82 = load i32, i32* %15
%83 = call i32 @_mm_add_epi16(i32 %81, i32 %82)
store i32 %83, i32* %9
%84 = load i32, i32* %14
%85 = load i32, i32* %16
%86 = call i32 @_mm_add_epi16(i32 %84, i32 %85)
store i32 %86, i32* %10
%87 = load i32*, i32** %6
%88 = load i32, i32* %9
%89 = call i32 @_mm_store_si128(i32* %87, i32 %88)
%90 = load i32*, i32** %6
%91 = getelementptr inbounds i32, i32* %90, i64 64
%92 = load i32, i32* %10
%93 = call i32 @_mm_store_si128(i32* %91, i32 %92)
%94 = load i32, i32* %13
%95 = load i32, i32* %15
%96 = call i32 @_mm_sub_epi16(i32 %94, i32 %95)
store i32 %96, i32* %11
%97 = load i32, i32* %14
%98 = load i32, i32* %16
%99 = call i32 @_mm_sub_epi16(i32 %97, i32 %98)
store i32 %99, i32* %12
%100 = load i32*, i32** %6
%101 = getelementptr inbounds i32, i32* %100, i64 128
%102 = load i32, i32* %11
%103 = call i32 @_mm_store_si128(i32* %101, i32 %102)
%104 = load i32*, i32** %6
%105 = getelementptr inbounds i32, i32* %104, i64 192
%106 = load i32, i32* %12
%107 = call i32 @_mm_store_si128(i32* %105, i32 %106)
%108 = load i32*, i32** %6
%109 = getelementptr inbounds i32, i32* %108, i64 8
store i32* %109, i32** %6
br label %110
110: ; preds = %49
%111 = load i32, i32* %7
%112 = add nsw i32 %111, 8
store i32 %112, i32* %7
br label %46
113: ; preds = %46
ret void
}

LLVM IR (-O2):
define void @aom_hadamard_16x16_sse2(i32* %0, i32 %1, i32* %2) {
%4 = tail call i32 @aom_hadamard_8x8_sse2(i32* %0, i32 %1, i32* %2)
%5 = getelementptr inbounds i32, i32* %0, i64 8
%6 = getelementptr inbounds i32, i32* %2, i64 64
%7 = tail call i32 @aom_hadamard_8x8_sse2(i32* %5, i32 %1, i32* %6)
%8 = shl nsw i32 %1, 3
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = getelementptr inbounds i32, i32* %2, i64 128
%12 = tail call i32 @aom_hadamard_8x8_sse2(i32* %10, i32 %1, i32* %11)
%13 = getelementptr inbounds i32, i32* %10, i64 8
%14 = getelementptr inbounds i32, i32* %2, i64 192
%15 = tail call i32 @aom_hadamard_8x8_sse2(i32* %13, i32 %1, i32* %14)
br label %16
16: ; preds = %3, %16
%17 = phi i32* [ %42, %16 ], [ %2, %3 ]
%18 = phi i32 [ %43, %16 ], [ 0, %3 ]
%19 = tail call i32 @_mm_load_si128(i32* %17)
%20 = getelementptr inbounds i32, i32* %17, i64 64
%21 = tail call i32 @_mm_load_si128(i32* %20)
%22 = getelementptr inbounds i32, i32* %17, i64 128
%23 = tail call i32 @_mm_load_si128(i32* %22)
%24 = getelementptr inbounds i32, i32* %17, i64 192
%25 = tail call i32 @_mm_load_si128(i32* %24)
%26 = tail call i32 @_mm_add_epi16(i32 %19, i32 %21)
%27 = tail call i32 @_mm_sub_epi16(i32 %19, i32 %21)
%28 = tail call i32 @_mm_add_epi16(i32 %23, i32 %25)
%29 = tail call i32 @_mm_sub_epi16(i32 %23, i32 %25)
%30 = tail call i32 @_mm_srai_epi16(i32 %26, i32 1)
%31 = tail call i32 @_mm_srai_epi16(i32 %27, i32 1)
%32 = tail call i32 @_mm_srai_epi16(i32 %28, i32 1)
%33 = tail call i32 @_mm_srai_epi16(i32 %29, i32 1)
%34 = tail call i32 @_mm_add_epi16(i32 %30, i32 %32)
%35 = tail call i32 @_mm_add_epi16(i32 %31, i32 %33)
%36 = tail call i32 @_mm_store_si128(i32* %17, i32 %34)
%37 = tail call i32 @_mm_store_si128(i32* %20, i32 %35)
%38 = tail call i32 @_mm_sub_epi16(i32 %30, i32 %32)
%39 = tail call i32 @_mm_sub_epi16(i32 %31, i32 %33)
%40 = tail call i32 @_mm_store_si128(i32* %22, i32 %38)
%41 = tail call i32 @_mm_store_si128(i32* %24, i32 %39)
%42 = getelementptr inbounds i32, i32* %17, i64 8
%43 = add nuw nsw i32 %18, 8
%44 = icmp ult i32 %18, 56
br i1 %44, label %16, label %45
45: ; preds = %16
ret void
}