; LLVM IR from AlgoGenesis/C :: Machine_Learning_Algorithms/SVM (Program)

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

%struct.DataPoint = type { double, double, i32 }

; 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
declare dso_local double @dotProduct(ptr noundef, ptr noundef byval(%struct.DataPoint) align 8) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @trainSVM(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.DataPoint, align 8
  %11 = alloca double, align 8
  %12 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  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 %13

13:                                               ; preds = %86, %3
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 1000
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %89

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

18:                                               ; preds = %82, %17
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %85

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #4
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds %struct.DataPoint, ptr %24, i64 %26
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %27, i64 24, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %28 = getelementptr inbounds %struct.DataPoint, ptr %10, i32 0, i32 2
  %29 = load i32, ptr %28, align 8, !tbaa !14
  %30 = sitofp i32 %29 to double
  store double %30, ptr %11, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = call double @dotProduct(ptr noundef %31, ptr noundef byval(%struct.DataPoint) align 8 %10)
  store double %32, ptr %12, align 8, !tbaa !12
  %33 = load double, ptr %11, align 8, !tbaa !12
  %34 = load double, ptr %12, align 8, !tbaa !12
  %35 = fmul double %33, %34
  %36 = fcmp olt double %35, 1.000000e+00
  br i1 %36, label %37, label %64

37:                                               ; preds = %23
  %38 = load double, ptr %11, align 8, !tbaa !12
  %39 = getelementptr inbounds %struct.DataPoint, ptr %10, i32 0, i32 0
  %40 = load double, ptr %39, align 8, !tbaa !16
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds double, ptr %41, i64 0
  %43 = load double, ptr %42, align 8, !tbaa !12
  %44 = fmul double 2.000000e-02, %43
  %45 = fneg double %44
  %46 = call double @llvm.fmuladd.f64(double %38, double %40, double %45)
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds double, ptr %47, i64 0
  %49 = load double, ptr %48, align 8, !tbaa !12
  %50 = call double @llvm.fmuladd.f64(double 1.000000e-02, double %46, double %49)
  store double %50, ptr %48, align 8, !tbaa !12
  %51 = load double, ptr %11, align 8, !tbaa !12
  %52 = getelementptr inbounds %struct.DataPoint, ptr %10, i32 0, i32 1
  %53 = load double, ptr %52, align 8, !tbaa !17
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds double, ptr %54, i64 1
  %56 = load double, ptr %55, align 8, !tbaa !12
  %57 = fmul double 2.000000e-02, %56
  %58 = fneg double %57
  %59 = call double @llvm.fmuladd.f64(double %51, double %53, double %58)
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds double, ptr %60, i64 1
  %62 = load double, ptr %61, align 8, !tbaa !12
  %63 = call double @llvm.fmuladd.f64(double 1.000000e-02, double %59, double %62)
  store double %63, ptr %61, align 8, !tbaa !12
  br label %81

64:                                               ; preds = %23
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds double, ptr %65, i64 0
  %67 = load double, ptr %66, align 8, !tbaa !12
  %68 = fmul double -2.000000e-02, %67
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds double, ptr %69, i64 0
  %71 = load double, ptr %70, align 8, !tbaa !12
  %72 = call double @llvm.fmuladd.f64(double 1.000000e-02, double %68, double %71)
  store double %72, ptr %70, align 8, !tbaa !12
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = getelementptr inbounds double, ptr %73, i64 1
  %75 = load double, ptr %74, align 8, !tbaa !12
  %76 = fmul double -2.000000e-02, %75
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds double, ptr %77, i64 1
  %79 = load double, ptr %78, align 8, !tbaa !12
  %80 = call double @llvm.fmuladd.f64(double 1.000000e-02, double %76, double %79)
  store double %80, ptr %78, align 8, !tbaa !12
  br label %81

81:                                               ; preds = %64, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #4
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %9, align 4, !tbaa !9
  br label %18, !llvm.loop !18

85:                                               ; preds = %22
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %7, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %7, align 4, !tbaa !9
  br label %13, !llvm.loop !20

89:                                               ; preds = %16
  ret void
}

; 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) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{i64 0, i64 8, !12, i64 8, i64 8, !12, i64 16, i64 4, !9}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!15, !10, i64 16}
!15 = !{!"", !13, i64 0, !13, i64 8, !10, i64 16}
!16 = !{!15, !13, i64 0}
!17 = !{!15, !13, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


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

%struct.DataPoint = type { double, double, i32 }

; Function Attrs: nounwind uwtable
declare dso_local double @dotProduct(ptr noundef, ptr noundef byval(%struct.DataPoint) align 8) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @trainSVM(ptr nocapture noundef readonly %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %1, 0
  %5 = getelementptr inbounds i8, ptr %2, i64 8
  br i1 %4, label %.preheader.us.preheader, label %.split23.us

.preheader.us.preheader:                          ; preds = %3
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.021.us = phi i32 [ %29, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  br label %6

6:                                                ; preds = %.preheader.us, %28
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %28 ]
  %7 = getelementptr inbounds %struct.DataPoint, ptr %0, i64 %indvars.iv
  %.sroa.0.0.copyload = load double, ptr %7, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %7, i64 8
  %.sroa.4.0.copyload = load double, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %7, i64 16
  %.sroa.5.0.copyload = load i32, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !9
  %8 = sitofp i32 %.sroa.5.0.copyload to double
  %9 = tail call double @dotProduct(ptr noundef %2, ptr noundef nonnull byval(%struct.DataPoint) align 8 %7)
  %10 = fmul double %9, %8
  %11 = fcmp olt double %10, 1.000000e+00
  br i1 %11, label %19, label %12

12:                                               ; preds = %6
  %13 = load double, ptr %2, align 8, !tbaa !5
  %14 = fmul double %13, -2.000000e-02
  %15 = tail call double @llvm.fmuladd.f64(double %14, double 1.000000e-02, double %13)
  store double %15, ptr %2, align 8, !tbaa !5
  %16 = load double, ptr %5, align 8, !tbaa !5
  %17 = fmul double %16, -2.000000e-02
  %18 = tail call double @llvm.fmuladd.f64(double %17, double 1.000000e-02, double %16)
  br label %28

19:                                               ; preds = %6
  %20 = load double, ptr %2, align 8, !tbaa !5
  %21 = fmul double %20, -2.000000e-02
  %22 = tail call double @llvm.fmuladd.f64(double %8, double %.sroa.0.0.copyload, double %21)
  %23 = tail call double @llvm.fmuladd.f64(double %22, double 1.000000e-02, double %20)
  store double %23, ptr %2, align 8, !tbaa !5
  %24 = load double, ptr %5, align 8, !tbaa !5
  %25 = fmul double %24, -2.000000e-02
  %26 = tail call double @llvm.fmuladd.f64(double %8, double %.sroa.4.0.copyload, double %25)
  %27 = tail call double @llvm.fmuladd.f64(double %26, double 1.000000e-02, double %24)
  br label %28

28:                                               ; preds = %19, %12
  %storemerge = phi double [ %18, %12 ], [ %27, %19 ]
  store double %storemerge, ptr %5, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us, label %6, !llvm.loop !11

._crit_edge.us:                                   ; preds = %28
  %29 = add nuw nsw i32 %.021.us, 1
  %exitcond26.not = icmp eq i32 %29, 1000
  br i1 %exitcond26.not, label %.split23.us, label %.preheader.us, !llvm.loop !13

.split23.us:                                      ; preds = %._crit_edge.us, %3
  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 = { 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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass