#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 fabs(double);
int /*<<< orphan*/ free(double *);
double inner(double *, double *, int);
int /*<<< orphan*/ product(double *, double *, double *, int);
double *random_vect(int);
double sqrt(double);
int power(double *a, int n, int maxiter, double eps, double *v, double *w) {
  int niter, i;
  double *y;
  double sum, l, normy, d;
  y = random_vect(n);
  niter = 0;
  do {
    normy = sqrt(inner(y, y, n));
    for (i = 0; i < n; i++)
      w[i] = y[i] / normy;
    product(y, a, w, n);
    l = inner(w, y, n);
    niter++;
    for (sum = 0, i = 0; i < n; i++) {
      d = y[i] - l * w[i];
      sum += d * d;
    }
    d = sqrt(sum);
  } while (d > eps * fabs(l) && niter < maxiter);
  free(y);
  *v = l;
  return niter;
}


x86 assembly (clang, -O0):
<power>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <random_vect@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <inner@plt>
call   1070 <sqrt@plt>
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11dc <power+0x8c>
mov    -0x38(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
divsd  -0x50(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11a3 <power+0x53>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0xc(%rbp),%ecx
call   1060 <product@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <inner@plt>
movsd  %xmm0,-0x48(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1296 <power+0x146>
mov    -0x38(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x48(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    121d <power+0xcd>
movsd  -0x40(%rbp),%xmm0
call   1070 <sqrt@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x48(%rbp),%xmm2
movaps 0xd45(%rip),%xmm3
pand   %xmm3,%xmm2
mulsd  %xmm2,%xmm1
xor    %eax,%eax
ucomisd %xmm1,%xmm0
mov    %al,-0x59(%rbp)
jbe    12de <power+0x18e>
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
setl   %al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%al
test   $0x1,%al
jne    1182 <power+0x32>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x48(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<power>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r8,%rbx
mov    %rcx,0x28(%rsp)
movsd  %xmm0,0x50(%rsp)
mov    %edx,0x4(%rsp)
mov    %esi,%r13d
mov    %rdi,0x48(%rsp)
mov    %esi,%edi
call   1050 <random_vect@plt>
mov    %rax,%rbp
mov    %r13d,%r12d
lea    (%rbx,%r12,8),%rax
lea    0x0(,%r12,8),%rcx
add    %rbp,%rcx
mov    %r12d,%r15d
and    $0xfffffffe,%r15d
lea    -0x2(%r15),%rdx
mov    %rdx,0x40(%rsp)
shr    %rdx
add    $0x1,%rdx
lea    -0x1(%r12),%rsi
mov    %rsi,0x8(%rsp)
cmp    %rbx,%rcx
seta   %cl
cmp    %rax,%rbp
setb   %al
and    %cl,%al
mov    %al,0x3(%rsp)
mov    %rdx,%rax
mov    %rdx,0x38(%rsp)
and    $0xfffffffffffffffe,%rdx
mov    %rdx,0x30(%rsp)
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
call   1040 <inner@plt>
ucomisd 0xe2a(%rip),%xmm0
jb     1210 <power+0xc0>
sqrtsd %xmm0,%xmm0
test   %r13d,%r13d
jg     121e <power+0xce>
jmp    12e8 <power+0x198>
cs nopw 0x0(%rax,%rax,1)
call   1070 <sqrt@plt>
test   %r13d,%r13d
jle    12e8 <power+0x198>
cmp    $0x1,%r13d
sete   %al
or     0x3(%rsp),%al
je     1230 <power+0xe0>
xor    %ecx,%ecx
jmp    1297 <power+0x147>
nop
movapd %xmm0,%xmm1
unpcklpd %xmm0,%xmm1
cmpq   $0x0,0x40(%rsp)
je     13ea <power+0x29a>
mov    0x30(%rsp),%rcx
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movupd 0x0(%rbp,%rax,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx,%rax,8)
movupd 0x10(%rbp,%rax,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,0x10(%rbx,%rax,8)
add    $0x4,%rax
add    $0xfffffffffffffffe,%rcx
jne    1250 <power+0x100>
testb  $0x1,0x38(%rsp)
je     128f <power+0x13f>
movupd 0x0(%rbp,%rax,8),%xmm2
divpd  %xmm1,%xmm2
movupd %xmm2,(%rbx,%rax,8)
mov    %r15,%rcx
cmp    %r12,%r15
je     12e8 <power+0x198>
mov    %rcx,%rax
test   $0x1,%r12b
je     12b6 <power+0x166>
movsd  0x0(%rbp,%rcx,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rcx,8)
mov    %rcx,%rax
or     $0x1,%rax
cmp    %rcx,0x8(%rsp)
je     12e8 <power+0x198>
nopl   (%rax)
movsd  0x0(%rbp,%rax,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx,%rax,8)
movsd  0x8(%rbp,%rax,8),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rbx,%rax,8)
add    $0x2,%rax
cmp    %rax,%r12
jne    12c0 <power+0x170>
mov    %rbp,%rdi
mov    0x48(%rsp),%rsi
mov    %rbx,%rdx
mov    %r13d,%ecx
call   1060 <product@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
call   1040 <inner@plt>
movapd %xmm0,%xmm3
test   %r13d,%r13d
jle    1370 <power+0x220>
movapd %xmm3,%xmm1
xorpd  0xce2(%rip),%xmm1
cmpq   $0x0,0x8(%rsp)
je     1380 <power+0x230>
xorpd  %xmm0,%xmm0
xor    %eax,%eax
nopl   0x0(%rax)
movsd  (%rbx,%rax,8),%xmm2
mulsd  %xmm1,%xmm2
addsd  0x0(%rbp,%rax,8),%xmm2
mulsd  %xmm2,%xmm2
addsd  %xmm0,%xmm2
movsd  0x8(%rbx,%rax,8),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x8(%rbp,%rax,8),%xmm0
mulsd  %xmm0,%xmm0
addsd  %xmm2,%xmm0
add    $0x2,%rax
cmp    %rax,%r15
jne    1330 <power+0x1e0>
test   $0x1,%r12b
jne    138c <power+0x23c>
jmp    139f <power+0x24f>
xorpd  %xmm0,%xmm0
jmp    139f <power+0x24f>
cs nopw 0x0(%rax,%rax,1)
xorpd  %xmm0,%xmm0
xor    %eax,%eax
test   $0x1,%r12b
je     139f <power+0x24f>
mulsd  (%rbx,%rax,8),%xmm1
addsd  0x0(%rbp,%rax,8),%xmm1
mulsd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
ucomisd 0xc79(%rip),%xmm0
jb     13b0 <power+0x260>
sqrtsd %xmm0,%xmm0
jmp    13c1 <power+0x271>
nop
movapd %xmm3,0x10(%rsp)
call   1070 <sqrt@plt>
movapd 0x10(%rsp),%xmm3
add    $0x1,%r14d
movapd %xmm3,%xmm1
andpd  0xc3f(%rip),%xmm1
mulsd  0x50(%rsp),%xmm1
ucomisd %xmm1,%xmm0
jbe    13fc <power+0x2ac>
cmp    0x4(%rsp),%r14d
jl     11e0 <power+0x90>
jmp    13fc <power+0x2ac>
xor    %eax,%eax
testb  $0x1,0x38(%rsp)
jne    1280 <power+0x130>
jmp    128f <power+0x13f>
mov    %rbp,%rdi
movapd %xmm3,0x10(%rsp)
call   1030 <free@plt>
mov    0x28(%rsp),%rax
movaps 0x10(%rsp),%xmm0
movsd  %xmm0,(%rax)
mov    %r14d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @power(double* %0, i32 %1, i32 %2, double %3, double* %4, double* %5) {
%7 = alloca double*
%8 = alloca i32
%9 = alloca i32
%10 = alloca double
%11 = alloca double*
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
%15 = alloca double*
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
store double* %0, double** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store double %3, double* %10
store double* %4, double** %11
store double* %5, double** %12
%20 = load i32, i32* %8
%21 = call double* @random_vect(i32 %20)
store double* %21, double** %15
store i32 0, i32* %13
br label %22
22: ; preds = %98, %6
%23 = load double*, double** %15
%24 = load double*, double** %15
%25 = load i32, i32* %8
%26 = call double @inner(double* %23, double* %24, i32 %25)
%27 = call double @sqrt(double %26)
store double %27, double* %18
store i32 0, i32* %14
br label %28
28: ; preds = %44, %22
%29 = load i32, i32* %14
%30 = load i32, i32* %8
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %47
32: ; preds = %28
%33 = load double*, double** %15
%34 = load i32, i32* %14
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds double, double* %33, i64 %35
%37 = load double, double* %36
%38 = load double, double* %18
%39 = fdiv double %37, %38
%40 = load double*, double** %12
%41 = load i32, i32* %14
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
store double %39, double* %43
br label %44
44: ; preds = %32
%45 = load i32, i32* %14
%46 = add nsw i32 %45, 1
store i32 %46, i32* %14
br label %28
47: ; preds = %28
%48 = load double*, double** %15
%49 = load double*, double** %7
%50 = load double*, double** %12
%51 = load i32, i32* %8
%52 = call i32 @product(double* %48, double* %49, double* %50, i32 %51)
%53 = load double*, double** %12
%54 = load double*, double** %15
%55 = load i32, i32* %8
%56 = call double @inner(double* %53, double* %54, i32 %55)
store double %56, double* %17
%57 = load i32, i32* %13
%58 = add nsw i32 %57, 1
store i32 %58, i32* %13
store double 0.000000e+00, double* %16
store i32 0, i32* %14
br label %59
59: ; preds = %81, %47
%60 = load i32, i32* %14
%61 = load i32, i32* %8
%62 = icmp slt i32 %60, %61
br i1 %62, label %63, label %84
63: ; preds = %59
%64 = load double*, double** %15
%65 = load i32, i32* %14
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds double, double* %64, i64 %66
%68 = load double, double* %67
%69 = load double, double* %17
%70 = load double*, double** %12
%71 = load i32, i32* %14
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
%74 = load double, double* %73
%75 = fneg double %69
%76 = call double @llvm.fmuladd.f64(double %75, double %74, double %68)
store double %76, double* %19
%77 = load double, double* %19
%78 = load double, double* %19
%79 = load double, double* %16
%80 = call double @llvm.fmuladd.f64(double %77, double %78, double %79)
store double %80, double* %16
br label %81
81: ; preds = %63
%82 = load i32, i32* %14
%83 = add nsw i32 %82, 1
store i32 %83, i32* %14
br label %59
84: ; preds = %59
%85 = load double, double* %16
%86 = call double @sqrt(double %85)
store double %86, double* %19
br label %87
87: ; preds = %84
%88 = load double, double* %19
%89 = load double, double* %10
%90 = load double, double* %17
%91 = call double @llvm.fabs.f64(double %90)
%92 = fmul double %89, %91
%93 = fcmp ogt double %88, %92
br i1 %93, label %94, label %98
94: ; preds = %87
%95 = load i32, i32* %13
%96 = load i32, i32* %9
%97 = icmp slt i32 %95, %96
br label %98
98: ; preds = %94, %87
%99 = phi i1 [ false, %87 ], [ %97, %94 ]
br i1 %99, label %22, label %100
100: ; preds = %98
%101 = load double*, double** %15
%102 = call i32 @free(double* %101)
%103 = load double, double* %17
%104 = load double*, double** %11
store double %103, double* %104
%105 = load i32, i32* %13
ret i32 %105
}

LLVM IR (-O2):
define i32 @power(double* %0, i32 %1, i32 %2, double %3, double* nocapture writeonly %4, double* %5) {
%7 = tail call double* @random_vect(i32 %1)
%8 = icmp sgt i32 %1, 0
%9 = zext i32 %1 to i64
%10 = getelementptr double, double* %5, i64 %9
%11 = getelementptr double, double* %7, i64 %9
%12 = and i64 %9, 4294967294
%13 = add nsw i64 %12, -2
%14 = lshr exact i64 %13, 1
%15 = add nuw i64 %14, 1
%16 = add nsw i64 %9, -1
%17 = icmp eq i32 %1, 1
%18 = icmp ugt double* %11, %5
%19 = icmp ult double* %7, %10
%20 = and i1 %18, %19
%21 = and i64 %9, 4294967294
%22 = and i64 %15, 1
%23 = icmp eq i64 %13, 0
%24 = and i64 %15, -2
%25 = icmp eq i64 %22, 0
%26 = icmp eq i64 %21, %9
%27 = and i64 %9, 1
%28 = icmp eq i64 %27, 0
%29 = and i64 %9, 1
%30 = icmp eq i64 %16, 0
%31 = and i64 %9, 4294967294
%32 = icmp eq i64 %29, 0
br label %33
33: ; preds = %132, %6
%34 = phi i32 [ 0, %6 ], [ %98, %132 ]
%35 = tail call double @inner(double* %7, double* %7, i32 %1)
%36 = tail call double @sqrt(double %35)
br i1 %8, label %37, label %95
37: ; preds = %33
%38 = select i1 %17, i1 true, i1 %20
br i1 %38, label %71, label %39
39: ; preds = %37
%40 = insertelement <2 x double> poison, double %36, i64 0
%41 = shufflevector <2 x double> %40, <2 x double> poison, <2 x i32> zeroinitializer
br i1 %23, label %61, label %42
42: ; preds = %39, %42
%43 = phi i64 [ %58, %42 ], [ 0, %39 ]
%44 = phi i64 [ %59, %42 ], [ 0, %39 ]
%45 = getelementptr inbounds double, double* %7, i64 %43
%46 = bitcast double* %45 to <2 x double>*
%47 = load <2 x double>, <2 x double>* %46
%48 = fdiv <2 x double> %47, %41
%49 = getelementptr inbounds double, double* %5, i64 %43
%50 = bitcast double* %49 to <2 x double>*
store <2 x double> %48, <2 x double>* %50
%51 = or i64 %43, 2
%52 = getelementptr inbounds double, double* %7, i64 %51
%53 = bitcast double* %52 to <2 x double>*
%54 = load <2 x double>, <2 x double>* %53
%55 = fdiv <2 x double> %54, %41
%56 = getelementptr inbounds double, double* %5, i64 %51
%57 = bitcast double* %56 to <2 x double>*
store <2 x double> %55, <2 x double>* %57
%58 = add nuw i64 %43, 4
%59 = add nuw i64 %44, 2
%60 = icmp eq i64 %59, %24
br i1 %60, label %61, label %42
61: ; preds = %42, %39
%62 = phi i64 [ 0, %39 ], [ %58, %42 ]
br i1 %25, label %70, label %63
63: ; preds = %61
%64 = getelementptr inbounds double, double* %7, i64 %62
%65 = bitcast double* %64 to <2 x double>*
%66 = load <2 x double>, <2 x double>* %65
%67 = fdiv <2 x double> %66, %41
%68 = getelementptr inbounds double, double* %5, i64 %62
%69 = bitcast double* %68 to <2 x double>*
store <2 x double> %67, <2 x double>* %69
br label %70
70: ; preds = %61, %63
br i1 %26, label %95, label %71
71: ; preds = %37, %70
%72 = phi i64 [ 0, %37 ], [ %21, %70 ]
br i1 %28, label %79, label %73
73: ; preds = %71
%74 = getelementptr inbounds double, double* %7, i64 %72
%75 = load double, double* %74
%76 = fdiv double %75, %36
%77 = getelementptr inbounds double, double* %5, i64 %72
store double %76, double* %77
%78 = or i64 %72, 1
br label %79
79: ; preds = %73, %71
%80 = phi i64 [ %72, %71 ], [ %78, %73 ]
%81 = icmp eq i64 %16, %72
br i1 %81, label %95, label %82
82: ; preds = %79, %82
%83 = phi i64 [ %93, %82 ], [ %80, %79 ]
%84 = getelementptr inbounds double, double* %7, i64 %83
%85 = load double, double* %84
%86 = fdiv double %85, %36
%87 = getelementptr inbounds double, double* %5, i64 %83
store double %86, double* %87
%88 = add nuw nsw i64 %83, 1
%89 = getelementptr inbounds double, double* %7, i64 %88
%90 = load double, double* %89
%91 = fdiv double %90, %36
%92 = getelementptr inbounds double, double* %5, i64 %88
store double %91, double* %92
%93 = add nuw nsw i64 %83, 2
%94 = icmp eq i64 %93, %9
br i1 %94, label %95, label %82
95: ; preds = %79, %82, %70, %33
%96 = tail call i32 @product(double* %7, double* %0, double* %5, i32 %1)
%97 = tail call double @inner(double* %5, double* %7, i32 %1)
%98 = add nuw nsw i32 %34, 1
br i1 %8, label %99, label %132
99: ; preds = %95
%100 = fneg double %97
br i1 %30, label %121, label %101
101: ; preds = %99, %101
%102 = phi i64 [ %118, %101 ], [ 0, %99 ]
%103 = phi double [ %117, %101 ], [ 0.000000e+00, %99 ]
%104 = phi i64 [ %119, %101 ], [ 0, %99 ]
%105 = getelementptr inbounds double, double* %7, i64 %102
%106 = load double, double* %105
%107 = getelementptr inbounds double, double* %5, i64 %102
%108 = load double, double* %107
%109 = tail call double @llvm.fmuladd.f64(double %100, double %108, double %106)
%110 = tail call double @llvm.fmuladd.f64(double %109, double %109, double %103)
%111 = or i64 %102, 1
%112 = getelementptr inbounds double, double* %7, i64 %111
%113 = load double, double* %112
%114 = getelementptr inbounds double, double* %5, i64 %111
%115 = load double, double* %114
%116 = tail call double @llvm.fmuladd.f64(double %100, double %115, double %113)
%117 = tail call double @llvm.fmuladd.f64(double %116, double %116, double %110)
%118 = add nuw nsw i64 %102, 2
%119 = add i64 %104, 2
%120 = icmp eq i64 %119, %31
br i1 %120, label %121, label %101
121: ; preds = %101, %99
%122 = phi double [ undef, %99 ], [ %117, %101 ]
%123 = phi i64 [ 0, %99 ], [ %118, %101 ]
%124 = phi double [ 0.000000e+00, %99 ], [ %117, %101 ]
br i1 %32, label %132, label %125
125: ; preds = %121
%126 = getelementptr inbounds double, double* %7, i64 %123
%127 = load double, double* %126
%128 = getelementptr inbounds double, double* %5, i64 %123
%129 = load double, double* %128
%130 = tail call double @llvm.fmuladd.f64(double %100, double %129, double %127)
%131 = tail call double @llvm.fmuladd.f64(double %130, double %130, double %124)
br label %132
132: ; preds = %125, %121, %95
%133 = phi double [ 0.000000e+00, %95 ], [ %122, %121 ], [ %131, %125 ]
%134 = tail call double @sqrt(double %133)
%135 = tail call double @llvm.fabs.f64(double %97)
%136 = fmul double %135, %3
%137 = fcmp ogt double %134, %136
%138 = icmp slt i32 %98, %2
%139 = select i1 %137, i1 %138, i1 false
br i1 %139, label %33, label %140
140: ; preds = %132
%141 = tail call i32 @free(double* %7)
store double %97, double* %4
ret i32 %98
}