#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 */
double cos(unsigned int);
double sqrt(double);
void dct(double *b, double *x, unsigned n, unsigned m) {
  for (unsigned i = 0; i < m; i++) {
    for (unsigned j = 0; j < n; j++) {
      if (i == 0) {
        b[i] += 1 / sqrt(n) * x[j];
        continue;
      }
      b[i] += sqrt(2.0 / n) *
              cos(i * 3.14159265358979323846 / (2.0 * n) * (2.0 * j + 1)) *
              x[j];
    }
  }
}


x86 assembly (clang, -O0):
<dct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    1268 <dct+0x148>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1255 <dct+0x135>
cmpl   $0x0,-0x1c(%rbp)
jne    11ac <dct+0x8c>
mov    -0x14(%rbp),%eax
cvtsi2sd %rax,%xmm0
call   1040 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe92(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1247 <dct+0x127>
mov    -0x14(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  0xe44(%rip),%xmm0
divsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe2e(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x14(%rbp),%eax
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm1
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%eax
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm1
movsd  0xe0e(%rip),%xmm2
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%edi
call   1030 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm2
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1150 <dct+0x30>
jmp    125a <dct+0x13a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113d <dct+0x1d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dct>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edx,0x4(%rsp)
test   %ecx,%ecx
je     1296 <dct+0x176>
mov    %rsi,%r13
mov    %rdi,%r15
mov    0x4(%rsp),%ebp
cvtsi2sd %rbp,%xmm0
movsd  0xeaf(%rip),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
addsd  %xmm0,%xmm2
movsd  %xmm2,0x18(%rsp)
mov    %ecx,%eax
mov    %rax,0x20(%rsp)
xor    %ebx,%ebx
movsd  %xmm0,0x8(%rsp)
sqrtsd %xmm0,%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  %xmm1,0x10(%rsp)
xorps  %xmm0,%xmm0
sqrtsd %xmm1,%xmm0
movsd  %xmm0,0x30(%rsp)
jmp    11af <dct+0x8f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    0x20(%rsp),%rbx
je     1296 <dct+0x176>
cmpl   $0x0,0x4(%rsp)
je     11a0 <dct+0x80>
mov    %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mulsd  0xe40(%rip),%xmm0
divsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x38(%rsp)
lea    (%r15,%rbx,8),%r14
xor    %r12d,%r12d
jmp    1232 <dct+0x112>
nopl   (%rax)
movsd  %xmm0,0x40(%rsp)
mov    %r12d,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
addsd  %xmm0,%xmm0
addsd  0xe13(%rip),%xmm0
mulsd  0x38(%rsp),%xmm0
cvttsd2si %xmm0,%rdi
call   1030 <cos@plt>
mulsd  0x40(%rsp),%xmm0
mov    %r14,%rax
mulsd  0x0(%r13,%r12,8),%xmm0
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
add    $0x1,%r12
cmp    %r12,%rbp
je     11a0 <dct+0x80>
test   %rbx,%rbx
je     1260 <dct+0x140>
movsd  0x10(%rsp),%xmm0
ucomisd 0xdd3(%rip),%xmm0
movsd  0x30(%rsp),%xmm0
jae    11e0 <dct+0xc0>
movsd  0x10(%rsp),%xmm0
call   1040 <sqrt@plt>
jmp    11e0 <dct+0xc0>
nopw   0x0(%rax,%rax,1)
movsd  0x8(%rsp),%xmm0
ucomisd 0xdaa(%rip),%xmm0
movsd  0x28(%rsp),%xmm1
jae    1285 <dct+0x165>
movsd  0x8(%rsp),%xmm0
call   1040 <sqrt@plt>
movapd %xmm0,%xmm1
movsd  0xd83(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    %r15,%rax
jmp    1216 <dct+0xf6>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @dct(double* %0, double* %1, i32 %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 0, i32* %9
br label %11
11: ; preds = %73, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %8
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %76
15: ; preds = %11
store i32 0, i32* %10
br label %16
16: ; preds = %69, %15
%17 = load i32, i32* %10
%18 = load i32, i32* %7
%19 = icmp ult i32 %17, %18
br i1 %19, label %20, label %72
20: ; preds = %16
%21 = load i32, i32* %9
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %39
23: ; preds = %20
%24 = load i32, i32* %7
%25 = uitofp i32 %24 to double
%26 = call double @sqrt(double %25)
%27 = fdiv double 1.000000e+00, %26
%28 = load double*, double** %6
%29 = load i32, i32* %10
%30 = zext i32 %29 to i64
%31 = getelementptr inbounds double, double* %28, i64 %30
%32 = load double, double* %31
%33 = load double*, double** %5
%34 = load i32, i32* %9
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = load double, double* %36
%38 = call double @llvm.fmuladd.f64(double %27, double %32, double %37)
store double %38, double* %36
br label %69
39: ; preds = %20
%40 = load i32, i32* %7
%41 = uitofp i32 %40 to double
%42 = fdiv double 2.000000e+00, %41
%43 = call double @sqrt(double %42)
%44 = load i32, i32* %9
%45 = uitofp i32 %44 to double
%46 = fmul double %45, 0x400921FB54442D18
%47 = load i32, i32* %7
%48 = uitofp i32 %47 to double
%49 = fmul double 2.000000e+00, %48
%50 = fdiv double %46, %49
%51 = load i32, i32* %10
%52 = uitofp i32 %51 to double
%53 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %52, double 1.000000e+00)
%54 = fmul double %50, %53
%55 = fptoui double %54 to i32
%56 = call double @cos(i32 %55)
%57 = fmul double %43, %56
%58 = load double*, double** %6
%59 = load i32, i32* %10
%60 = zext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
%62 = load double, double* %61
%63 = load double*, double** %5
%64 = load i32, i32* %9
%65 = zext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
%67 = load double, double* %66
%68 = call double @llvm.fmuladd.f64(double %57, double %62, double %67)
store double %68, double* %66
br label %69
69: ; preds = %39, %23
%70 = load i32, i32* %10
%71 = add i32 %70, 1
store i32 %71, i32* %10
br label %16
72: ; preds = %16
br label %73
73: ; preds = %72
%74 = load i32, i32* %9
%75 = add i32 %74, 1
store i32 %75, i32* %9
br label %11
76: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @dct(double* nocapture %0, double* nocapture %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
br i1 %5, label %22, label %6
6: ; preds = %4
%7 = icmp eq i32 %2, 0
%8 = uitofp i32 %2 to double
%9 = fdiv double 2.000000e+00, %8
%10 = fmul double %8, 2.000000e+00
%11 = zext i32 %3 to i64
%12 = zext i32 %2 to i64
br label %13
13: ; preds = %6, %23
%14 = phi i64 [ 0, %6 ], [ %24, %23 ]
br i1 %7, label %23, label %15
15: ; preds = %13
%16 = icmp eq i64 %14, 0
%17 = trunc i64 %14 to i32
%18 = uitofp i32 %17 to double
%19 = fmul double %18, 0x400921FB54442D18
%20 = fdiv double %19, %10
%21 = getelementptr inbounds double, double* %0, i64 %14
br label %26
22: ; preds = %23, %4
ret void
23: ; preds = %40, %13
%24 = add nuw nsw i64 %14, 1
%25 = icmp eq i64 %24, %11
br i1 %25, label %22, label %13
26: ; preds = %15, %40
%27 = phi i64 [ 0, %15 ], [ %47, %40 ]
br i1 %16, label %28, label %31
28: ; preds = %26
%29 = tail call double @sqrt(double %8)
%30 = fdiv double 1.000000e+00, %29
br label %40
31: ; preds = %26
%32 = tail call double @sqrt(double %9)
%33 = trunc i64 %27 to i32
%34 = uitofp i32 %33 to double
%35 = tail call double @llvm.fmuladd.f64(double %34, double 2.000000e+00, double 1.000000e+00)
%36 = fmul double %20, %35
%37 = fptoui double %36 to i32
%38 = tail call double @cos(i32 %37)
%39 = fmul double %32, %38
br label %40
40: ; preds = %31, %28
%41 = phi double* [ %21, %31 ], [ %0, %28 ]
%42 = phi double [ %39, %31 ], [ %30, %28 ]
%43 = getelementptr inbounds double, double* %1, i64 %27
%44 = load double, double* %43
%45 = load double, double* %41
%46 = tail call double @llvm.fmuladd.f64(double %42, double %44, double %45)
store double %46, double* %41
%47 = add nuw nsw i64 %27, 1
%48 = icmp eq i64 %47, %12
br i1 %48, label %23, label %26
}