#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*/ crstrns(double *, double *);
int /*<<< orphan*/ mv_mul(double *, double *, double *);
void cal_p(double **p, double **x, double *g, const int i) {
  double t[4], s[2];
  int j;
  for (j = 0; j < i; j++) {
    crstrns(t, x[i - j]);
    mv_mul(s, t, g);
    p[j][0] += s[0];
    p[j][1] += s[1];
  }
  p[i][0] = g[0];
  p[i][1] = g[1];
  return;
}


x86 assembly (clang, -O0):
<cal_p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11b7 <cal_p+0x97>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    -0x54(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <crstrns@plt>
lea    -0x50(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <mv_mul@plt>
movsd  -0x50(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  -0x48(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x54(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
addsd  0x8(%rax),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    113e <cal_p+0x1e>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  %xmm0,(%rax)
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsd  %xmm0,0x8(%rax)
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cal_p>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r15
test   %ecx,%ecx
jle    11a0 <cal_p+0x80>
mov    %rsi,%r12
mov    %ecx,%ebp
lea    0x20(%rsp),%rbx
lea    0x10(%rsp),%r13
mov    %rdi,0x8(%rsp)
mov    %rdi,%r14
mov    %rbp,(%rsp)
mov    (%r12,%rbp,8),%rsi
mov    %rbx,%rdi
call   1030 <crstrns@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1040 <mv_mul@plt>
movsd  0x10(%rsp),%xmm0
mov    (%r14),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  0x18(%rsp),%xmm0
addsd  0x8(%rax),%xmm0
movsd  %xmm0,0x8(%rax)
add    $0x8,%r14
add    $0xffffffffffffffff,%rbp
jne    1150 <cal_p+0x30>
mov    0x8(%rsp),%rdi
mov    (%rsp),%rax
jmp    11a3 <cal_p+0x83>
movslq %ecx,%rax
movsd  (%r15),%xmm0
mov    (%rdi,%rax,8),%rax
movsd  %xmm0,(%rax)
movsd  0x8(%r15),%xmm0
movsd  %xmm0,0x8(%rax)
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @cal_p(double** %0, double** %1, double* %2, i32 %3) {
%5 = alloca double**
%6 = alloca double**
%7 = alloca double*
%8 = alloca i32
%9 = alloca [4 x double]
%10 = alloca [2 x double]
%11 = alloca i32
store double** %0, double*** %5
store double** %1, double*** %6
store double* %2, double** %7
store i32 %3, i32* %8
store i32 0, i32* %11
br label %12
12: ; preds = %50, %4
%13 = load i32, i32* %11
%14 = load i32, i32* %8
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %53
16: ; preds = %12
%17 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%18 = load double**, double*** %6
%19 = load i32, i32* %8
%20 = load i32, i32* %11
%21 = sub nsw i32 %19, %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double*, double** %18, i64 %22
%24 = load double*, double** %23
%25 = call i32 @crstrns(double* %17, double* %24)
%26 = getelementptr inbounds [2 x double], [2 x double]* %10, i64 0, i64 0
%27 = getelementptr inbounds [4 x double], [4 x double]* %9, i64 0, i64 0
%28 = load double*, double** %7
%29 = call i32 @mv_mul(double* %26, double* %27, double* %28)
%30 = getelementptr inbounds [2 x double], [2 x double]* %10, i64 0, i64 0
%31 = load double, double* %30
%32 = load double**, double*** %5
%33 = load i32, i32* %11
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double*, double** %32, i64 %34
%36 = load double*, double** %35
%37 = getelementptr inbounds double, double* %36, i64 0
%38 = load double, double* %37
%39 = fadd double %38, %31
store double %39, double* %37
%40 = getelementptr inbounds [2 x double], [2 x double]* %10, i64 0, i64 1
%41 = load double, double* %40
%42 = load double**, double*** %5
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double*, double** %42, i64 %44
%46 = load double*, double** %45
%47 = getelementptr inbounds double, double* %46, i64 1
%48 = load double, double* %47
%49 = fadd double %48, %41
store double %49, double* %47
br label %50
50: ; preds = %16
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %12
53: ; preds = %12
%54 = load double*, double** %7
%55 = getelementptr inbounds double, double* %54, i64 0
%56 = load double, double* %55
%57 = load double**, double*** %5
%58 = load i32, i32* %8
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double*, double** %57, i64 %59
%61 = load double*, double** %60
%62 = getelementptr inbounds double, double* %61, i64 0
store double %56, double* %62
%63 = load double*, double** %7
%64 = getelementptr inbounds double, double* %63, i64 1
%65 = load double, double* %64
%66 = load double**, double*** %5
%67 = load i32, i32* %8
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double*, double** %66, i64 %68
%70 = load double*, double** %69
%71 = getelementptr inbounds double, double* %70, i64 1
store double %65, double* %71
ret void
}

LLVM IR (-O2):
define void @cal_p(double** nocapture %0, double** nocapture %1, double* %2, i32 %3) {
%5 = alloca [4 x double]
%6 = alloca [2 x double]
%7 = bitcast [4 x double]* %5 to i8*
%8 = bitcast [2 x double]* %6 to i8*
%9 = icmp sgt i32 %3, 0
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = sext i32 %3 to i64
br label %36
12: ; preds = %4
%13 = getelementptr inbounds [4 x double], [4 x double]* %5, i64 0, i64 0
%14 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 0
%15 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 1
%16 = zext i32 %3 to i64
%17 = zext i32 %3 to i64
br label %18
18: ; preds = %12, %18
%19 = phi i64 [ 0, %12 ], [ %34, %18 ]
%20 = sub nsw i64 %16, %19
%21 = getelementptr inbounds double*, double** %1, i64 %20
%22 = load double*, double** %21
%23 = call i32 @crstrns(double* %13, double* %22)
%24 = call i32 @mv_mul(double* %14, double* %13, double* %2)
%25 = load double, double* %14
%26 = getelementptr inbounds double*, double** %0, i64 %19
%27 = load double*, double** %26
%28 = load double, double* %27
%29 = fadd double %25, %28
store double %29, double* %27
%30 = load double, double* %15
%31 = getelementptr inbounds double, double* %27, i64 1
%32 = load double, double* %31
%33 = fadd double %30, %32
store double %33, double* %31
%34 = add nuw nsw i64 %19, 1
%35 = icmp eq i64 %34, %17
br i1 %35, label %36, label %18
36: ; preds = %18, %10
%37 = phi i64 [ %11, %10 ], [ %16, %18 ]
%38 = load double, double* %2
%39 = getelementptr inbounds double*, double** %0, i64 %37
%40 = load double*, double** %39
store double %38, double* %40
%41 = getelementptr inbounds double, double* %2, i64 1
%42 = load double, double* %41
%43 = getelementptr inbounds double, double* %40, i64 1
store double %42, double* %43
ret void
}