#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 /*<<< orphan*/ printf(char *, int, double, double, double);
double grib_invtrans_trig(int L, double *TR, double *TI, double *c, double *s) {
  double ret = 0;
  int m = 0;
  for (m = 1; m <= L; m++) {
    ret += TR[m] * c[m];
    printf("++ %d ++ %.20e %g %g\n", m, ret, TR[m], c[m]);
    ret -= TI[m] * s[m];
    printf("+- %d ++ %.20e %g %g\n", m, ret, TI[m], s[m]);
  }
  ret = 2 * ret + TR[0];
  return ret;
}


x86 assembly (clang, -O0):
<grib_invtrans_trig>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1226 <grib_invtrans_trig+0x116>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%esi
movsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x30(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x34(%rbp),%esi
movsd  -0x30(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
lea    0xe03(%rip),%rdi
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1141 <grib_invtrans_trig+0x31>
movsd  -0x30(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grib_invtrans_trig>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
test   %edi,%edi
jle    11b0 <grib_invtrans_trig+0xa0>
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r13
mov    %edi,%ebx
add    $0x1,%ebx
xorpd  %xmm3,%xmm3
mov    $0x1,%ebp
nopl   (%rax)
movsd  (%r14,%rbp,8),%xmm1
movsd  (%r12,%rbp,8),%xmm2
movapd %xmm1,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
movsd  %xmm0,(%rsp)
lea    0xe9c(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
movsd  0x0(%r13,%rbp,8),%xmm1
movsd  (%r15,%rbp,8),%xmm2
movapd %xmm1,%xmm3
mulsd  %xmm2,%xmm3
movsd  (%rsp),%xmm0
subsd  %xmm3,%xmm0
movsd  %xmm0,(%rsp)
lea    0xe81(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
movsd  (%rsp),%xmm0
add    $0x1,%rbp
movapd %xmm0,%xmm3
cmp    %rbp,%rbx
jne    1140 <grib_invtrans_trig+0x30>
jmp    11b4 <grib_invtrans_trig+0xa4>
xorpd  %xmm0,%xmm0
addsd  %xmm0,%xmm0
addsd  (%r14),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"++ %d ++ %.20e %g %g\0A\00"
@.str.1 = [22 x i8] c"+- %d ++ %.20e %g %g\0A\00"
define double @grib_invtrans_trig(i32 %0, double* %1, double* %2, double* %3, double* %4) {
%6 = alloca i32
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca double*
%11 = alloca double
%12 = alloca i32
store i32 %0, i32* %6
store double* %1, double** %7
store double* %2, double** %8
store double* %3, double** %9
store double* %4, double** %10
store double 0.000000e+00, double* %11
store i32 0, i32* %12
store i32 1, i32* %12
br label %13
13: ; preds = %69, %5
%14 = load i32, i32* %12
%15 = load i32, i32* %6
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %72
17: ; preds = %13
%18 = load double*, double** %7
%19 = load i32, i32* %12
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
%22 = load double, double* %21
%23 = load double*, double** %9
%24 = load i32, i32* %12
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load double, double* %11
%29 = call double @llvm.fmuladd.f64(double %22, double %27, double %28)
store double %29, double* %11
%30 = load i32, i32* %12
%31 = load double, double* %11
%32 = load double*, double** %7
%33 = load i32, i32* %12
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double, double* %32, i64 %34
%36 = load double, double* %35
%37 = load double*, double** %9
%38 = load i32, i32* %12
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
%42 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %30, double %31, double %36, double %41)
%43 = load double*, double** %8
%44 = load i32, i32* %12
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
%47 = load double, double* %46
%48 = load double*, double** %10
%49 = load i32, i32* %12
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
%52 = load double, double* %51
%53 = load double, double* %11
%54 = fneg double %47
%55 = call double @llvm.fmuladd.f64(double %54, double %52, double %53)
store double %55, double* %11
%56 = load i32, i32* %12
%57 = load double, double* %11
%58 = load double*, double** %8
%59 = load i32, i32* %12
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
%62 = load double, double* %61
%63 = load double*, double** %10
%64 = load i32, i32* %12
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds double, double* %63, i64 %65
%67 = load double, double* %66
%68 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %56, double %57, double %62, double %67)
br label %69
69: ; preds = %17
%70 = load i32, i32* %12
%71 = add nsw i32 %70, 1
store i32 %71, i32* %12
br label %13
72: ; preds = %13
%73 = load double, double* %11
%74 = load double*, double** %7
%75 = getelementptr inbounds double, double* %74, i64 0
%76 = load double, double* %75
%77 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %73, double %76)
store double %77, double* %11
%78 = load double, double* %11
ret double %78
}

LLVM IR (-O2):
@.str = [22 x i8] c"++ %d ++ %.20e %g %g\0A\00"
@.str.1 = [22 x i8] c"+- %d ++ %.20e %g %g\0A\00"
define double @grib_invtrans_trig(i32 %0, double* nocapture %1, double* nocapture %2, double* nocapture %3, double* nocapture %4) {
%6 = icmp slt i32 %0, 1
br i1 %6, label %29, label %7
7: ; preds = %5
%8 = add nuw i32 %0, 1
%9 = zext i32 %8 to i64
br label %10
10: ; preds = %7, %10
%11 = phi i64 [ 1, %7 ], [ %27, %10 ]
%12 = phi double [ 0.000000e+00, %7 ], [ %25, %10 ]
%13 = getelementptr inbounds double, double* %1, i64 %11
%14 = load double, double* %13
%15 = getelementptr inbounds double, double* %3, i64 %11
%16 = load double, double* %15
%17 = tail call double @llvm.fmuladd.f64(double %14, double %16, double %12)
%18 = trunc i64 %11 to i32
%19 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %18, double %17, double %14, double %16)
%20 = getelementptr inbounds double, double* %2, i64 %11
%21 = load double, double* %20
%22 = getelementptr inbounds double, double* %4, i64 %11
%23 = load double, double* %22
%24 = fneg double %21
%25 = tail call double @llvm.fmuladd.f64(double %24, double %23, double %17)
%26 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %18, double %25, double %21, double %23)
%27 = add nuw nsw i64 %11, 1
%28 = icmp eq i64 %27, %9
br i1 %28, label %29, label %10
29: ; preds = %10, %5
%30 = phi double [ 0.000000e+00, %5 ], [ %25, %10 ]
%31 = load double, double* %1
%32 = tail call double @llvm.fmuladd.f64(double %30, double 2.000000e+00, double %31)
ret double %32
}