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

; 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.8 = external hidden unnamed_addr constant [11 x i8], align 1
@logfile3 = external dso_local global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [10 x i8], align 1

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #0

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #0

; Function Attrs: nounwind uwtable
declare dso_local void @print(double noundef) #1

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

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

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

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

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @Gradienti_conjugati_nepatr(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, double noundef %4, ptr noundef %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca double, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca double, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca double, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i64, align 8
  store i32 %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !9
  store double %4, ptr %11, align 8, !tbaa !11
  store ptr %5, ptr %12, align 8, !tbaa !9
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = zext i32 %22 to i64
  %24 = load ptr, ptr @logfile3, align 8, !tbaa !9
  %25 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %24, ptr noundef @.str.8) #5
  %26 = load i32, ptr %7, align 4, !tbaa !5
  %27 = zext i32 %26 to i64
  %28 = call ptr @llvm.stacksave.p0()
  store ptr %28, ptr %13, align 8
  %29 = alloca double, i64 %27, align 16
  store i64 %27, ptr %14, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = zext i32 %30 to i64
  %32 = alloca double, i64 %31, align 16
  store i64 %31, ptr %16, align 8
  %33 = load ptr, ptr %9, align 8, !tbaa !9
  %34 = load ptr, ptr %12, align 8, !tbaa !9
  %35 = getelementptr inbounds double, ptr %34, i64 0
  %36 = load double, ptr %35, align 8, !tbaa !11
  %37 = load ptr, ptr %12, align 8, !tbaa !9
  %38 = getelementptr inbounds double, ptr %37, i64 1
  %39 = load double, ptr %38, align 8, !tbaa !11
  %40 = call double %33(double noundef %36, double noundef %39)
  %41 = getelementptr inbounds double, ptr %32, i64 0
  store double %40, ptr %41, align 16, !tbaa !11
  %42 = load ptr, ptr %10, align 8, !tbaa !9
  %43 = load ptr, ptr %12, align 8, !tbaa !9
  %44 = getelementptr inbounds double, ptr %43, i64 0
  %45 = load double, ptr %44, align 8, !tbaa !11
  %46 = load ptr, ptr %12, align 8, !tbaa !9
  %47 = getelementptr inbounds double, ptr %46, i64 1
  %48 = load double, ptr %47, align 8, !tbaa !11
  %49 = call double %42(double noundef %45, double noundef %48)
  %50 = getelementptr inbounds double, ptr %32, i64 1
  store double %49, ptr %50, align 8, !tbaa !11
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = zext i32 %51 to i64
  %53 = alloca double, i64 %52, align 16
  store i64 %52, ptr %17, align 8
  %54 = load i32, ptr %7, align 4, !tbaa !5
  call void @Vec_copy(i32 noundef %54, ptr noundef %32, ptr noundef %53)
  %55 = load i32, ptr %7, align 4, !tbaa !5
  call void @Vec_negat(i32 noundef %55, ptr noundef %53)
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  store i32 0, ptr %18, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %112, %6
  %57 = load i32, ptr %18, align 4, !tbaa !5
  %58 = icmp slt i32 %57, 100
  br i1 %58, label %60, label %59

59:                                               ; preds = %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  br label %115

