; LLVM IR from SudeErzurumlu/matrix_eigenvalues_eigenvectors :: C (eigen_calculation)

; 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"

@.str = external hidden unnamed_addr constant [75 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @matrix_vector_mult(ptr noundef, ptr noundef, ptr noundef) #0

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @vector_norm(ptr noundef) #0

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

17:                                               ; preds = %26, %3
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 2
  br i1 %19, label %21, label %20

20:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %29

21:                                               ; preds = %17
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds double, ptr %22, i64 %24
  store double 1.000000e+00, ptr %25, align 8, !tbaa !11
  br label %26

26:                                               ; preds = %21
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %7, align 4, !tbaa !9
  br label %17, !llvm.loop !13

29:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 0.000000e+00, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %124, %29
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = icmp slt i32 %31, 1000
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  store i32 5, ptr %10, align 4
  br label %127

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #4
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds [2 x double], ptr %11, i64 0, i64 0
  call void @matrix_vector_mult(ptr noundef %35, ptr noundef %36, ptr noundef %37)
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %38 = getelementptr inbounds [2 x double], ptr %11, i64 0, i64 0
  %39 = call double @vector_norm(ptr noundef %38)
  store double %39, ptr %12, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %51, %34
  %41 = load i32, ptr %13, align 4, !tbaa !9
  %42 = icmp slt i32 %41, 2
  br i1 %42, label %44, label %43

43:                                               ; preds = %40
  store i32 8, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %54

44:                                               ; preds = %40
  %45 = load double, ptr %12, align 8, !tbaa !11
  %46 = load i32, ptr %13, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [2 x double], ptr %11, i64 0, i64 %47
  %49 = load double, ptr %48, align 8, !tbaa !11
  %50 = fdiv double %49, %45
  store double %50, ptr %48, align 8, !tbaa !11
  br label %51

51:                                               ; preds = %44
  %52 = load i32, ptr %13, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %13, align 4, !tbaa !9
  br label %40, !llvm.loop !15

54:                                               ; preds = %43
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  store double 0.000000e+00, ptr %55, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %73, %54
  %57 = load i32, ptr %14, align 4, !tbaa !9
  %58 = icmp slt i32 %57, 2
  br i1 %58, label %60, label %59

59:                                               ; preds = %56
  store i32 11, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %76

60:                                               ; preds = %56
  %61 = load i32, ptr %14, align 4, !tbaa !9
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [2 x double], ptr %11, i64 0, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !11
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = load i32, ptr %14, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds double, ptr %65, i64 %67
  %69 = load double, ptr %68, align 8, !tbaa !11
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load double, ptr %70, align 8, !tbaa !11
  %72 = call double @llvm.fmuladd.f64(double %64, double %69, double %71)
  store double %72, ptr %70, align 8, !tbaa !11
  br label %73

73:                                               ; preds = %60
  %74 = load i32, ptr %14, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %14, align 4, !tbaa !9
  br label %56, !llvm.loop !16

76:                                               ; preds = %59
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = load double, ptr %77, align 8, !tbaa !11
  %79 = load double, ptr %8, align 8, !tbaa !11
  %80 = fsub double %78, %79
  %81 = call double @llvm.fabs.f64(double %80)
  %82 = fcmp olt double %81, 1.000000e-09
  br i1 %82, label %83, label %101

83:                                               ; preds = %76
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %84

84:                                               ; preds = %97, %83
  %85 = load i32, ptr %15, align 4, !tbaa !9
  %86 = icmp slt i32 %85, 2
  br i1 %86, label %88, label %87

87:                                               ; preds = %84
  store i32 14, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  br label %100

88:                                               ; preds = %84
  %89 = load i32, ptr %15, align 4, !tbaa !9
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [2 x double], ptr %11, i64 0, i64 %90
  %92 = load double, ptr %91, align 8, !tbaa !11
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = load i32, ptr %15, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds double, ptr %93, i64 %95
  store double %92, ptr %96, align 8, !tbaa !11
  br label %97

97:                                               ; preds = %88
  %98 = load i32, ptr %15, align 4, !tbaa !9
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %15, align 4, !tbaa !9
  br label %84, !llvm.loop !17

100:                                              ; preds = %87
  store i32 1, ptr %10, align 4
  br label %121

101:                                              ; preds = %76
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = load double, ptr %102, align 8, !tbaa !11
  store double %103, ptr %8, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %104

104:                                              ; preds = %117, %101
  %105 = load i32, ptr %16, align 4, !tbaa !9
  %106 = icmp slt i32 %105, 2
  br i1 %106, label %108, label %107

107:                                              ; preds = %104
  store i32 17, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  br label %120

108:                                              ; preds = %104
  %109 = load i32, ptr %16, align 4, !tbaa !9
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [2 x double], ptr %11, i64 0, i64 %110
  %112 = load double, ptr %111, align 8, !tbaa !11
  %113 = load ptr, ptr %6, align 8, !tbaa !5
  %114 = load i32, ptr %16, align 4, !tbaa !9
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds double, ptr %113, i64 %115
  store double %112, ptr %116, align 8, !tbaa !11
  br label %117

117:                                              ; preds = %108
  %118 = load i32, ptr %16, align 4, !tbaa !9
  %119 = add nsw i32 %118, 1
  store i32 %119, ptr %16, align 4, !tbaa !9
  br label %104, !llvm.loop !18

120:                                              ; preds = %107
  store i32 0, ptr %10, align 4
  br label %121

121:                                              ; preds = %120, %100
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #4
  %122 = load i32, ptr %10, align 4
  switch i32 %122, label %127 [
    i32 0, label %123
  ]

123:                                              ; preds = %121
  br label %124

124:                                              ; preds = %123
  %125 = load i32, ptr %9, align 4, !tbaa !9
  %126 = add nsw i32 %125, 1
  store i32 %126, ptr %9, align 4, !tbaa !9
  br label %30, !llvm.loop !19

127:                                              ; preds = %121, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %128 = load i32, ptr %10, align 4
  switch i32 %128, label %131 [
    i32 5, label %129
  ]

129:                                              ; preds = %127
  %130 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  store i32 0, ptr %10, align 4
  br label %131

131:                                              ; preds = %129, %127
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %132 = load i32, ptr %10, align 4
  switch i32 %132, label %134 [
    i32 0, label %133
    i32 1, label %133
  ]

133:                                              ; preds = %131, %131
  ret void

134:                                              ; preds = %131
  unreachable
}

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

