#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*/ __m256i;

/* Variables and functions */
int /*<<< orphan*/ _mm256_add_epi32(int /*<<< orphan*/,
                                    int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm256_madd_epi16(int /*<<< orphan*/,
                                     int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm256_packs_epi32(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm256_set1_epi16(int /*<<< orphan*/ const);
int /*<<< orphan*/ _mm256_set1_epi32(int);
int /*<<< orphan*/ _mm256_setzero_si256();
int /*<<< orphan*/ _mm256_slli_epi16(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm256_srai_epi32(int /*<<< orphan*/, int);
int /*<<< orphan*/ _mm256_unpackhi_epi16(int /*<<< orphan*/ const,
                                         int /*<<< orphan*/);
int /*<<< orphan*/ _mm256_unpacklo_epi16(int /*<<< orphan*/ const,
                                         int /*<<< orphan*/);
void txfm_scaling16_avx2(const int16_t c, __m256i *in) {
  const __m256i zero = _mm256_setzero_si256();
  const __m256i sqrt2_epi16 = _mm256_set1_epi16(c);
  const __m256i dct_const_rounding = _mm256_set1_epi32((1 << (14 - 1)));
  __m256i u0, u1;
  int i = 0;
  while (i < 16) {
    in[i] = _mm256_slli_epi16(in[i], 1);
    u0 = _mm256_unpacklo_epi16(zero, in[i]);
    u1 = _mm256_unpackhi_epi16(zero, in[i]);
    u0 = _mm256_madd_epi16(u0, sqrt2_epi16);
    u1 = _mm256_madd_epi16(u1, sqrt2_epi16);
    u0 = _mm256_add_epi32(u0, dct_const_rounding);
    u1 = _mm256_add_epi32(u1, dct_const_rounding);
    u0 = _mm256_srai_epi32(u0, 14);
    u1 = _mm256_srai_epi32(u1, 14);
    in[i] = _mm256_packs_epi32(u0, u1);
    i++;
  }
}


x86 assembly (clang, -O0):
<txfm_scaling16_avx2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <_mm256_setzero_si256@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <_mm256_set1_epi16@plt>
mov    %eax,-0x18(%rbp)
mov    $0x2000,%edi
call   1070 <_mm256_set1_epi32@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x10,-0x28(%rbp)
jge    12ae <txfm_scaling16_avx2+0x10e>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    $0x1,%esi
call   1030 <_mm256_slli_epi16@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1040 <_mm256_unpacklo_epi16@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   10b0 <_mm256_unpackhi_epi16@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%esi
call   10a0 <_mm256_madd_epi16@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%esi
call   10a0 <_mm256_madd_epi16@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10c0 <_mm256_add_epi32@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10c0 <_mm256_add_epi32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    $0xe,%esi
call   1080 <_mm256_srai_epi32@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    $0xe,%esi
call   1080 <_mm256_srai_epi32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1060 <_mm256_packs_epi32@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11d8 <txfm_scaling16_avx2+0x38>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<txfm_scaling16_avx2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %edi,%ebp
xor    %r14d,%r14d
xor    %eax,%eax
call   1090 <_mm256_setzero_si256@plt>
mov    %eax,0x4(%rsp)
mov    %ebp,%edi
call   1050 <_mm256_set1_epi16@plt>
mov    %eax,%r15d
mov    $0x2000,%edi
call   1070 <_mm256_set1_epi32@plt>
mov    %eax,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13,%r14,4),%edi
mov    $0x1,%esi
call   1030 <_mm256_slli_epi16@plt>
mov    %eax,0x0(%r13,%r14,4)
mov    0x4(%rsp),%ebx
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <_mm256_unpacklo_epi16@plt>
mov    %eax,%ebp
mov    0x0(%r13,%r14,4),%esi
mov    %ebx,%edi
call   10b0 <_mm256_unpackhi_epi16@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r15d,%esi
call   10a0 <_mm256_madd_epi16@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r15d,%esi
call   10a0 <_mm256_madd_epi16@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r12d,%esi
call   10c0 <_mm256_add_epi32@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r12d,%esi
call   10c0 <_mm256_add_epi32@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    $0xe,%esi
call   1080 <_mm256_srai_epi32@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    $0xe,%esi
call   1080 <_mm256_srai_epi32@plt>
mov    %ebp,%edi
mov    %eax,%esi
call   1060 <_mm256_packs_epi32@plt>
mov    %eax,0x0(%r13,%r14,4)
add    $0x1,%r14
cmp    $0x10,%r14
jne    11e0 <txfm_scaling16_avx2+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @txfm_scaling16_avx2(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%11 = call i32 (...) @_mm256_setzero_si256()
store i32 %11, i32* %5
%12 = load i32, i32* %3
%13 = call i32 @_mm256_set1_epi16(i32 %12)
store i32 %13, i32* %6
%14 = call i32 @_mm256_set1_epi32(i32 8192)
store i32 %14, i32* %7
store i32 0, i32* %10
br label %15
15: ; preds = %18, %2
%16 = load i32, i32* %10
%17 = icmp slt i32 %16, 16
br i1 %17, label %18, label %68
18: ; preds = %15
%19 = load i32*, i32** %4
%20 = load i32, i32* %10
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = call i32 @_mm256_slli_epi16(i32 %23, i32 1)
%25 = load i32*, i32** %4
%26 = load i32, i32* %10
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
store i32 %24, i32* %28
%29 = load i32, i32* %5
%30 = load i32*, i32** %4
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = call i32 @_mm256_unpacklo_epi16(i32 %29, i32 %34)
store i32 %35, i32* %8
%36 = load i32, i32* %5
%37 = load i32*, i32** %4
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = call i32 @_mm256_unpackhi_epi16(i32 %36, i32 %41)
store i32 %42, i32* %9
%43 = load i32, i32* %8
%44 = load i32, i32* %6
%45 = call i32 @_mm256_madd_epi16(i32 %43, i32 %44)
store i32 %45, i32* %8
%46 = load i32, i32* %9
%47 = load i32, i32* %6
%48 = call i32 @_mm256_madd_epi16(i32 %46, i32 %47)
store i32 %48, i32* %9
%49 = load i32, i32* %8
%50 = load i32, i32* %7
%51 = call i32 @_mm256_add_epi32(i32 %49, i32 %50)
store i32 %51, i32* %8
%52 = load i32, i32* %9
%53 = load i32, i32* %7
%54 = call i32 @_mm256_add_epi32(i32 %52, i32 %53)
store i32 %54, i32* %9
%55 = load i32, i32* %8
%56 = call i32 @_mm256_srai_epi32(i32 %55, i32 14)
store i32 %56, i32* %8
%57 = load i32, i32* %9
%58 = call i32 @_mm256_srai_epi32(i32 %57, i32 14)
store i32 %58, i32* %9
%59 = load i32, i32* %8
%60 = load i32, i32* %9
%61 = call i32 @_mm256_packs_epi32(i32 %59, i32 %60)
%62 = load i32*, i32** %4
%63 = load i32, i32* %10
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i32, i32* %62, i64 %64
store i32 %61, i32* %65
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 1
store i32 %67, i32* %10
br label %15
68: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @txfm_scaling16_avx2(i32 %0, i32* nocapture %1) {
%3 = tail call i32 (...) @_mm256_setzero_si256()
%4 = tail call i32 @_mm256_set1_epi16(i32 %0)
%5 = tail call i32 @_mm256_set1_epi32(i32 8192)
br label %6
6: ; preds = %2, %6
%7 = phi i64 [ 0, %2 ], [ %21, %6 ]
%8 = getelementptr inbounds i32, i32* %1, i64 %7
%9 = load i32, i32* %8
%10 = tail call i32 @_mm256_slli_epi16(i32 %9, i32 1)
store i32 %10, i32* %8
%11 = tail call i32 @_mm256_unpacklo_epi16(i32 %3, i32 %10)
%12 = load i32, i32* %8
%13 = tail call i32 @_mm256_unpackhi_epi16(i32 %3, i32 %12)
%14 = tail call i32 @_mm256_madd_epi16(i32 %11, i32 %4)
%15 = tail call i32 @_mm256_madd_epi16(i32 %13, i32 %4)
%16 = tail call i32 @_mm256_add_epi32(i32 %14, i32 %5)
%17 = tail call i32 @_mm256_add_epi32(i32 %15, i32 %5)
%18 = tail call i32 @_mm256_srai_epi32(i32 %16, i32 14)
%19 = tail call i32 @_mm256_srai_epi32(i32 %17, i32 14)
%20 = tail call i32 @_mm256_packs_epi32(i32 %18, i32 %19)
store i32 %20, i32* %8
%21 = add nuw nsw i64 %7, 1
%22 = icmp eq i64 %21, 16
br i1 %22, label %23, label %6
23: ; preds = %6
ret void
}