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

/* Variables and functions */
int M_PI;
float cos(int);
int sqrt(double);
void ddct(const float X[], float x[]) {
  for (int n = 0; n < 32; ++n) {
    float sum = 0;
    for (int k = 0; k < 32; ++k) {
      float s = (k == 0) ? sqrt(.5) : 1;
      sum += s * X[k] * cos(M_PI * (n + .5) * k / 32);
    }
    x[n] = sum / 4;
  }
}


x86 assembly (clang, -O0):
<ddct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jge    123b <ddct+0x11b>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jge    120f <ddct+0xef>
cmpl   $0x0,-0x1c(%rbp)
jne    1179 <ddct+0x59>
movsd  0xe9c(%rip),%xmm0
call   1040 <sqrt@plt>
mov    %eax,-0x24(%rbp)
jmp    1186 <ddct+0x66>
mov    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1186 <ddct+0x66>
mov    -0x24(%rbp),%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mulss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x28(%rbp)
mov    0x2e38(%rip),%rax
cvtsi2sdl (%rax),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xe47(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe36(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1030 <cos@plt>
movaps %xmm0,%xmm2
movss  -0x28(%rbp),%xmm0
movss  -0x18(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1150 <ddct+0x30>
movss  -0x18(%rbp),%xmm0
movss  0xde4(%rip),%xmm1
divss  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1137 <ddct+0x17>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ddct>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r13
xor    %r15d,%r15d
mov    0x2eaa(%rip),%r12
jmp    115c <ddct+0x3c>
mulss  0xed0(%rip),%xmm0
movss  %xmm0,(%r14,%r15,4)
add    $0x1,%r15
cmp    $0x20,%r15
je     1296 <ddct+0x176>
xorps  %xmm1,%xmm1
cvtsi2sd %r15d,%xmm1
movsd  0xe94(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
call   1040 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sdl (%r12),%xmm0
mulsd  0x10(%rsp),%xmm0
mulsd  0xe7e(%rip),%xmm0
movsd  0xe6e(%rip),%xmm1
mulsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ss %eax,%xmm1
cvttsd2si %xmm0,%edi
mulss  0x0(%r13),%xmm1
movss  %xmm1,0x8(%rsp)
call   1030 <cos@plt>
movsd  0xe46(%rip),%xmm2
mulss  0x8(%rsp),%xmm0
addss  0xe4c(%rip),%xmm0
movss  %xmm0,0xc(%rsp)
mov    $0x1,%ebx
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sdl (%r12),%xmm0
movss  0x0(%r13,%rbx,4),%xmm1
movss  %xmm1,0x8(%rsp)
mulsd  0x10(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
mulsd  %xmm0,%xmm1
mulsd  %xmm2,%xmm1
cvttsd2si %xmm1,%edi
call   1030 <cos@plt>
mulss  0x8(%rsp),%xmm0
addss  0xc(%rsp),%xmm0
lea    0x1(%rbx),%rbp
cmp    $0x20,%rbp
je     1140 <ddct+0x20>
movss  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sdl (%r12),%xmm0
movss  0x4(%r13,%rbx,4),%xmm1
movss  %xmm1,0xc(%rsp)
mulsd  0x10(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
mulsd  %xmm0,%xmm1
movsd  0xda5(%rip),%xmm0
mulsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1030 <cos@plt>
mulss  0xc(%rsp),%xmm0
addss  0x8(%rsp),%xmm0
movss  %xmm0,0xc(%rsp)
add    $0x1,%rbp
mov    %rbp,%rbx
movsd  0xd77(%rip),%xmm2
jmp    11e0 <ddct+0xc0>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global i32 0
define void @ddct(float* %0, float* %1) {
%3 = alloca float*
%4 = alloca float*
%5 = alloca i32
%6 = alloca float
%7 = alloca i32
%8 = alloca float
store float* %0, float** %3
store float* %1, float** %4
store i32 0, i32* %5
br label %9
9: ; preds = %56, %2
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 32
br i1 %11, label %12, label %59
12: ; preds = %9
store float 0.000000e+00, float* %6
store i32 0, i32* %7
br label %13
13: ; preds = %46, %12
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 32
br i1 %15, label %16, label %49
16: ; preds = %13
%17 = load i32, i32* %7
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @sqrt(double 5.000000e-01)
br label %22
21: ; preds = %16
br label %22
22: ; preds = %21, %19
%23 = phi i32 [ %20, %19 ], [ 1, %21 ]
%24 = sitofp i32 %23 to float
store float %24, float* %8
%25 = load float, float* %8
%26 = load float*, float** %3
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds float, float* %26, i64 %28
%30 = load float, float* %29
%31 = fmul float %25, %30
%32 = load i32, i32* @M_PI
%33 = sitofp i32 %32 to double
%34 = load i32, i32* %5
%35 = sitofp i32 %34 to double
%36 = fadd double %35, 5.000000e-01
%37 = fmul double %33, %36
%38 = load i32, i32* %7
%39 = sitofp i32 %38 to double
%40 = fmul double %37, %39
%41 = fdiv double %40, 3.200000e+01
%42 = fptosi double %41 to i32
%43 = call float @cos(i32 %42)
%44 = load float, float* %6
%45 = call float @llvm.fmuladd.f32(float %31, float %43, float %44)
store float %45, float* %6
br label %46
46: ; preds = %22
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %13
49: ; preds = %13
%50 = load float, float* %6
%51 = fdiv float %50, 4.000000e+00
%52 = load float*, float** %4
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds float, float* %52, i64 %54
store float %51, float* %55
br label %56
56: ; preds = %49
%57 = load i32, i32* %5
%58 = add nsw i32 %57, 1
store i32 %58, i32* %5
br label %9
59: ; preds = %9
ret void
}

LLVM IR (-O2):
@M_PI = global i32 0
define void @ddct(float* nocapture %0, float* nocapture writeonly %1) {
br label %3
3: ; preds = %21, %2
%4 = phi i64 [ 0, %2 ], [ %24, %21 ]
%5 = trunc i64 %4 to i32
%6 = sitofp i32 %5 to double
%7 = fadd double %6, 5.000000e-01
%8 = tail call i32 @sqrt(double 5.000000e-01)
%9 = load float, float* %0
%10 = load i32, i32* @M_PI
%11 = sitofp i32 %10 to double
%12 = fmul double %7, %11
%13 = fmul double %12, 0.000000e+00
%14 = fmul double %13, 3.125000e-02
%15 = fptosi double %14 to i32
%16 = tail call float @cos(i32 %15)
%17 = sitofp i32 %8 to float
%18 = fmul float %9, %17
%19 = tail call float @llvm.fmuladd.f32(float %18, float %16, float 0.000000e+00)
br label %26
20: ; preds = %21
ret void
21: ; preds = %26
%22 = fmul float %40, 2.500000e-01
%23 = getelementptr inbounds float, float* %1, i64 %4
store float %22, float* %23
%24 = add nuw nsw i64 %4, 1
%25 = icmp eq i64 %24, 32
br i1 %25, label %20, label %3
26: ; preds = %43, %3
%27 = phi i64 [ 1, %3 ], [ %56, %43 ]
%28 = phi float [ %19, %3 ], [ %55, %43 ]
%29 = getelementptr inbounds float, float* %0, i64 %27
%30 = load float, float* %29
%31 = load i32, i32* @M_PI
%32 = sitofp i32 %31 to double
%33 = fmul double %7, %32
%34 = trunc i64 %27 to i32
%35 = sitofp i32 %34 to double
%36 = fmul double %33, %35
%37 = fmul double %36, 3.125000e-02
%38 = fptosi double %37 to i32
%39 = tail call float @cos(i32 %38)
%40 = tail call float @llvm.fmuladd.f32(float %30, float %39, float %28)
%41 = add nuw nsw i64 %27, 1
%42 = icmp eq i64 %41, 32
br i1 %42, label %21, label %43
43: ; preds = %26
%44 = getelementptr inbounds float, float* %0, i64 %41
%45 = load float, float* %44
%46 = load i32, i32* @M_PI
%47 = sitofp i32 %46 to double
%48 = fmul double %7, %47
%49 = trunc i64 %41 to i32
%50 = sitofp i32 %49 to double
%51 = fmul double %48, %50
%52 = fmul double %51, 3.125000e-02
%53 = fptosi double %52 to i32
%54 = tail call float @cos(i32 %53)
%55 = tail call float @llvm.fmuladd.f32(float %45, float %54, float %40)
%56 = add nuw nsw i64 %27, 2
br label %26
}