#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 *calloc(int, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ memset(double *, int /*<<< orphan*/, int);
int polynomial_multiplication(double *, int, double *, int, double *, int);
int /*<<< orphan*/ swap_ptr(double **, double **);
double *polynomial_power(double *a, int adeg, int n, int *maxdegp) {
  int i, maxdeg = 0;
  double *c0, *c1;
  if (n == 0) {
    c0 = calloc(1, sizeof(double));
    c0[0] = 1.;
    if (maxdegp)
      *maxdegp = maxdeg;
    return c0;
  }
  c1 = calloc(adeg * n + 1, sizeof(double));
  c0 = calloc(adeg * n + 1, sizeof(double));
  c0[0] = 1.;
  for (i = 1; i <= n; i++) {
    memset(c1, 0, (adeg * n + 1) * sizeof(double));
    maxdeg = polynomial_multiplication(a, adeg, c0, maxdeg, c1, adeg * n);
    swap_ptr(&c0, &c1);
  }
  free(c1);
  if (maxdegp)
    *maxdegp = maxdeg;
  return c0;
}


x86 assembly (clang, -O0):
<polynomial_power>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11bb <polynomial_power+0x6b>
mov    $0x1,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsd  0xe6a(%rip),%xmm0
movsd  %xmm0,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     11ae <polynomial_power+0x5e>
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    128e <polynomial_power+0x13e>
mov    -0x14(%rbp),%edi
imul   -0x18(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
imul   -0x18(%rbp),%edi
add    $0x1,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsd  0xe09(%rip),%xmm0
movsd  %xmm0,(%rax)
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     1269 <polynomial_power+0x119>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%ecx
mov    -0x38(%rbp),%r8
mov    -0x14(%rbp),%r9d
imul   -0x18(%rbp),%r9d
call   1060 <polynomial_multiplication@plt>
mov    %eax,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <swap_ptr@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1202 <polynomial_power+0xb2>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
je     1286 <polynomial_power+0x136>
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<polynomial_power>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,%rbx
mov    %rdi,0x20(%rsp)
test   %edx,%edx
je     121e <polynomial_power+0xce>
mov    %edx,%ebp
mov    %esi,%r12d
mov    %rbx,0x18(%rsp)
mov    %edx,%r13d
imul   %esi,%r13d
lea    0x1(%r13),%ebx
mov    %ebx,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,%r15
mov    %rax,0x8(%rsp)
mov    %ebx,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,0x10(%rsp)
movabs $0x3ff0000000000000,%rcx
mov    %rcx,(%rax)
test   %ebp,%ebp
jle    1249 <polynomial_power+0xf9>
shl    $0x3,%ebx
add    $0xffffffff,%ebp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <memset@plt>
mov    0x10(%rsp),%rdx
mov    0x8(%rsp),%r8
mov    0x20(%rsp),%rdi
mov    %r12d,%esi
mov    %r14d,%ecx
mov    %r13d,%r9d
call   1060 <polynomial_multiplication@plt>
mov    %eax,%r14d
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1070 <swap_ptr@plt>
sub    $0x1,%ebp
jb     1217 <polynomial_power+0xc7>
mov    0x8(%rsp),%r15
jmp    11d0 <polynomial_power+0x80>
mov    0x8(%rsp),%r15
jmp    124c <polynomial_power+0xfc>
mov    $0x1,%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,0x10(%rsp)
movabs $0x3ff0000000000000,%rcx
mov    %rcx,(%rax)
xor    %r14d,%r14d
test   %rbx,%rbx
jne    125e <polynomial_power+0x10e>
jmp    1261 <polynomial_power+0x111>
xor    %r14d,%r14d
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rbx
test   %rbx,%rbx
je     1261 <polynomial_power+0x111>
mov    %r14d,(%rbx)
mov    0x10(%rsp),%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double* @polynomial_power(double* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca double*
%13 = alloca double*
store double* %0, double** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
store i32 0, i32* %11
%14 = load i32, i32* %8
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %4
%17 = call double* @calloc(i32 1, i32 8)
store double* %17, double** %12
%18 = load double*, double** %12
%19 = getelementptr inbounds double, double* %18, i64 0
store double 1.000000e+00, double* %19
%20 = load i32*, i32** %9
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* %11
%24 = load i32*, i32** %9
store i32 %23, i32* %24
br label %25
25: ; preds = %22, %16
%26 = load double*, double** %12
store double* %26, double** %5
br label %77
27: ; preds = %4
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = mul nsw i32 %28, %29
%31 = add nsw i32 %30, 1
%32 = call double* @calloc(i32 %31, i32 8)
store double* %32, double** %13
%33 = load i32, i32* %7
%34 = load i32, i32* %8
%35 = mul nsw i32 %33, %34
%36 = add nsw i32 %35, 1
%37 = call double* @calloc(i32 %36, i32 8)
store double* %37, double** %12
%38 = load double*, double** %12
%39 = getelementptr inbounds double, double* %38, i64 0
store double 1.000000e+00, double* %39
store i32 1, i32* %10
br label %40
40: ; preds = %64, %27
%41 = load i32, i32* %10
%42 = load i32, i32* %8
%43 = icmp sle i32 %41, %42
br i1 %43, label %44, label %67
44: ; preds = %40
%45 = load double*, double** %13
%46 = load i32, i32* %7
%47 = load i32, i32* %8
%48 = mul nsw i32 %46, %47
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = mul i64 %50, 8
%52 = trunc i64 %51 to i32
%53 = call i32 @memset(double* %45, i32 0, i32 %52)
%54 = load double*, double** %6
%55 = load i32, i32* %7
%56 = load double*, double** %12
%57 = load i32, i32* %11
%58 = load double*, double** %13
%59 = load i32, i32* %7
%60 = load i32, i32* %8
%61 = mul nsw i32 %59, %60
%62 = call i32 @polynomial_multiplication(double* %54, i32 %55, double* %56, i32 %57, double* %58, i32 %61)
store i32 %62, i32* %11
%63 = call i32 @swap_ptr(double** %12, double** %13)
br label %64
64: ; preds = %44
%65 = load i32, i32* %10
%66 = add nsw i32 %65, 1
store i32 %66, i32* %10
br label %40
67: ; preds = %40
%68 = load double*, double** %13
%69 = call i32 @free(double* %68)
%70 = load i32*, i32** %9
%71 = icmp ne i32* %70, null
br i1 %71, label %72, label %75
72: ; preds = %67
%73 = load i32, i32* %11
%74 = load i32*, i32** %9
store i32 %73, i32* %74
br label %75
75: ; preds = %72, %67
%76 = load double*, double** %12
store double* %76, double** %5
br label %77
77: ; preds = %75, %25
%78 = load double*, double** %5
ret double* %78
}

LLVM IR (-O2):
define double* @polynomial_power(double* %0, i32 %1, i32 %2, i32* writeonly %3) {
%5 = alloca double*
%6 = alloca double*
%7 = bitcast double** %5 to i8*
%8 = bitcast double** %6 to i8*
%9 = icmp eq i32 %2, 0
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = tail call double* @calloc(i32 1, i32 8)
store double* %11, double** %5
store double 1.000000e+00, double* %11
%12 = icmp eq i32* %3, null
br i1 %12, label %43, label %41
13: ; preds = %4
%14 = mul nsw i32 %2, %1
%15 = add nsw i32 %14, 1
%16 = tail call double* @calloc(i32 %15, i32 8)
store double* %16, double** %6
%17 = tail call double* @calloc(i32 %15, i32 8)
store double* %17, double** %5
store double 1.000000e+00, double* %17
%18 = icmp slt i32 %2, 1
br i1 %18, label %36, label %19
19: ; preds = %13
%20 = shl i32 %15, 3
br label %21
21: ; preds = %31, %19
%22 = phi double* [ %16, %19 ], [ %33, %31 ]
%23 = phi i32 [ 0, %19 ], [ %28, %31 ]
%24 = phi i32 [ 1, %19 ], [ %32, %31 ]
%25 = call i32 @memset(double* %22, i32 0, i32 %20)
%26 = load double*, double** %5
%27 = load double*, double** %6
%28 = call i32 @polynomial_multiplication(double* %0, i32 %1, double* %26, i32 %23, double* %27, i32 %14)
%29 = call i32 @swap_ptr(double** %5, double** %6)
%30 = icmp eq i32 %24, %2
br i1 %30, label %34, label %31
31: ; preds = %21
%32 = add nuw i32 %24, 1
%33 = load double*, double** %6
br label %21
34: ; preds = %21
%35 = load double*, double** %6
br label %36
36: ; preds = %34, %13
%37 = phi double* [ %16, %13 ], [ %35, %34 ]
%38 = phi i32 [ 0, %13 ], [ %28, %34 ]
%39 = call i32 @free(double* %37)
%40 = icmp eq i32* %3, null
br i1 %40, label %43, label %41
41: ; preds = %36, %10
%42 = phi i32 [ 0, %10 ], [ %38, %36 ]
store i32 %42, i32* %3
br label %43
43: ; preds = %41, %36, %10
%44 = load double*, double** %5
ret double* %44
}