60:                                               ; preds = %56
  %61 = load i32, ptr %18, align 4, !tbaa !5
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, i32 noundef %61)
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  %63 = load i32, ptr %7, align 4, !tbaa !5
  %64 = load ptr, ptr %8, align 8, !tbaa !9
  %65 = load ptr, ptr %12, align 8, !tbaa !9
  %66 = load double, ptr %11, align 8, !tbaa !11
  %67 = call double @goldsearch(i32 noundef %63, ptr noundef %64, ptr noundef %53, ptr noundef %65, double noundef %66, ptr noundef %29)
  store double %67, ptr %19, align 8, !tbaa !11
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  %69 = load double, ptr %19, align 8, !tbaa !11
  call void @print(double noundef %69)
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = load double, ptr %19, align 8, !tbaa !11
  %72 = load ptr, ptr %12, align 8, !tbaa !9
  %73 = load ptr, ptr %12, align 8, !tbaa !9
  call void @Vec_add_coefVec(i32 noundef %70, double noundef %71, ptr noundef %72, ptr noundef %53, ptr noundef %73)
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = load ptr, ptr %12, align 8, !tbaa !9
  call void @printVec(i32 noundef %74, ptr noundef %75)
  %76 = load ptr, ptr @logfile3, align 8, !tbaa !9
  %77 = load ptr, ptr %12, align 8, !tbaa !9
  call void @fprint(ptr noundef %76, ptr noundef %77)
  %78 = load i32, ptr %7, align 4, !tbaa !5
  %79 = zext i32 %78 to i64
  %80 = call ptr @llvm.stacksave.p0()
  store ptr %80, ptr %20, align 8
  %81 = alloca double, i64 %79, align 16
  store i64 %79, ptr %21, align 8
  %82 = load i32, ptr %7, align 4, !tbaa !5
  call void @Vec_copy(i32 noundef %82, ptr noundef %32, ptr noundef %81)
  %83 = load ptr, ptr %9, align 8, !tbaa !9
  %84 = load ptr, ptr %12, align 8, !tbaa !9
  %85 = getelementptr inbounds double, ptr %84, i64 0
  %86 = load double, ptr %85, align 8, !tbaa !11
  %87 = load ptr, ptr %12, align 8, !tbaa !9
  %88 = getelementptr inbounds double, ptr %87, i64 1
  %89 = load double, ptr %88, align 8, !tbaa !11
  %90 = call double %83(double noundef %86, double noundef %89)
  %91 = getelementptr inbounds double, ptr %32, i64 0
  store double %90, ptr %91, align 16, !tbaa !11
  %92 = load ptr, ptr %10, align 8, !tbaa !9
  %93 = load ptr, ptr %12, align 8, !tbaa !9
  %94 = getelementptr inbounds double, ptr %93, i64 0
  %95 = load double, ptr %94, align 8, !tbaa !11
  %96 = load ptr, ptr %12, align 8, !tbaa !9
  %97 = getelementptr inbounds double, ptr %96, i64 1
  %98 = load double, ptr %97, align 8, !tbaa !11
  %99 = call double %92(double noundef %95, double noundef %98)
  %100 = getelementptr inbounds double, ptr %32, i64 1
  store double %99, ptr %100, align 8, !tbaa !11
  %101 = load i32, ptr %7, align 4, !tbaa !5
  %102 = call double @Vec_norm(i32 noundef %101, ptr noundef %32)
  %103 = call double @pow(double noundef %102, double noundef 2.000000e+00) #5
  %104 = load i32, ptr %7, align 4, !tbaa !5
  %105 = call double @Vec_norm(i32 noundef %104, ptr noundef %81)
  %106 = call double @pow(double noundef %105, double noundef 2.000000e+00) #5
  %107 = fdiv double %103, %106
  store double %107, ptr %15, align 8, !tbaa !11
  %108 = load i32, ptr %7, align 4, !tbaa !5
  call void @Vec_negat(i32 noundef %108, ptr noundef %32)
  %109 = load i32, ptr %7, align 4, !tbaa !5
  %110 = load double, ptr %15, align 8, !tbaa !11
  call void @Vec_add_coefVec(i32 noundef %109, double noundef %110, ptr noundef %32, ptr noundef %53, ptr noundef %53)
  %111 = load ptr, ptr %20, align 8
  call void @llvm.stackrestore.p0(ptr %111)
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  br label %112

112:                                              ; preds = %60
  %113 = load i32, ptr %18, align 4, !tbaa !5
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %18, align 4, !tbaa !5
  br label %56, !llvm.loop !13