declare i32 @printf(ptr noundef, ...) #3

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { "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 #4 = { 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}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !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"

@.str = external hidden unnamed_addr constant [75 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @matrix_vector_mult(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @vector_norm(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @calculate_eigenvalue_vector(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr noundef %2) local_unnamed_addr #0 {
.preheader44.preheader:
  %3 = alloca [2 x double], align 16
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  store <2 x double> <double 1.000000e+00, double 1.000000e+00>, ptr %2, align 8, !tbaa !5
  br label %.preheader44

5:                                                ; preds = %.preheader44
  %6 = add nuw nsw i32 %.03952, 1
  %exitcond = icmp eq i32 %6, 1000
  br i1 %exitcond, label %.critedge, label %.preheader44, !llvm.loop !9

.preheader44:                                     ; preds = %.preheader44.preheader, %5
  %.03952 = phi i32 [ %6, %5 ], [ 0, %.preheader44.preheader ]
  %.04051 = phi double [ %17, %5 ], [ 0.000000e+00, %.preheader44.preheader ]
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #5
  call void @matrix_vector_mult(ptr noundef %0, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %7 = call double @vector_norm(ptr noundef nonnull %3)
  %8 = load <2 x double>, ptr %3, align 16, !tbaa !5
  %9 = insertelement <2 x double> poison, double %7, i64 0
  %10 = shufflevector <2 x double> %9, <2 x double> poison, <2 x i32> zeroinitializer
  %11 = fdiv <2 x double> %8, %10
  store <2 x double> %11, ptr %3, align 16, !tbaa !5
  store double 0.000000e+00, ptr %1, align 8, !tbaa !5
  %12 = load double, ptr %2, align 8, !tbaa !5
  %13 = extractelement <2 x double> %11, i64 0
  %14 = call double @llvm.fmuladd.f64(double %13, double %12, double 0.000000e+00)
  store double %14, ptr %1, align 8, !tbaa !5
  %15 = load double, ptr %4, align 8, !tbaa !5
  %16 = extractelement <2 x double> %11, i64 1
  %17 = call double @llvm.fmuladd.f64(double %16, double %15, double %14)
  store double %17, ptr %1, align 8, !tbaa !5
  %18 = fsub double %17, %.04051
  %19 = call double @llvm.fabs.f64(double %18)
  %20 = fcmp uge double %19, 1.000000e-09
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 16 dereferenceable(16) %3, i64 16, i1 false), !tbaa !5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #5
  br i1 %20, label %5, label %.loopexit45

.critedge:                                        ; preds = %5
  %21 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %.loopexit45

.loopexit45:                                      ; preds = %.preheader44, %.critedge
  ret void
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nofree nounwind "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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass