#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 *malloc(size_t);
double *deriveEq(double *equation, size_t degree) {
  double *derivative = malloc(degree * sizeof(double));
  for (int i = 0; i < degree; i++)
    derivative[i] = equation[i + 1] * (i + 1);
  return derivative;
}


x86 assembly (clang, -O0):
<deriveEq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
shl    $0x3,%rdi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1181 <deriveEq+0x71>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1138 <deriveEq+0x28>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deriveEq>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x0(,%rsi,8),%rdi
call   1030 <malloc@plt>
test   %r14,%r14
je     11ee <deriveEq+0xde>
cmp    $0x4,%r14
jae    113d <deriveEq+0x2d>
xor    %ecx,%ecx
jmp    11d0 <deriveEq+0xc0>
mov    %r14,%rcx
and    $0xfffffffffffffffc,%rcx
xor    %edx,%edx
movdqa 0xeb1(%rip),%xmm8
movdqa 0xeb9(%rip),%xmm1
movdqa 0xec1(%rip),%xmm2
nop
movq   %rdx,%xmm3
pshufd $0x44,%xmm3,%xmm4
movdqa %xmm4,%xmm5
por    %xmm8,%xmm5
por    %xmm1,%xmm3
paddq  %xmm2,%xmm4
movq   %xmm5,%rsi
movupd (%rbx,%rsi,8),%xmm6
movupd 0x10(%rbx,%rsi,8),%xmm7
pshufd $0xfa,%xmm5,%xmm5
movd   %esi,%xmm0
movss  %xmm0,%xmm5
pshufd $0xee,%xmm4,%xmm0
punpckldq %xmm0,%xmm3
cvtdq2pd %xmm5,%xmm0
mulpd  %xmm6,%xmm0
cvtdq2pd %xmm3,%xmm3
mulpd  %xmm7,%xmm3
movupd %xmm0,(%rax,%rdx,8)
movupd %xmm3,0x10(%rax,%rdx,8)
add    $0x4,%rdx
cmp    %rdx,%rcx
jne    1160 <deriveEq+0x50>
cmp    %r14,%rcx
je     11ee <deriveEq+0xde>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rcx),%rdx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
mulsd  0x8(%rbx,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    %rdx,%rcx
cmp    %rdx,%r14
jne    11d0 <deriveEq+0xc0>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double* @deriveEq(double* %0, i64 %1) {
%3 = alloca double*
%4 = alloca i64
%5 = alloca double*
%6 = alloca i32
store double* %0, double** %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
%8 = mul i64 %7, 8
%9 = call double* @malloc(i64 %8)
store double* %9, double** %5
store i32 0, i32* %6
br label %10
10: ; preds = %30, %2
%11 = load i32, i32* %6
%12 = sext i32 %11 to i64
%13 = load i64, i64* %4
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %33
15: ; preds = %10
%16 = load double*, double** %3
%17 = load i32, i32* %6
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds double, double* %16, i64 %19
%21 = load double, double* %20
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
%24 = sitofp i32 %23 to double
%25 = fmul double %21, %24
%26 = load double*, double** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
store double %25, double* %29
br label %30
30: ; preds = %15
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
br label %10
33: ; preds = %10
%34 = load double*, double** %5
ret double* %34
}

LLVM IR (-O2):
define noalias double* @deriveEq(double* nocapture %0, i64 %1) {
%3 = shl i64 %1, 3
%4 = tail call double* @malloc(i64 %3)
%5 = icmp eq i64 %1, 0
br i1 %5, label %41, label %6
6: ; preds = %2
%7 = icmp ult i64 %1, 4
br i1 %7, label %39, label %8
8: ; preds = %6
%9 = and i64 %1, -4
br label %10
10: ; preds = %10, %8
%11 = phi i64 [ 0, %8 ], [ %35, %10 ]
%12 = insertelement <2 x i64> poison, i64 %11, i64 0
%13 = shufflevector <2 x i64> %12, <2 x i64> poison, <2 x i32> zeroinitializer
%14 = or <2 x i64> %13, <i64 1, i64 2>
%15 = or <2 x i64> %13, <i64 3, i64 poison>
%16 = add <2 x i64> %13, <i64 poison, i64 4>
%17 = shufflevector <2 x i64> %15, <2 x i64> %16, <2 x i32> <i32 0, i32 3>
%18 = extractelement <2 x i64> %14, i64 0
%19 = getelementptr inbounds double, double* %0, i64 %18
%20 = bitcast double* %19 to <2 x double>*
%21 = load <2 x double>, <2 x double>* %20
%22 = getelementptr inbounds double, double* %19, i64 2
%23 = bitcast double* %22 to <2 x double>*
%24 = load <2 x double>, <2 x double>* %23
%25 = trunc <2 x i64> %14 to <2 x i32>
%26 = trunc <2 x i64> %17 to <2 x i32>
%27 = sitofp <2 x i32> %25 to <2 x double>
%28 = sitofp <2 x i32> %26 to <2 x double>
%29 = fmul <2 x double> %21, %27
%30 = fmul <2 x double> %24, %28
%31 = getelementptr inbounds double, double* %4, i64 %11
%32 = bitcast double* %31 to <2 x double>*
store <2 x double> %29, <2 x double>* %32
%33 = getelementptr inbounds double, double* %31, i64 2
%34 = bitcast double* %33 to <2 x double>*
store <2 x double> %30, <2 x double>* %34
%35 = add nuw i64 %11, 4
%36 = icmp eq i64 %35, %9
br i1 %36, label %37, label %10
37: ; preds = %10
%38 = icmp eq i64 %9, %1
br i1 %38, label %41, label %39
39: ; preds = %6, %37
%40 = phi i64 [ 0, %6 ], [ %9, %37 ]
br label %42
41: ; preds = %42, %37, %2
ret double* %4
42: ; preds = %39, %42
%43 = phi i64 [ %44, %42 ], [ %40, %39 ]
%44 = add nuw nsw i64 %43, 1
%45 = getelementptr inbounds double, double* %0, i64 %44
%46 = load double, double* %45
%47 = trunc i64 %44 to i32
%48 = sitofp i32 %47 to double
%49 = fmul double %46, %48
%50 = getelementptr inbounds double, double* %4, i64 %43
store double %49, double* %50
%51 = icmp eq i64 %44, %1
br i1 %51, label %41, label %42
}