#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;
double cos(int);
double sum1(int, int const);
double calc(const int n, const int m) {
  double res = 0;
  for (int i = 1; i <= n; i++)
    res += cos(M_PI / i) * sum1(i, m);
  return res;
}


x86 assembly (clang, -O0):
<calc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jg     1195 <calc+0x75>
mov    0x2e98(%rip),%rax
mov    (%rax),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%edi
call   1040 <cos@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <sum1@plt>
movaps %xmm0,%xmm2
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113d <calc+0x1d>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
jle    11a3 <calc+0x83>
mov    %esi,%r14d
mov    %edi,%ebx
neg    %ebx
xorpd  %xmm0,%xmm0
mov    $0x1,%ebp
mov    0x2ea3(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm0,0x8(%rsp)
mov    (%r15),%eax
cltd
idiv   %ebp
mov    %eax,%edi
call   1040 <cos@plt>
movsd  %xmm0,0x10(%rsp)
mov    %ebp,%edi
mov    %r14d,%esi
call   1030 <sum1@plt>
mulsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
lea    (%rbx,%rbp,1),%eax
add    $0x1,%eax
mov    %ebp,%ecx
add    $0x1,%ecx
mov    %ecx,%ebp
cmp    $0x1,%eax
jne    1150 <calc+0x30>
jmp    11a7 <calc+0x87>
xorpd  %xmm0,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global i32 0
define double @calc(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %5
store i32 1, i32* %6
br label %7
7: ; preds = %21, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %3
%10 = icmp sle i32 %8, %9
br i1 %10, label %11, label %24
11: ; preds = %7
%12 = load i32, i32* @M_PI
%13 = load i32, i32* %6
%14 = sdiv i32 %12, %13
%15 = call double @cos(i32 %14)
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = call double @sum1(i32 %16, i32 %17)
%19 = load double, double* %5
%20 = call double @llvm.fmuladd.f64(double %15, double %18, double %19)
store double %20, double* %5
br label %21
21: ; preds = %11
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %7
24: ; preds = %7
%25 = load double, double* %5
ret double %25
}

LLVM IR (-O2):
@M_PI = global i32 0
define double @calc(i32 %0, i32 %1) {
%3 = icmp slt i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %6, %2
%5 = phi double [ 0.000000e+00, %2 ], [ %13, %6 ]
ret double %5
6: ; preds = %2, %6
%7 = phi i32 [ %14, %6 ], [ 1, %2 ]
%8 = phi double [ %13, %6 ], [ 0.000000e+00, %2 ]
%9 = load i32, i32* @M_PI
%10 = sdiv i32 %9, %7
%11 = tail call double @cos(i32 %10)
%12 = tail call double @sum1(i32 %7, i32 %1)
%13 = tail call double @llvm.fmuladd.f64(double %11, double %12, double %8)
%14 = add nuw i32 %7, 1
%15 = icmp eq i32 %7, %0
br i1 %15, label %4, label %6
}