; LLVM IR from radualexandrub/Optimization-Algorithms-Find-local-minimum :: 2D_Derivative_NonQuadratic_CostFunctions (Gradienti_Conjugati_Rez)

; 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: nounwind
declare double @pow(double noundef, double noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @Vec_scale(i32 noundef, double noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @Vec_add_coefVec(i32 noundef, ptr noundef, double noundef, ptr noundef, ptr noundef) #3

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

; Function Attrs: nounwind uwtable
declare dso_local double @Vec_norm(i32 noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @Mat_mult_Vec(i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

; Function Attrs: nounwind uwtable
declare dso_local double @Vec_sprod(i32 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local double @Vec_Mat_Vec(i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local void @Gradienti_Conjugati_Rez(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca double, align 8
  %18 = alloca double, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i64, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = zext i32 %21 to i64
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = zext i32 %25 to i64
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = zext i32 %27 to i64
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store double 1.000000e-04, ptr %11, align 8, !tbaa !11
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = zext i32 %29 to i64
  %31 = call ptr @llvm.stacksave.p0()
  store ptr %31, ptr %12, align 8
  %32 = alloca double, i64 %30, align 16
  store i64 %30, ptr %13, align 8
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = zext i32 %33 to i64
  %35 = alloca double, i64 %34, align 16
  store i64 %34, ptr %14, align 8
  %36 = load i32, ptr %5, align 4, !tbaa !5
  %37 = zext i32 %36 to i64
  %38 = alloca double, i64 %37, align 16
  store i64 %37, ptr %15, align 8
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = zext i32 %39 to i64
  %41 = alloca double, i64 %40, align 16
  store i64 %40, ptr %16, align 8
  %42 = getelementptr inbounds double, ptr %41, i64 0
  store double 1.000000e-01, ptr %42, align 16, !tbaa !11
  %43 = getelementptr inbounds double, ptr %41, i64 1
  store double 1.000000e-01, ptr %43, align 8, !tbaa !11
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = load ptr, ptr %6, align 8, !tbaa !9
  call void @Mat_mult_Vec(i32 noundef %44, i32 noundef %45, ptr noundef %46, ptr noundef %41, ptr noundef %38)
  %47 = load ptr, ptr %7, align 8, !tbaa !9
  call void @Vec_add_coefVec(i32 noundef 2, ptr noundef %38, double noundef -1.000000e+00, ptr noundef %47, ptr noundef %32)
  %48 = load i32, ptr %5, align 4, !tbaa !5
  call void @Vec_scale(i32 noundef %48, double noundef -1.000000e+00, ptr noundef %32, ptr noundef %32)
  %49 = load i32, ptr %5, align 4, !tbaa !5
  call void @Vec_scale(i32 noundef %49, double noundef -1.000000e+00, ptr noundef %32, ptr noundef %35)
  br label %50

50:                                               ; preds = %55, %4
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = call double @Vec_norm(i32 noundef %51, ptr noundef %32)
  %53 = load double, ptr %11, align 8, !tbaa !11
  %54 = fcmp ogt double %52, %53
  br i1 %54, label %55, label %90

55:                                               ; preds = %50
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = call double @Vec_sprod(i32 noundef %56, ptr noundef %32, ptr noundef %35)
  store double %57, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = load ptr, ptr %6, align 8, !tbaa !9
  %61 = call double @Vec_Mat_Vec(i32 noundef %58, i32 noundef %59, ptr noundef %35, ptr noundef %60, ptr noundef %35)
  store double %61, ptr %18, align 8, !tbaa !11
  %62 = load double, ptr %17, align 8, !tbaa !11
  %63 = load double, ptr %18, align 8, !tbaa !11
  %64 = fdiv double %62, %63
  store double %64, ptr %9, align 8, !tbaa !11
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = load double, ptr %9, align 8, !tbaa !11
  call void @Vec_add_coefVec(i32 noundef %65, ptr noundef %41, double noundef %66, ptr noundef %32, ptr noundef %41)
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = zext i32 %67 to i64
  %69 = call ptr @llvm.stacksave.p0()
  store ptr %69, ptr %19, align 8
  %70 = alloca double, i64 %68, align 16
  store i64 %68, ptr %20, align 8
  %71 = load i32, ptr %5, align 4, !tbaa !5
  call void @Vec_scale(i32 noundef %71, double noundef 1.000000e+00, ptr noundef %32, ptr noundef %70)
  %72 = load i32, ptr %5, align 4, !tbaa !5
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = load ptr, ptr %6, align 8, !tbaa !9
  call void @Mat_mult_Vec(i32 noundef %72, i32 noundef %73, ptr noundef %74, ptr noundef %41, ptr noundef %38)
  %75 = load i32, ptr %5, align 4, !tbaa !5
  %76 = load ptr, ptr %7, align 8, !tbaa !9
  call void @Vec_add_coefVec(i32 noundef %75, ptr noundef %38, double noundef -1.000000e+00, ptr noundef %76, ptr noundef %32)
  %77 = load i32, ptr %5, align 4, !tbaa !5
  call void @Vec_scale(i32 noundef %77, double noundef -1.000000e+00, ptr noundef %32, ptr noundef %32)
  %78 = load i32, ptr %5, align 4, !tbaa !5
  %79 = call double @Vec_norm(i32 noundef %78, ptr noundef %32)
  %80 = call double @pow(double noundef %79, double noundef 2.000000e+00) #4
  store double %80, ptr %17, align 8, !tbaa !11
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = call double @Vec_norm(i32 noundef %81, ptr noundef %70)
  %83 = call double @pow(double noundef %82, double noundef 2.000000e+00) #4
  store double %83, ptr %18, align 8, !tbaa !11
  %84 = load double, ptr %17, align 8, !tbaa !11
  %85 = load double, ptr %18, align 8, !tbaa !11
  %86 = fdiv double %84, %85
  store double %86, ptr %10, align 8, !tbaa !11
  %87 = load i32, ptr %5, align 4, !tbaa !5
  %88 = load double, ptr %10, align 8, !tbaa !11
  call void @Vec_add_coefVec(i32 noundef %87, ptr noundef %32, double noundef %88, ptr noundef %35, ptr noundef %35)
  %89 = load ptr, ptr %19, align 8
  call void @llvm.stackrestore.p0(ptr %89)
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  br label %50, !llvm.loop !13

90:                                               ; preds = %50
  %91 = load i32, ptr %5, align 4, !tbaa !5
  %92 = load ptr, ptr %8, align 8, !tbaa !9
  call void @Vec_scale(i32 noundef %91, double noundef 1.000000e+00, ptr noundef %41, ptr noundef %92)
  %93 = load ptr, ptr %12, align 8
  call void @llvm.stackrestore.p0(ptr %93)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret void
}

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


; 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 nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #0

; Function Attrs: nounwind uwtable
declare dso_local void @Vec_scale(i32 noundef, double noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @Vec_add_coefVec(i32 noundef, ptr noundef, double noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local double @Vec_norm(i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @Mat_mult_Vec(i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #0

; Function Attrs: nounwind uwtable
declare dso_local double @Vec_sprod(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local double @Vec_Mat_Vec(i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @Gradienti_Conjugati_Rez(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = zext i32 %0 to i64
  %6 = alloca double, i64 %5, align 16
  %7 = alloca double, i64 %5, align 16
  %8 = alloca double, i64 %5, align 16
  %9 = alloca double, i64 %5, align 16
  store <2 x double> <double 1.000000e-01, double 1.000000e-01>, ptr %9, align 16, !tbaa !5
  call void @Mat_mult_Vec(i32 noundef %0, i32 noundef %0, ptr noundef %1, ptr noundef nonnull %9, ptr noundef nonnull %8)
  call void @Vec_add_coefVec(i32 noundef 2, ptr noundef nonnull %8, double noundef -1.000000e+00, ptr noundef %2, ptr noundef nonnull %6)
  call void @Vec_scale(i32 noundef %0, double noundef -1.000000e+00, ptr noundef nonnull %6, ptr noundef nonnull %6)
  call void @Vec_scale(i32 noundef %0, double noundef -1.000000e+00, ptr noundef nonnull %6, ptr noundef nonnull %7)
  %10 = call double @Vec_norm(i32 noundef %0, ptr noundef nonnull %6)
  %11 = fcmp ogt double %10, 1.000000e-04
  br i1 %11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4, %.lr.ph
  %12 = call double @Vec_sprod(i32 noundef %0, ptr noundef nonnull %6, ptr noundef nonnull %7)
  %13 = call double @Vec_Mat_Vec(i32 noundef %0, i32 noundef %0, ptr noundef nonnull %7, ptr noundef %1, ptr noundef nonnull %7)
  %14 = fdiv double %12, %13
  call void @Vec_add_coefVec(i32 noundef %0, ptr noundef nonnull %9, double noundef %14, ptr noundef nonnull %6, ptr noundef nonnull %9)
  %15 = call ptr @llvm.stacksave.p0()
  %16 = alloca double, i64 %5, align 16
  call void @Vec_scale(i32 noundef %0, double noundef 1.000000e+00, ptr noundef nonnull %6, ptr noundef nonnull %16)
  call void @Mat_mult_Vec(i32 noundef %0, i32 noundef %0, ptr noundef %1, ptr noundef nonnull %9, ptr noundef nonnull %8)
  call void @Vec_add_coefVec(i32 noundef %0, ptr noundef nonnull %8, double noundef -1.000000e+00, ptr noundef %2, ptr noundef nonnull %6)
  call void @Vec_scale(i32 noundef %0, double noundef -1.000000e+00, ptr noundef nonnull %6, ptr noundef nonnull %6)
  %17 = call double @Vec_norm(i32 noundef %0, ptr noundef nonnull %6)
  %square = fmul double %17, %17
  %18 = call double @Vec_norm(i32 noundef %0, ptr noundef nonnull %16)
  %square41 = fmul double %18, %18
  %19 = fdiv double %square, %square41
  call void @Vec_add_coefVec(i32 noundef %0, ptr noundef nonnull %6, double noundef %19, ptr noundef nonnull %7, ptr noundef nonnull %7)
  call void @llvm.stackrestore.p0(ptr %15)
  %20 = call double @Vec_norm(i32 noundef %0, ptr noundef nonnull %6)
  %21 = fcmp ogt double %20, 1.000000e-04
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %4
  call void @Vec_scale(i32 noundef %0, double noundef 1.000000e+00, ptr noundef nonnull %9, ptr noundef %3)
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn }
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" }

!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,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass