#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 cosh(double);
scalar_t__ malloc(int);
double sqrt(double);
double *analyticalSolution(double B, int N) {
  double *x = (double *)malloc(N * sizeof(double));
  double argument = sqrt(B);
  for (int i = 0; i < N; i++) {
    x[i] = cosh(argument * (double)(1 - ((double)(i) / (double)(N - 1)))) /
           cosh(argument);
  }
  return x;
}


x86 assembly (clang, -O0):
<analyticalSolution>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d8 <analyticalSolution+0xa8>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm2
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm2
movsd  0xe6b(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
call   1030 <cosh@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <cosh@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
divsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1169 <analyticalSolution+0x39>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<analyticalSolution>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%r14d
movsd  %xmm0,0x8(%rsp)
lea    0x0(,%r14,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r15
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
movapd %xmm1,%xmm0
jb     1174 <analyticalSolution+0x44>
sqrtsd %xmm0,%xmm2
test   %r14d,%r14d
jg     1182 <analyticalSolution+0x52>
jmp    11f2 <analyticalSolution+0xc2>
call   1050 <sqrt@plt>
movapd %xmm0,%xmm2
test   %r14d,%r14d
jle    11f2 <analyticalSolution+0xc2>
lea    -0x1(%r14),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x10(%rsp)
mov    %r14d,%r14d
xor    %ebx,%ebx
movsd  %xmm2,0x8(%rsp)
xchg   %ax,%ax
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
divsd  0x10(%rsp),%xmm1
movsd  0xe4b(%rip),%xmm0
subsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
call   1030 <cosh@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <cosh@plt>
movsd  0x8(%rsp),%xmm2
movsd  0x18(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11a0 <analyticalSolution+0x70>
mov    %r15,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double* @analyticalSolution(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca double*
%6 = alloca double
%7 = alloca i32
store double %0, double* %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 8
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to double*
store double* %13, double** %5
%14 = load double, double* %3
%15 = call double @sqrt(double %14)
store double %15, double* %6
store i32 0, i32* %7
br label %16
16: ; preds = %38, %2
%17 = load i32, i32* %7
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %41
20: ; preds = %16
%21 = load double, double* %6
%22 = load i32, i32* %7
%23 = sitofp i32 %22 to double
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, 1
%26 = sitofp i32 %25 to double
%27 = fdiv double %23, %26
%28 = fsub double 1.000000e+00, %27
%29 = fmul double %21, %28
%30 = call double @cosh(double %29)
%31 = load double, double* %6
%32 = call double @cosh(double %31)
%33 = fdiv double %30, %32
%34 = load double*, double** %5
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
store double %33, double* %37
br label %38
38: ; preds = %20
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %16
41: ; preds = %16
%42 = load double*, double** %5
ret double* %42
}

LLVM IR (-O2):
define double* @analyticalSolution(double %0, i32 %1) {
%3 = shl i32 %1, 3
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to double*
%6 = tail call double @sqrt(double %0)
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = add nsw i32 %1, -1
%10 = sitofp i32 %9 to double
%11 = zext i32 %1 to i64
br label %13
12: ; preds = %13, %2
ret double* %5
13: ; preds = %8, %13
%14 = phi i64 [ 0, %8 ], [ %24, %13 ]
%15 = trunc i64 %14 to i32
%16 = sitofp i32 %15 to double
%17 = fdiv double %16, %10
%18 = fsub double 1.000000e+00, %17
%19 = fmul double %6, %18
%20 = tail call double @cosh(double %19)
%21 = tail call double @cosh(double %6)
%22 = fdiv double %20, %21
%23 = getelementptr inbounds double, double* %5, i64 %14
store double %22, double* %23
%24 = add nuw nsw i64 %14, 1
%25 = icmp eq i64 %24, %11
br i1 %25, label %12, label %13
}