115:                                              ; preds = %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  %116 = load ptr, ptr %13, align 8
  call void @llvm.stackrestore.p0(ptr %116)
  ret void
}

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

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 = { 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 = { "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 #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nocallback nofree nosync nounwind willreturn }
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 = !{!"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"

@.str.8 = external hidden unnamed_addr constant [11 x i8], align 1
@logfile3 = external dso_local local_unnamed_addr global ptr, align 8
@.str.9 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [10 x i8], align 1

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

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

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

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

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

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @Gradienti_conjugati_nepatr(i32 noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly %3, double noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = load ptr, ptr @logfile3, align 8, !tbaa !5
  %8 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %7, ptr noundef nonnull @.str.8) #3
  %9 = zext i32 %0 to i64
  %10 = alloca double, i64 %9, align 16
  %11 = alloca double, i64 %9, align 16
  %12 = load double, ptr %5, align 8, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %5, i64 8
  %14 = load double, ptr %13, align 8, !tbaa !9
  %15 = tail call double %2(double noundef %12, double noundef %14) #3
  store double %15, ptr %11, align 16, !tbaa !9
  %16 = load double, ptr %5, align 8, !tbaa !9
  %17 = load double, ptr %13, align 8, !tbaa !9
  %18 = tail call double %3(double noundef %16, double noundef %17) #3
  %19 = getelementptr inbounds i8, ptr %11, i64 8
  store double %18, ptr %19, align 8, !tbaa !9
  %20 = alloca double, i64 %9, align 16
  call void @Vec_copy(i32 noundef %0, ptr noundef nonnull %11, ptr noundef nonnull %20)
  call void @Vec_negat(i32 noundef %0, ptr noundef nonnull %20)
  br label %22

21:                                               ; preds = %22
  ret void

22:                                               ; preds = %6, %22
  %.042 = phi i32 [ 0, %6 ], [ %38, %22 ]
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, i32 noundef %.042)
  %24 = call double @goldsearch(i32 noundef %0, ptr noundef %1, ptr noundef nonnull %20, ptr noundef nonnull %5, double noundef %4, ptr noundef nonnull %10)
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  call void @print(double noundef %24)
  call void @Vec_add_coefVec(i32 noundef %0, double noundef %24, ptr noundef nonnull %5, ptr noundef nonnull %20, ptr noundef nonnull %5)
  call void @printVec(i32 noundef %0, ptr noundef nonnull %5)
  %26 = load ptr, ptr @logfile3, align 8, !tbaa !5
  call void @fprint(ptr noundef %26, ptr noundef nonnull %5)
  %27 = call ptr @llvm.stacksave.p0()
  %28 = alloca double, i64 %9, align 16
  call void @Vec_copy(i32 noundef %0, ptr noundef nonnull %11, ptr noundef nonnull %28)
  %29 = load double, ptr %5, align 8, !tbaa !9
  %30 = load double, ptr %13, align 8, !tbaa !9
  %31 = call double %2(double noundef %29, double noundef %30) #3
  store double %31, ptr %11, align 16, !tbaa !9
  %32 = load double, ptr %5, align 8, !tbaa !9
  %33 = load double, ptr %13, align 8, !tbaa !9
  %34 = call double %3(double noundef %32, double noundef %33) #3
  store double %34, ptr %19, align 8, !tbaa !9
  %35 = call double @Vec_norm(i32 noundef %0, ptr noundef nonnull %11)
  %square = fmul double %35, %35
  %36 = call double @Vec_norm(i32 noundef %0, ptr noundef nonnull %28)
  %square41 = fmul double %36, %36
  %37 = fdiv double %square, %square41
  call void @Vec_negat(i32 noundef %0, ptr noundef nonnull %11)
  call void @Vec_add_coefVec(i32 noundef %0, double noundef %37, ptr noundef nonnull %11, ptr noundef nonnull %20, ptr noundef nonnull %20)
  call void @llvm.stackrestore.p0(ptr %27)
  %38 = add nuw nsw i32 %.042, 1
  %exitcond.not = icmp eq i32 %38, 100
  br i1 %exitcond.not, label %21, label %22, !llvm.loop !11
}

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

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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn }
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 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass