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

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

@logfile1 = external dso_local global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [11 x i8], align 1

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

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

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

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

; 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 void @Vec_negat(i32 noundef, ptr noundef) #0

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

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @Cauchy(i32 noundef %0, ptr noundef %1, ptr noundef %2, double noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca double, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca double, align 8
  %15 = alloca double, align 8
  %16 = alloca double, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !9
  store double %3, ptr %9, align 8, !tbaa !11
  store ptr %4, ptr %10, align 8, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = zext i32 %20 to i64
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = zext i32 %22 to i64
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = zext i32 %24 to i64
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = zext i32 %26 to i64
  %28 = load ptr, ptr @logfile1, align 8, !tbaa !9
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %28, ptr noundef @.str.8) #4
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = zext i32 %30 to i64
  %32 = call ptr @llvm.stacksave.p0()
  store ptr %32, ptr %11, align 8
  %33 = alloca double, i64 %31, align 16
  store i64 %31, ptr %12, align 8
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = zext i32 %34 to i64
  %36 = alloca double, i64 %35, align 16
  store i64 %35, ptr %13, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  store i32 15, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  store i32 0, ptr %18, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %73, %5
  %38 = load i32, ptr %18, align 4, !tbaa !5
  %39 = load i32, ptr %17, align 4, !tbaa !5
  %40 = icmp slt i32 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  store i32 2, ptr %19, align 4
  br label %76

42:                                               ; preds = %37
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = load ptr, ptr %7, align 8, !tbaa !9
  %46 = load ptr, ptr %10, align 8, !tbaa !9
  call void @Mat_mult_Vec(i32 noundef %43, i32 noundef %44, ptr noundef %45, ptr noundef %46, ptr noundef %33)
  %47 = load ptr, ptr %8, align 8, !tbaa !9
  call void @Vec_add_coefVec(i32 noundef 2, double noundef -1.000000e+00, ptr noundef %33, ptr noundef %47, ptr noundef %36)
  %48 = load i32, ptr %6, align 4, !tbaa !5
  call void @Vec_negat(i32 noundef %48, ptr noundef %36)
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = call double @Vec_norm(i32 noundef %49, ptr noundef %36)
  %51 = load double, ptr %9, align 8, !tbaa !11
  %52 = fcmp olt double %50, %51
  br i1 %52, label %53, label %54

53:                                               ; preds = %42
  store i32 2, ptr %19, align 4
  br label %76

54:                                               ; preds = %42
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = load ptr, ptr %10, align 8, !tbaa !9
  call void @printVec(i32 noundef %55, ptr noundef %56)
  %57 = load ptr, ptr @logfile1, align 8, !tbaa !9
  %58 = load ptr, ptr %10, align 8, !tbaa !9
  call void @fprint(ptr noundef %57, ptr noundef %58)
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = call double @Vec_sprod(i32 noundef %59, ptr noundef %36, ptr noundef %36)
  store double %60, ptr %14, align 8, !tbaa !11
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !9
  %64 = call double @Vec_Mat_Vec(i32 noundef %61, i32 noundef %62, ptr noundef %36, ptr noundef %63, ptr noundef %36)
  %65 = fdiv double 1.000000e+00, %64
  store double %65, ptr %15, align 8, !tbaa !11
  %66 = load double, ptr %14, align 8, !tbaa !11
  %67 = load double, ptr %15, align 8, !tbaa !11
  %68 = fmul double %66, %67
  store double %68, ptr %16, align 8, !tbaa !11
  %69 = load i32, ptr %6, align 4, !tbaa !5
  %70 = load double, ptr %16, align 8, !tbaa !11
  %71 = load ptr, ptr %10, align 8, !tbaa !9
  %72 = load ptr, ptr %10, align 8, !tbaa !9
  call void @Vec_add_coefVec(i32 noundef %69, double noundef %70, ptr noundef %71, ptr noundef %36, ptr noundef %72)
  br label %73

73:                                               ; preds = %54
  %74 = load i32, ptr %18, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %18, align 4, !tbaa !5
  br label %37, !llvm.loop !13

76:                                               ; preds = %53, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  br label %77

77:                                               ; preds = %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %78 = load ptr, ptr %11, align 8
  call void @llvm.stackrestore.p0(ptr %78)
  ret void
}

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

@logfile1 = external dso_local local_unnamed_addr global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [11 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 @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 @Mat_mult_Vec(i32 noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @Cauchy(i32 noundef %0, ptr noundef %1, ptr noundef %2, double noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = load ptr, ptr @logfile1, align 8, !tbaa !5
  %7 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %6, ptr noundef nonnull @.str.8) #2
  %8 = zext i32 %0 to i64
  %9 = alloca double, i64 %8, align 16
  %10 = alloca double, i64 %8, align 16
  br label %11

11:                                               ; preds = %5, %14
  %.030 = phi i32 [ 0, %5 ], [ %20, %14 ]
  call void @Mat_mult_Vec(i32 noundef %0, i32 noundef %0, ptr noundef %1, ptr noundef %4, ptr noundef nonnull %9)
  call void @Vec_add_coefVec(i32 noundef 2, double noundef -1.000000e+00, ptr noundef nonnull %9, ptr noundef %2, ptr noundef nonnull %10)
  call void @Vec_negat(i32 noundef %0, ptr noundef nonnull %10)
  %12 = call double @Vec_norm(i32 noundef %0, ptr noundef nonnull %10)
  %13 = fcmp olt double %12, %3
  br i1 %13, label %21, label %14

14:                                               ; preds = %11
  call void @printVec(i32 noundef %0, ptr noundef %4)
  %15 = load ptr, ptr @logfile1, align 8, !tbaa !5
  call void @fprint(ptr noundef %15, ptr noundef %4)
  %16 = call double @Vec_sprod(i32 noundef %0, ptr noundef nonnull %10, ptr noundef nonnull %10)
  %17 = call double @Vec_Mat_Vec(i32 noundef %0, i32 noundef %0, ptr noundef nonnull %10, ptr noundef %1, ptr noundef nonnull %10)
  %18 = fdiv double 1.000000e+00, %17
  %19 = fmul double %16, %18
  call void @Vec_add_coefVec(i32 noundef %0, double noundef %19, ptr noundef %4, ptr noundef nonnull %10, ptr noundef %4)
  %20 = add nuw nsw i32 %.030, 1
  %exitcond.not = icmp eq i32 %20, 15
  br i1 %exitcond.not, label %21, label %11, !llvm.loop !9

21:                                               ; preds = %11, %14
  ret void
}

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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