#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 */
typedef int uint32_t;

/* Variables and functions */
int fabs(double);
int /*<<< orphan*/ produce_matrix_vector_product(double *, double *, double *,
                                                 int, int);
double rayliegh_quatient(double *, double *, int);
void power_method(double a[], double n[], double x[], double ix[],
                  uint32_t cubic_matrix_size) {
  double x_old[cubic_matrix_size];
  uint32_t i = 0;
  double r = 0;
  double r_new = 0;
  for (i = 0; i < cubic_matrix_size; i++)
    x_old[i] = ix[i];
  produce_matrix_vector_product(a, ix, x, cubic_matrix_size, cubic_matrix_size);
  r_new = rayliegh_quatient(a, x, cubic_matrix_size);
  r = 0.0;
  while (fabs(r - r_new) > 1E-6) {
    r = r_new;
    for (i = 0; i < cubic_matrix_size; i++) {
      x_old[i] = x[i];
    }
    produce_matrix_vector_product(a, x_old, x, cubic_matrix_size,
                                  cubic_matrix_size);
    r_new = rayliegh_quatient(a, x, cubic_matrix_size);
  }
  n[0] = r_new;
}


x86 assembly (clang, -O0):
<power_method>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11c5 <power_method+0x95>
mov    -0x58(%rbp),%rax
mov    -0x20(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm0
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1191 <power_method+0x61>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1050 <produce_matrix_vector_product@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <rayliegh_quatient@plt>
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
subsd  -0x50(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm0
movsd  0xdeb(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1296 <power_method+0x166>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1264 <power_method+0x134>
mov    -0x58(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
movsd  (%rcx,%rdx,8),%xmm0
movslq -0x3c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1230 <power_method+0x100>
mov    -0x58(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1050 <produce_matrix_vector_product@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <rayliegh_quatient@plt>
movsd  %xmm0,-0x50(%rbp)
jmp    11fa <power_method+0xca>
movsd  -0x50(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<power_method>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%ebx
mov    %rdx,%r15
mov    %rsi,-0x38(%rbp)
mov    %rdi,%r12
mov    %r8d,%r13d
mov    %rsp,%r14
lea    0xf(,%r13,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
test   %r8d,%r8d
jle    1196 <power_method+0x56>
lea    0x0(,%r13,8),%rdx
mov    %r14,%rdi
mov    %rcx,%rsi
mov    %rcx,-0x30(%rbp)
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rcx
mov    %r12,%rdi
mov    %rcx,%rsi
mov    %r15,%rdx
mov    %ebx,%ecx
mov    %ebx,%r8d
call   1060 <produce_matrix_vector_product@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <rayliegh_quatient@plt>
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
movsd  %xmm1,-0x30(%rbp)
subsd  %xmm1,%xmm0
call   1040 <fabs@plt>
test   %eax,%eax
jle    1239 <power_method+0xf9>
shl    $0x3,%r13
jmp    1225 <power_method+0xe5>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %ebx,%ecx
mov    %ebx,%r8d
call   1060 <produce_matrix_vector_product@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <rayliegh_quatient@plt>
movapd %xmm0,%xmm1
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  %xmm1,%xmm0
call   1040 <fabs@plt>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
test   %eax,%eax
jle    123e <power_method+0xfe>
test   %ebx,%ebx
jle    11e0 <power_method+0xa0>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1050 <memcpy@plt>
jmp    11e0 <power_method+0xa0>
movsd  -0x30(%rbp),%xmm0
mov    -0x38(%rbp),%rax
movsd  %xmm0,(%rax)
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @power_method(double* %0, double* %1, double* %2, double* %3, i32 %4) {
%6 = alloca double*
%7 = alloca double*
%8 = alloca double*
%9 = alloca double*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca double
%15 = alloca double
store double* %0, double** %6
store double* %1, double** %7
store double* %2, double** %8
store double* %3, double** %9
store i32 %4, i32* %10
%16 = load i32, i32* %10
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %11
%19 = alloca double, i64 %17
store i64 %17, i64* %12
store i32 0, i32* %13
store double 0.000000e+00, double* %14
store double 0.000000e+00, double* %15
store i32 0, i32* %13
br label %20
20: ; preds = %33, %5
%21 = load i32, i32* %13
%22 = load i32, i32* %10
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = load double*, double** %9
%26 = load i32, i32* %13
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double, double* %25, i64 %27
%29 = load double, double* %28
%30 = load i32, i32* %13
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %19, i64 %31
store double %29, double* %32
br label %33
33: ; preds = %24
%34 = load i32, i32* %13
%35 = add nsw i32 %34, 1
store i32 %35, i32* %13
br label %20
36: ; preds = %20
%37 = load double*, double** %6
%38 = load double*, double** %9
%39 = load double*, double** %8
%40 = load i32, i32* %10
%41 = load i32, i32* %10
%42 = call i32 @produce_matrix_vector_product(double* %37, double* %38, double* %39, i32 %40, i32 %41)
%43 = load double*, double** %6
%44 = load double*, double** %8
%45 = load i32, i32* %10
%46 = call double @rayliegh_quatient(double* %43, double* %44, i32 %45)
store double %46, double* %15
store double 0.000000e+00, double* %14
br label %47
47: ; preds = %72, %36
%48 = load double, double* %14
%49 = load double, double* %15
%50 = fsub double %48, %49
%51 = call i32 @fabs(double %50)
%52 = sitofp i32 %51 to double
%53 = fcmp ogt double %52, 0x3EB0C6F7A0B5ED8D
br i1 %53, label %54, label %82
54: ; preds = %47
%55 = load double, double* %15
store double %55, double* %14
store i32 0, i32* %13
br label %56
56: ; preds = %69, %54
%57 = load i32, i32* %13
%58 = load i32, i32* %10
%59 = icmp slt i32 %57, %58
br i1 %59, label %60, label %72
60: ; preds = %56
%61 = load double*, double** %8
%62 = load i32, i32* %13
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
%65 = load double, double* %64
%66 = load i32, i32* %13
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %19, i64 %67
store double %65, double* %68
br label %69
69: ; preds = %60
%70 = load i32, i32* %13
%71 = add nsw i32 %70, 1
store i32 %71, i32* %13
br label %56
72: ; preds = %56
%73 = load double*, double** %6
%74 = load double*, double** %8
%75 = load i32, i32* %10
%76 = load i32, i32* %10
%77 = call i32 @produce_matrix_vector_product(double* %73, double* %19, double* %74, i32 %75, i32 %76)
%78 = load double*, double** %6
%79 = load double*, double** %8
%80 = load i32, i32* %10
%81 = call double @rayliegh_quatient(double* %78, double* %79, i32 %80)
store double %81, double* %15
br label %47
82: ; preds = %47
%83 = load double, double* %15
%84 = load double*, double** %7
%85 = getelementptr inbounds double, double* %84, i64 0
store double %83, double* %85
%86 = load i8*, i8** %11
ret void
}

LLVM IR (-O2):
define void @power_method(double* %0, double* nocapture writeonly %1, double* %2, double* %3, i32 %4) {
%6 = bitcast double* %2 to i8*
%7 = zext i32 %4 to i64
%8 = alloca double, i64 %7
%9 = bitcast double* %8 to i8*
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = bitcast double* %3 to i8*
%13 = shl nuw nsw i64 %7, 3
br label %14
14: ; preds = %11, %5
%15 = tail call i32 @produce_matrix_vector_product(double* %0, double* %3, double* %2, i32 %4, i32 %4)
%16 = tail call double @rayliegh_quatient(double* %0, double* %2, i32 %4)
%17 = fsub double 0.000000e+00, %16
%18 = call i32 @fabs(double %17)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %14
%21 = shl nuw nsw i64 %7, 3
br label %22
22: ; preds = %20, %25
%23 = phi double [ %16, %20 ], [ %27, %25 ]
br i1 %10, label %24, label %25
24: ; preds = %22
br label %25
25: ; preds = %24, %22
%26 = call i32 @produce_matrix_vector_product(double* %0, double* %8, double* %2, i32 %4, i32 %4)
%27 = call double @rayliegh_quatient(double* %0, double* %2, i32 %4)
%28 = fsub double %23, %27
%29 = call i32 @fabs(double %28)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %22, label %31
31: ; preds = %25, %14
%32 = phi double [ %16, %14 ], [ %27, %25 ]
store double %32, double* %1
ret void
}