#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 */
float M_PI;
float cos(float);
float sin(float);
float sqrt(float);
int discreteHartley(int Width, float *sample, float *outputSample) {
  int n = 0;
  int N = Width;
  int k = 0;
  int result = 0;
  if (N > 0 && sample && outputSample) {
    for (k = 0; N - 1 >= k; k++) {
      float outputValue = 0.0;
      for (n = 0; N - 1 >= n; n++) {
        float coeff = ((2.0f * M_PI) / (float)N) * (float)k * (float)n;
        float im = (sin(coeff) + cos(coeff));
        outputValue += sample[n] * im;
      }
      outputSample[k] = outputValue * (1.0f / sqrt((float)N));
    }
    result = 0;
  } else {
    result = -1;
  }
  return result;
}


x86 assembly (clang, -O0):
<discreteHartley>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    1294 <discreteHartley+0x164>
cmpq   $0x0,-0x10(%rbp)
je     1294 <discreteHartley+0x164>
cmpq   $0x0,-0x18(%rbp)
je     1294 <discreteHartley+0x164>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
cmp    -0x24(%rbp),%eax
jl     1288 <discreteHartley+0x158>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x2c(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jl     1241 <discreteHartley+0x111>
movss  0xe4a(%rip),%xmm0
mov    0x2e27(%rip),%rax
mulss  (%rax),%xmm0
cvtsi2ssl -0x20(%rbp),%xmm1
divss  %xmm1,%xmm0
cvtsi2ssl -0x24(%rbp),%xmm1
mulss  %xmm1,%xmm0
cvtsi2ssl -0x1c(%rbp),%xmm1
mulss  %xmm1,%xmm0
movss  %xmm0,-0x30(%rbp)
movss  -0x30(%rbp),%xmm0
call   1030 <sin@plt>
movss  %xmm0,-0x38(%rbp)
movss  -0x30(%rbp),%xmm0
call   1040 <cos@plt>
movaps %xmm0,%xmm1
movss  -0x38(%rbp),%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  -0x34(%rbp),%xmm2
movss  -0x2c(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a3 <discreteHartley+0x73>
movss  -0x2c(%rbp),%xmm0
movss  %xmm0,-0x3c(%rbp)
cvtsi2ssl -0x20(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm2
movss  -0x3c(%rbp),%xmm0
movss  0xd9b(%rip),%xmm1
divss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1185 <discreteHartley+0x55>
movl   $0x0,-0x28(%rbp)
jmp    129b <discreteHartley+0x16b>
movl   $0xffffffff,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<discreteHartley>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xffffffff,%eax
test   %edi,%edi
jle    1266 <discreteHartley+0x136>
mov    %rsi,%r15
test   %rsi,%rsi
je     1266 <discreteHartley+0x136>
mov    %rdx,%r14
test   %rdx,%rdx
je     1266 <discreteHartley+0x136>
cvtsi2ss %edi,%xmm2
mov    %edi,%ebx
xor    %r12d,%r12d
mov    0x2e75(%rip),%r13
sqrtss %xmm2,%xmm0
movss  %xmm0,0x8(%rsp)
movss  %xmm2,0x4(%rsp)
jmp    11b3 <discreteHartley+0x83>
cs nopw 0x0(%rax,%rax,1)
nop
movss  0xe68(%rip),%xmm1
divss  %xmm0,%xmm1
mulss  %xmm1,%xmm3
movss  %xmm3,(%r14,%r12,4)
add    $0x1,%r12
cmp    %rbx,%r12
je     1264 <discreteHartley+0x134>
xorps  %xmm0,%xmm0
cvtsi2ss %r12d,%xmm0
movss  %xmm0,0xc(%rsp)
xor    %ebp,%ebp
xorps  %xmm3,%xmm3
cs nopw 0x0(%rax,%rax,1)
movss  %xmm3,(%rsp)
movss  0x0(%r13),%xmm1
addss  %xmm1,%xmm1
divss  %xmm2,%xmm1
mulss  0xc(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
mulss  %xmm1,%xmm0
movss  %xmm0,0x10(%rsp)
call   1030 <sin@plt>
movss  %xmm0,0x14(%rsp)
movss  0x10(%rsp),%xmm0
call   1040 <cos@plt>
movss  (%rsp),%xmm3
movss  0x4(%rsp),%xmm2
addss  0x14(%rsp),%xmm0
mulss  (%r15,%rbp,4),%xmm0
addss  %xmm0,%xmm3
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11d0 <discreteHartley+0xa0>
ucomiss 0xdc9(%rip),%xmm2
movss  0x8(%rsp),%xmm0
jae    1190 <discreteHartley+0x60>
movaps %xmm2,%xmm0
movss  %xmm3,(%rsp)
call   1050 <sqrt@plt>
movss  (%rsp),%xmm3
movss  0x4(%rsp),%xmm2
jmp    1190 <discreteHartley+0x60>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@M_PI = global float 0.000000e+00
define i32 @discreteHartley(i32 %0, float* %1, float* writeonly %2) {
%4 = icmp sgt i32 %0, 0
%5 = icmp ne float* %1, null
%6 = and i1 %4, %5
%7 = icmp ne float* %2, null
%8 = and i1 %6, %7
br i1 %8, label %9, label %41
9: ; preds = %3
%10 = sitofp i32 %0 to float
%11 = zext i32 %0 to i64
br label %12
12: ; preds = %34, %9
%13 = phi i64 [ 0, %9 ], [ %39, %34 ]
%14 = trunc i64 %13 to i32
%15 = sitofp i32 %14 to float
br label %16
16: ; preds = %12, %16
%17 = phi i64 [ 0, %12 ], [ %32, %16 ]
%18 = phi float [ 0.000000e+00, %12 ], [ %31, %16 ]
%19 = load float, float* @M_PI
%20 = fmul float %19, 2.000000e+00
%21 = fdiv float %20, %10
%22 = fmul float %21, %15
%23 = trunc i64 %17 to i32
%24 = sitofp i32 %23 to float
%25 = fmul float %22, %24
%26 = tail call float @sin(float %25)
%27 = tail call float @cos(float %25)
%28 = fadd float %26, %27
%29 = getelementptr inbounds float, float* %1, i64 %17
%30 = load float, float* %29
%31 = tail call float @llvm.fmuladd.f32(float %30, float %28, float %18)
%32 = add nuw nsw i64 %17, 1
%33 = icmp eq i64 %32, %11
br i1 %33, label %34, label %16
34: ; preds = %16
%35 = tail call float @sqrt(float %10)
%36 = fdiv float 1.000000e+00, %35
%37 = fmul float %31, %36
%38 = getelementptr inbounds float, float* %2, i64 %13
store float %37, float* %38
%39 = add nuw nsw i64 %13, 1
%40 = icmp eq i64 %39, %11
br i1 %40, label %41, label %12
41: ; preds = %34, %3
%42 = phi i32 [ -1, %3 ], [ 0, %34 ]
ret i32 %42
}