; LLVM IR from Dutta-SD/Numerical_Methods :: Linear_Algebra (Power_Method)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local double @Max_Arr(ptr noundef %0) #1 {
  %2 = alloca double, align 8
  %3 = alloca ptr, align 8
  %4 = alloca double, align 8
  %5 = alloca [3 x double], align 16
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %22, %1
  %9 = load i32, ptr %6, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 3
  br i1 %10, label %11, label %25

11:                                               ; preds = %8
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1 x double], ptr %12, i64 %14
  %16 = getelementptr inbounds [1 x double], ptr %15, i64 0, i64 0
  %17 = load double, ptr %16, align 8, !tbaa !11
  %18 = call double @llvm.fabs.f64(double %17)
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [3 x double], ptr %5, i64 0, i64 %20
  store double %18, ptr %21, align 8, !tbaa !11
  br label %22

22:                                               ; preds = %11
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %6, align 4, !tbaa !9
  br label %8, !llvm.loop !13

25:                                               ; preds = %8
  %26 = getelementptr inbounds [3 x double], ptr %5, i64 0, i64 0
  %27 = load double, ptr %26, align 16, !tbaa !11
  store double %27, ptr %4, align 8, !tbaa !11
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %28

28:                                               ; preds = %42, %25
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = icmp slt i32 %29, 3
  br i1 %30, label %31, label %45

31:                                               ; preds = %28
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [3 x double], ptr %5, i64 0, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !11
  %36 = load double, ptr %4, align 8, !tbaa !11
  %37 = fcmp ogt double %35, %36
  br i1 %37, label %38, label %41

38:                                               ; preds = %31
  %39 = getelementptr inbounds [3 x double], ptr %5, i64 0, i64 0
  %40 = load double, ptr %39, align 16, !tbaa !11
  store double %40, ptr %4, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %38, %31
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %6, align 4, !tbaa !9
  br label %28, !llvm.loop !15

45:                                               ; preds = %28
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %70, %45
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = icmp slt i32 %47, 3
  br i1 %48, label %49, label %73

49:                                               ; preds = %46
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [3 x double], ptr %5, i64 0, i64 %51
  %53 = load double, ptr %52, align 8, !tbaa !11
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1 x double], ptr %54, i64 %56
  %58 = getelementptr inbounds [1 x double], ptr %57, i64 0, i64 0
  %59 = load double, ptr %58, align 8, !tbaa !11
  %60 = fadd double %53, %59
  %61 = fcmp oeq double %60, 0.000000e+00
  br i1 %61, label %62, label %69

62:                                               ; preds = %49
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [1 x double], ptr %63, i64 %65
  %67 = getelementptr inbounds [1 x double], ptr %66, i64 0, i64 0
  %68 = load double, ptr %67, align 8, !tbaa !11
  store double %68, ptr %2, align 8
  store i32 1, ptr %7, align 4
  br label %74

69:                                               ; preds = %49
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %6, align 4, !tbaa !9
  br label %46, !llvm.loop !16

73:                                               ; preds = %46
  store i32 0, ptr %7, align 4
  br label %74

74:                                               ; preds = %73, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %75 = load i32, ptr %7, align 4
  switch i32 %75, label %78 [
    i32 0, label %76
    i32 1, label %76
  ]

76:                                               ; preds = %74, %74
  %77 = load double, ptr %2, align 8
  ret double %77

78:                                               ; preds = %74
  unreachable
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local double @Max_Arr(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
.preheader.preheader:
  %1 = load double, ptr %0, align 8, !tbaa !5
  %2 = tail call double @llvm.fabs.f64(double %1)
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load double, ptr %3, align 8, !tbaa !5
  %5 = fadd double %2, %1
  %6 = fcmp oeq double %5, 0.000000e+00
  br i1 %6, label %12, label %.preheader.1

.preheader.1:                                     ; preds = %.preheader.preheader
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load double, ptr %7, align 8, !tbaa !5
  %9 = tail call double @llvm.fabs.f64(double %8)
  %10 = fadd double %9, %8
  %11 = fcmp oeq double %10, 0.000000e+00
  br i1 %11, label %12, label %.preheader.2

.preheader.2:                                     ; preds = %.preheader.1
  br label %12

12:                                               ; preds = %.preheader.2, %.preheader.1, %.preheader.preheader
  %.lcssa = phi double [ %1, %.preheader.preheader ], [ %8, %.preheader.1 ], [ %4, %.preheader.2 ]
  ret double %.lcssa
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: ADCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass