; LLVM IR from softmin/ReHLine-SVM :: liblinear/linear.ll (ZN14l2r_l2_svc_fun23get_diag_preconditionerEPd)

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

%class.l2r_erm_fun = type <{ %class.function, ptr, ptr, ptr, ptr, double, i32, [4 x i8] }>
%class.function = type { ptr }
%struct.problem = type { i32, i32, ptr, ptr, double }
%class.l2r_l2_svc_fun = type <{ %class.l2r_erm_fun.base, [4 x i8], ptr, i32, [4 x i8] }>
%class.l2r_erm_fun.base = type <{ %class.function, ptr, ptr, ptr, ptr, double, i32 }>
%struct.feature_node = type { i32, double }

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14l2r_l2_svc_fun23get_diag_preconditionerEPd(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr noundef %1) unnamed_addr #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds ptr, ptr %11, i64 3
  %13 = load ptr, ptr %12, align 8
  %14 = call noundef i32 %13(ptr noundef nonnull align 8 dereferenceable(52) %10)
  store i32 %14, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %15 = getelementptr inbounds %class.l2r_erm_fun, ptr %10, i32 0, i32 2
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = getelementptr inbounds %struct.problem, ptr %16, i32 0, i32 3
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  store ptr %18, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %19

19:                                               ; preds = %28, %2
  %20 = load i32, ptr %5, align 4, !tbaa !11
  %21 = load i32, ptr %6, align 4, !tbaa !11
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %23, label %31

23:                                               ; preds = %19
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !11
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds double, ptr %24, i64 %26
  store double 1.000000e+00, ptr %27, align 8, !tbaa !19
  br label %28

28:                                               ; preds = %23
  %29 = load i32, ptr %5, align 4, !tbaa !11
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %5, align 4, !tbaa !11
  br label %19, !llvm.loop !20

31:                                               ; preds = %19
  %32 = getelementptr inbounds %class.l2r_erm_fun, ptr %10, i32 0, i32 6
  %33 = load i32, ptr %32, align 8, !tbaa !22
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %41

35:                                               ; preds = %31
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !11
  %38 = sub nsw i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds double, ptr %36, i64 %39
  store double 0.000000e+00, ptr %40, align 8, !tbaa !19
  br label %41

41:                                               ; preds = %35, %31
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %42

42:                                               ; preds = %91, %41
  %43 = load i32, ptr %5, align 4, !tbaa !11
  %44 = getelementptr inbounds %class.l2r_l2_svc_fun, ptr %10, i32 0, i32 3
  %45 = load i32, ptr %44, align 8, !tbaa !23
  %46 = icmp slt i32 %43, %45
  br i1 %46, label %47, label %94

47:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %48 = getelementptr inbounds %class.l2r_l2_svc_fun, ptr %10, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !25
  %50 = load i32, ptr %5, align 4, !tbaa !11
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr %49, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !11
  store i32 %53, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !11
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds ptr, ptr %54, i64 %56
  %58 = load ptr, ptr %57, align 8, !tbaa !5
  store ptr %58, ptr %9, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %64, %47
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.feature_node, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !26
  %63 = icmp ne i32 %62, -1
  br i1 %63, label %64, label %90

64:                                               ; preds = %59
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.feature_node, ptr %65, i32 0, i32 1
  %67 = load double, ptr %66, align 8, !tbaa !28
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.feature_node, ptr %68, i32 0, i32 1
  %70 = load double, ptr %69, align 8, !tbaa !28
  %71 = fmul double %67, %70
  %72 = getelementptr inbounds %class.l2r_erm_fun, ptr %10, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !29
  %74 = load i32, ptr %8, align 4, !tbaa !11
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds double, ptr %73, i64 %75
  %77 = load double, ptr %76, align 8, !tbaa !19
  %78 = fmul double %71, %77
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.feature_node, ptr %80, i32 0, i32 0
  %82 = load i32, ptr %81, align 8, !tbaa !26
  %83 = sub nsw i32 %82, 1
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds double, ptr %79, i64 %84
  %86 = load double, ptr %85, align 8, !tbaa !19
  %87 = call double @llvm.fmuladd.f64(double %78, double 2.000000e+00, double %86)
  store double %87, ptr %85, align 8, !tbaa !19
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.feature_node, ptr %88, i32 1
  store ptr %89, ptr %9, align 8, !tbaa !5
  br label %59, !llvm.loop !30

90:                                               ; preds = %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %5, align 4, !tbaa !11
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %5, align 4, !tbaa !11
  br label %42, !llvm.loop !31

94:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 16}
!14 = !{!"_ZTS11l2r_erm_fun", !15, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !16, i64 40, !12, i64 48}
!15 = !{!"_ZTS8function"}
!16 = !{!"double", !7, i64 0}
!17 = !{!18, !6, i64 16}
!18 = !{!"_ZTS7problem", !12, i64 0, !12, i64 4, !6, i64 8, !6, i64 16, !16, i64 24}
!19 = !{!16, !16, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!14, !12, i64 48}
!23 = !{!24, !12, i64 64}
!24 = !{!"_ZTS14l2r_l2_svc_fun", !14, i64 0, !6, i64 56, !12, i64 64}
!25 = !{!24, !6, i64 56}
!26 = !{!27, !12, i64 0}
!27 = !{!"_ZTS12feature_node", !12, i64 0, !16, i64 8}
!28 = !{!27, !16, i64 8}
!29 = !{!14, !6, i64 8}
!30 = distinct !{!30, !21}
!31 = distinct !{!31, !21}


; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14l2r_l2_svc_fun23get_diag_preconditionerEPd(ptr noundef nonnull align 8 dereferenceable(68) %0, ptr nocapture noundef %1) unnamed_addr #1 align 2 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 24
  %5 = load ptr, ptr %4, align 8
  %6 = tail call noundef i32 %5(ptr noundef nonnull align 8 dereferenceable(52) %0)
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !8
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %11 = icmp sgt i32 %6, 0
  br i1 %11, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %6 to i64
  %min.iters.check = icmp ult i32 %6, 4
  br i1 %min.iters.check, label %.lr.ph.preheader38, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %wide.trip.count, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %12 = getelementptr inbounds double, ptr %1, i64 %index
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  store <2 x double> <double 1.000000e+00, double 1.000000e+00>, ptr %12, align 8, !tbaa !17
  store <2 x double> <double 1.000000e+00, double 1.000000e+00>, ptr %13, align 8, !tbaa !17
  %index.next = add nuw i64 %index, 4
  %14 = icmp eq i64 %index.next, %n.vec
  br i1 %14, label %middle.block, label %vector.body, !llvm.loop !18

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader38

.lr.ph.preheader38:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader38, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader38 ]
  %15 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  store double 1.000000e+00, ptr %15, align 8, !tbaa !17
  %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, label %.lr.ph, !llvm.loop !22

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %2
  %16 = getelementptr inbounds i8, ptr %0, i64 48
  %17 = load i32, ptr %16, align 8, !tbaa !23
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %23

19:                                               ; preds = %._crit_edge
  %20 = sext i32 %6 to i64
  %21 = getelementptr double, ptr %1, i64 %20
  %22 = getelementptr i8, ptr %21, i64 -8
  store double 0.000000e+00, ptr %22, align 8, !tbaa !17
  br label %23

23:                                               ; preds = %19, %._crit_edge
  %24 = getelementptr inbounds i8, ptr %0, i64 64
  %25 = load i32, ptr %24, align 8, !tbaa !24
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.lr.ph30, label %._crit_edge31

.lr.ph30:                                         ; preds = %23
  %27 = getelementptr inbounds i8, ptr %0, i64 56
  %28 = load ptr, ptr %27, align 8, !tbaa !26
  %invariant.gep = getelementptr i8, ptr %1, i64 -8
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  %30 = load ptr, ptr %29, align 8
  %wide.trip.count36 = zext nneg i32 %25 to i64
  br label %31

31:                                               ; preds = %.lr.ph30, %._crit_edge27
  %indvars.iv33 = phi i64 [ 0, %.lr.ph30 ], [ %indvars.iv.next34, %._crit_edge27 ]
  %32 = getelementptr inbounds i32, ptr %28, i64 %indvars.iv33
  %33 = load i32, ptr %32, align 4, !tbaa !27
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds ptr, ptr %10, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !28
  %37 = load i32, ptr %36, align 8, !tbaa !29
  %.not23 = icmp eq i32 %37, -1
  br i1 %.not23, label %._crit_edge27, label %.lr.ph26

.lr.ph26:                                         ; preds = %31
  %38 = getelementptr inbounds double, ptr %30, i64 %34
  br label %39

39:                                               ; preds = %.lr.ph26, %39
  %40 = phi i32 [ %37, %.lr.ph26 ], [ %50, %39 ]
  %.024 = phi ptr [ %36, %.lr.ph26 ], [ %49, %39 ]
  %41 = getelementptr inbounds i8, ptr %.024, i64 8
  %42 = load double, ptr %41, align 8, !tbaa !31
  %43 = fmul double %42, %42
  %44 = load double, ptr %38, align 8, !tbaa !17
  %45 = fmul double %43, %44
  %46 = sext i32 %40 to i64
  %gep = getelementptr double, ptr %invariant.gep, i64 %46
  %47 = load double, ptr %gep, align 8, !tbaa !17
  %48 = tail call double @llvm.fmuladd.f64(double %45, double 2.000000e+00, double %47)
  store double %48, ptr %gep, align 8, !tbaa !17
  %49 = getelementptr inbounds i8, ptr %.024, i64 16
  %50 = load i32, ptr %49, align 8, !tbaa !29
  %.not = icmp eq i32 %50, -1
  br i1 %.not, label %._crit_edge27, label %39, !llvm.loop !32

._crit_edge27:                                    ; preds = %39, %31
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %exitcond37.not = icmp eq i64 %indvars.iv.next34, %wide.trip.count36
  br i1 %exitcond37.not, label %._crit_edge31, label %31, !llvm.loop !33

._crit_edge31:                                    ; preds = %._crit_edge27, %23
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !11, i64 16}
!9 = !{!"_ZTS11l2r_erm_fun", !10, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !13, i64 40, !14, i64 48}
!10 = !{!"_ZTS8function"}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !7, i64 0}
!13 = !{!"double", !12, i64 0}
!14 = !{!"int", !12, i64 0}
!15 = !{!16, !11, i64 16}
!16 = !{!"_ZTS7problem", !14, i64 0, !14, i64 4, !11, i64 8, !11, i64 16, !13, i64 24}
!17 = !{!13, !13, i64 0}
!18 = distinct !{!18, !19, !20, !21}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!"llvm.loop.isvectorized", i32 1}
!21 = !{!"llvm.loop.unroll.runtime.disable"}
!22 = distinct !{!22, !19, !21, !20}
!23 = !{!9, !14, i64 48}
!24 = !{!25, !14, i64 64}
!25 = !{!"_ZTS14l2r_l2_svc_fun", !9, i64 0, !11, i64 56, !14, i64 64}
!26 = !{!25, !11, i64 56}
!27 = !{!14, !14, i64 0}
!28 = !{!11, !11, i64 0}
!29 = !{!30, !14, i64 0}
!30 = !{!"_ZTS12feature_node", !14, i64 0, !13, i64 8}
!31 = !{!30, !13, i64 8}
!32 = distinct !{!32, !19}
!33 = distinct !{!33, !19}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass