#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 coefficient(double *, int, int);
void multiply(double P[], int degreeP, double Q[], int degreeQ, double R[]) {
  int degreeR = degreeP + degreeQ;
  int term;
  for (term = 0; term <= degreeR; term++) {
    R[term] = 0;
  }
  int i;
  for (term = 0; term <= degreeR; term++) {
    for (i = 0; i <= term; i++) {
      R[term] += coefficient(P, degreeP, i) * coefficient(Q, degreeQ, term - i);
    }
  }
}


x86 assembly (clang, -O0):
<multiply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0xc(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jg     1164 <multiply+0x54>
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    113a <multiply+0x2a>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jg     11f3 <multiply+0xe3>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x30(%rbp),%eax
jg     11e0 <multiply+0xd0>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x34(%rbp),%edx
call   1030 <coefficient@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x30(%rbp),%edx
sub    -0x34(%rbp),%edx
call   1030 <coefficient@plt>
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    117e <multiply+0x6e>
jmp    11e5 <multiply+0xd5>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    116b <multiply+0x5b>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiply>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x10(%rsp)
mov    %ecx,(%rsp)
mov    %ecx,%eax
add    %esi,%eax
js     11da <multiply+0xba>
mov    %r8,%rbx
mov    %eax,%eax
lea    0x8(,%rax,8),%rdx
add    $0x1,%rax
mov    %rax,0x8(%rsp)
xor    %r15d,%r15d
mov    %rdi,0x18(%rsp)
mov    %r8,%rdi
mov    %esi,0x4(%rsp)
xor    %esi,%esi
call   1030 <memset@plt>
mov    (%rsp),%r12d
mov    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15d,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
mov    0x18(%rsp),%rdi
mov    0x4(%rsp),%esi
mov    %r14d,%edx
call   1040 <coefficient@plt>
movsd  %xmm0,0x20(%rsp)
mov    %r13,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
call   1040 <coefficient@plt>
mulsd  0x20(%rsp),%xmm0
addsd  (%rbx,%r15,8),%xmm0
movsd  %xmm0,(%rbx,%r15,8)
add    $0x1,%r14d
add    $0xffffffff,%ebp
jb     1190 <multiply+0x70>
add    $0x1,%r15
cmp    0x8(%rsp),%r15
jne    1180 <multiply+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @multiply(double* %0, i32 %1, double* %2, i32 %3, double* %4) {
%6 = alloca double*
%7 = alloca i32
%8 = alloca double*
%9 = alloca i32
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store double* %0, double** %6
store i32 %1, i32* %7
store double* %2, double** %8
store i32 %3, i32* %9
store double* %4, double** %10
%14 = load i32, i32* %7
%15 = load i32, i32* %9
%16 = add nsw i32 %14, %15
store i32 %16, i32* %11
store i32 0, i32* %12
br label %17
17: ; preds = %26, %5
%18 = load i32, i32* %12
%19 = load i32, i32* %11
%20 = icmp sle i32 %18, %19
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load double*, double** %10
%23 = load i32, i32* %12
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
store double 0.000000e+00, double* %25
br label %26
26: ; preds = %21
%27 = load i32, i32* %12
%28 = add nsw i32 %27, 1
store i32 %28, i32* %12
br label %17
29: ; preds = %17
store i32 0, i32* %12
br label %30
30: ; preds = %60, %29
%31 = load i32, i32* %12
%32 = load i32, i32* %11
%33 = icmp sle i32 %31, %32
br i1 %33, label %34, label %63
34: ; preds = %30
store i32 0, i32* %13
br label %35
35: ; preds = %56, %34
%36 = load i32, i32* %13
%37 = load i32, i32* %12
%38 = icmp sle i32 %36, %37
br i1 %38, label %39, label %59
39: ; preds = %35
%40 = load double*, double** %6
%41 = load i32, i32* %7
%42 = load i32, i32* %13
%43 = call double @coefficient(double* %40, i32 %41, i32 %42)
%44 = load double*, double** %8
%45 = load i32, i32* %9
%46 = load i32, i32* %12
%47 = load i32, i32* %13
%48 = sub nsw i32 %46, %47
%49 = call double @coefficient(double* %44, i32 %45, i32 %48)
%50 = load double*, double** %10
%51 = load i32, i32* %12
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds double, double* %50, i64 %52
%54 = load double, double* %53
%55 = call double @llvm.fmuladd.f64(double %43, double %49, double %54)
store double %55, double* %53
br label %56
56: ; preds = %39
%57 = load i32, i32* %13
%58 = add nsw i32 %57, 1
store i32 %58, i32* %13
br label %35
59: ; preds = %35
br label %60
60: ; preds = %59
%61 = load i32, i32* %12
%62 = add nsw i32 %61, 1
store i32 %62, i32* %12
br label %30
63: ; preds = %30
ret void
}

LLVM IR (-O2):
define void @multiply(double* %0, i32 %1, double* %2, i32 %3, double* nocapture %4) {
%6 = add i32 %3, %1
%7 = icmp slt i32 %6, 0
br i1 %7, label %33, label %8
8: ; preds = %5
%9 = bitcast double* %4 to i8*
%10 = add nuw i32 %6, 1
%11 = zext i32 %10 to i64
%12 = shl nuw nsw i64 %11, 3
%13 = add nuw i32 %6, 1
%14 = zext i32 %13 to i64
br label %15
15: ; preds = %8, %29
%16 = phi i64 [ 0, %8 ], [ %30, %29 ]
%17 = phi i32 [ 1, %8 ], [ %31, %29 ]
%18 = getelementptr inbounds double, double* %4, i64 %16
%19 = trunc i64 %16 to i32
br label %20
20: ; preds = %15, %20
%21 = phi i32 [ 0, %15 ], [ %27, %20 ]
%22 = tail call double @coefficient(double* %0, i32 %1, i32 %21)
%23 = sub nsw i32 %19, %21
%24 = tail call double @coefficient(double* %2, i32 %3, i32 %23)
%25 = load double, double* %18
%26 = tail call double @llvm.fmuladd.f64(double %22, double %24, double %25)
store double %26, double* %18
%27 = add nuw i32 %21, 1
%28 = icmp eq i32 %27, %17
br i1 %28, label %29, label %20
29: ; preds = %20
%30 = add nuw nsw i64 %16, 1
%31 = add nuw i32 %17, 1
%32 = icmp eq i64 %30, %14
br i1 %32, label %33, label %15
33: ; preds = %29, %5
ret void
}