#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*/ __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_epi32(int);
int /*<<< orphan*/ _mm256_srai_epi32(int /*<<< orphan*/, int);
__m256i butter_fly(__m256i a0, __m256i a1, const __m256i cospi) {
  const __m256i dct_rounding = _mm256_set1_epi32((1 << (14 - 1)));
  __m256i y0 = _mm256_madd_epi16(a0, cospi);
  __m256i y1 = _mm256_madd_epi16(a1, cospi);
  y0 = _mm256_add_epi32(y0, dct_rounding);
  y1 = _mm256_add_epi32(y1, dct_rounding);
  y0 = _mm256_srai_epi32(y0, 14);
  y1 = _mm256_srai_epi32(y1, 14);
  return _mm256_packs_epi32(y0, y1);
}


x86 assembly (clang, -O0):
<butter_fly>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    $0x2000,%edi
call   1040 <_mm256_set1_epi32@plt>
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <_mm256_madd_epi16@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1060 <_mm256_madd_epi16@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1070 <_mm256_add_epi32@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1070 <_mm256_add_epi32@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    $0xe,%esi
call   1050 <_mm256_srai_epi32@plt>
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
mov    $0xe,%esi
call   1050 <_mm256_srai_epi32@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1030 <_mm256_packs_epi32@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<butter_fly>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edi,%r15d
mov    $0x2000,%edi
call   1040 <_mm256_set1_epi32@plt>
mov    %eax,%ebp
mov    %r15d,%edi
mov    %ebx,%esi
call   1060 <_mm256_madd_epi16@plt>
mov    %eax,%r15d
mov    %r14d,%edi
mov    %ebx,%esi
call   1060 <_mm256_madd_epi16@plt>
mov    %eax,%ebx
mov    %r15d,%edi
mov    %ebp,%esi
call   1070 <_mm256_add_epi32@plt>
mov    %eax,%r14d
mov    %ebx,%edi
mov    %ebp,%esi
call   1070 <_mm256_add_epi32@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    $0xe,%esi
call   1050 <_mm256_srai_epi32@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    $0xe,%esi
call   1050 <_mm256_srai_epi32@plt>
mov    %ebp,%edi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <_mm256_packs_epi32@plt>

LLVM IR (-O0):
define i32 @butter_fly(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = call i32 @_mm256_set1_epi32(i32 8192)
store i32 %10, i32* %7
%11 = load i32, i32* %4
%12 = load i32, i32* %6
%13 = call i32 @_mm256_madd_epi16(i32 %11, i32 %12)
store i32 %13, i32* %8
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = call i32 @_mm256_madd_epi16(i32 %14, i32 %15)
store i32 %16, i32* %9
%17 = load i32, i32* %8
%18 = load i32, i32* %7
%19 = call i32 @_mm256_add_epi32(i32 %17, i32 %18)
store i32 %19, i32* %8
%20 = load i32, i32* %9
%21 = load i32, i32* %7
%22 = call i32 @_mm256_add_epi32(i32 %20, i32 %21)
store i32 %22, i32* %9
%23 = load i32, i32* %8
%24 = call i32 @_mm256_srai_epi32(i32 %23, i32 14)
store i32 %24, i32* %8
%25 = load i32, i32* %9
%26 = call i32 @_mm256_srai_epi32(i32 %25, i32 14)
store i32 %26, i32* %9
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = call i32 @_mm256_packs_epi32(i32 %27, i32 %28)
ret i32 %29
}

LLVM IR (-O2):
define i32 @butter_fly(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 @_mm256_set1_epi32(i32 8192)
%5 = tail call i32 @_mm256_madd_epi16(i32 %0, i32 %2)
%6 = tail call i32 @_mm256_madd_epi16(i32 %1, i32 %2)
%7 = tail call i32 @_mm256_add_epi32(i32 %5, i32 %4)
%8 = tail call i32 @_mm256_add_epi32(i32 %6, i32 %4)
%9 = tail call i32 @_mm256_srai_epi32(i32 %7, i32 14)
%10 = tail call i32 @_mm256_srai_epi32(i32 %8, i32 14)
%11 = tail call i32 @_mm256_packs_epi32(i32 %9, i32 %10)
ret i32 %11
}