; LLVM IR from softmin/ReHLine-SVM :: liblinear/linear.ll (ZN10l2r_lr_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 }
%struct.feature_node = type { i32, double }
%class.l2r_lr_fun = type { %class.l2r_erm_fun.base, ptr }
%class.l2r_erm_fun.base = type <{ %class.function, ptr, ptr, ptr, ptr, 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: 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 @_ZN10l2r_lr_fun23get_diag_preconditionerEPd(ptr noundef nonnull align 8 dereferenceable(64) %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 i32, align 4
  %8 = alloca ptr, align 8
  %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 = getelementptr inbounds %class.l2r_erm_fun, ptr %10, i32 0, i32 2
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.problem, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !14
  store i32 %14, ptr %6, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %15 = load ptr, ptr %10, align 8, !tbaa !17
  %16 = getelementptr inbounds ptr, ptr %15, i64 3
  %17 = load ptr, ptr %16, align 8
  %18 = call noundef i32 %17(ptr noundef nonnull align 8 dereferenceable(52) %10)
  store i32 %18, ptr %7, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %19 = getelementptr inbounds %class.l2r_erm_fun, ptr %10, i32 0, i32 2
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.problem, ptr %20, i32 0, i32 3
  %22 = load ptr, ptr %21, align 8, !tbaa !19
  store ptr %22, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !16
  br label %23

23:                                               ; preds = %32, %2
  %24 = load i32, ptr %5, align 4, !tbaa !16
  %25 = load i32, ptr %7, align 4, !tbaa !16
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %35

27:                                               ; preds = %23
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !16
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds double, ptr %28, i64 %30
  store double 1.000000e+00, ptr %31, align 8, !tbaa !20
  br label %32

32:                                               ; preds = %27
  %33 = load i32, ptr %5, align 4, !tbaa !16
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %5, align 4, !tbaa !16
  br label %23, !llvm.loop !21

35:                                               ; preds = %23
  %36 = getelementptr inbounds %class.l2r_erm_fun, ptr %10, i32 0, i32 6
  %37 = load i32, ptr %36, align 8, !tbaa !23
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %45

39:                                               ; preds = %35
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !16
  %42 = sub nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds double, ptr %40, i64 %43
  store double 0.000000e+00, ptr %44, align 8, !tbaa !20
  br label %45

45:                                               ; preds = %39, %35
  store i32 0, ptr %5, align 4, !tbaa !16
  br label %46

46:                                               ; preds = %94, %45
  %47 = load i32, ptr %5, align 4, !tbaa !16
  %48 = load i32, ptr %6, align 4, !tbaa !16
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %50, label %97

50:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = load i32, ptr %5, align 4, !tbaa !16
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds ptr, ptr %51, i64 %53
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  store ptr %55, ptr %9, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %61, %50
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.feature_node, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !24
  %60 = icmp ne i32 %59, -1
  br i1 %60, label %61, label %93

61:                                               ; preds = %56
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.feature_node, ptr %62, i32 0, i32 1
  %64 = load double, ptr %63, align 8, !tbaa !26
  %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 !26
  %68 = fmul double %64, %67
  %69 = getelementptr inbounds %class.l2r_erm_fun, ptr %10, i32 0, i32 1
  %70 = load ptr, ptr %69, align 8, !tbaa !27
  %71 = load i32, ptr %5, align 4, !tbaa !16
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds double, ptr %70, i64 %72
  %74 = load double, ptr %73, align 8, !tbaa !20
  %75 = fmul double %68, %74
  %76 = getelementptr inbounds %class.l2r_lr_fun, ptr %10, i32 0, i32 1
  %77 = load ptr, ptr %76, align 8, !tbaa !28
  %78 = load i32, ptr %5, align 4, !tbaa !16
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds double, ptr %77, i64 %79
  %81 = load double, ptr %80, align 8, !tbaa !20
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.feature_node, ptr %83, i32 0, i32 0
  %85 = load i32, ptr %84, align 8, !tbaa !24
  %86 = sub nsw i32 %85, 1
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds double, ptr %82, i64 %87
  %89 = load double, ptr %88, align 8, !tbaa !20
  %90 = call double @llvm.fmuladd.f64(double %75, double %81, double %89)
  store double %90, ptr %88, align 8, !tbaa !20
  %91 = load ptr, ptr %9, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.feature_node, ptr %91, i32 1
  store ptr %92, ptr %9, align 8, !tbaa !5
  br label %56, !llvm.loop !30

93:                                               ; preds = %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %5, align 4, !tbaa !16
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %5, align 4, !tbaa !16
  br label %46, !llvm.loop !31

97:                                               ; preds = %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, 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, !6, i64 16}
!10 = !{!"_ZTS11l2r_erm_fun", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !13, i64 48}
!11 = !{!"_ZTS8function"}
!12 = !{!"double", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 0}
!15 = !{!"_ZTS7problem", !13, i64 0, !13, i64 4, !6, i64 8, !6, i64 16, !12, i64 24}
!16 = !{!13, !13, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"vtable pointer", !8, i64 0}
!19 = !{!15, !6, i64 16}
!20 = !{!12, !12, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!10, !13, i64 48}
!24 = !{!25, !13, i64 0}
!25 = !{!"_ZTS12feature_node", !13, i64 0, !12, i64 8}
!26 = !{!25, !12, i64 8}
!27 = !{!10, !6, i64 8}
!28 = !{!29, !6, i64 56}
!29 = !{!"_ZTS10l2r_lr_fun", !10, i64 0, !6, i64 56}
!30 = distinct !{!30, !22}
!31 = distinct !{!31, !22}


; 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 @_ZN10l2r_lr_fun23get_diag_preconditionerEPd(ptr noundef nonnull align 8 dereferenceable(64) %0, ptr nocapture noundef %1) unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load i32, ptr %4, align 8, !tbaa !13
  %6 = load ptr, ptr %0, align 8, !tbaa !15
  %7 = getelementptr inbounds i8, ptr %6, i64 24
  %8 = load ptr, ptr %7, align 8
  %9 = tail call noundef i32 %8(ptr noundef nonnull align 8 dereferenceable(52) %0)
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !17
  %13 = icmp sgt i32 %9, 0
  br i1 %13, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %9 to i64
  %min.iters.check = icmp ult i32 %9, 4
  br i1 %min.iters.check, label %.lr.ph.preheader39, 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 ]
  %14 = getelementptr inbounds double, ptr %1, i64 %index
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  store <2 x double> <double 1.000000e+00, double 1.000000e+00>, ptr %14, align 8, !tbaa !18
  store <2 x double> <double 1.000000e+00, double 1.000000e+00>, ptr %15, align 8, !tbaa !18
  %index.next = add nuw i64 %index, 4
  %16 = icmp eq i64 %index.next, %n.vec
  br i1 %16, label %middle.block, label %vector.body, !llvm.loop !19

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.preheader39

.lr.ph.preheader39:                               ; 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.preheader39, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader39 ]
  %17 = getelementptr inbounds double, ptr %1, i64 %indvars.iv
  store double 1.000000e+00, ptr %17, align 8, !tbaa !18
  %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 !23

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

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

25:                                               ; preds = %21, %._crit_edge
  %26 = icmp sgt i32 %5, 0
  br i1 %26, label %.lr.ph31, label %._crit_edge32

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

31:                                               ; preds = %.lr.ph31, %._crit_edge28
  %indvars.iv34 = phi i64 [ 0, %.lr.ph31 ], [ %indvars.iv.next35, %._crit_edge28 ]
  %32 = getelementptr inbounds ptr, ptr %12, i64 %indvars.iv34
  %33 = load ptr, ptr %32, align 8, !tbaa !25
  %34 = load i32, ptr %33, align 8, !tbaa !26
  %.not24 = icmp eq i32 %34, -1
  br i1 %.not24, label %._crit_edge28, label %.lr.ph27

.lr.ph27:                                         ; preds = %31
  %35 = getelementptr inbounds double, ptr %28, i64 %indvars.iv34
  %36 = getelementptr inbounds double, ptr %30, i64 %indvars.iv34
  br label %37

37:                                               ; preds = %.lr.ph27, %37
  %38 = phi i32 [ %34, %.lr.ph27 ], [ %49, %37 ]
  %.025 = phi ptr [ %33, %.lr.ph27 ], [ %48, %37 ]
  %39 = getelementptr inbounds i8, ptr %.025, i64 8
  %40 = load double, ptr %39, align 8, !tbaa !28
  %41 = fmul double %40, %40
  %42 = load double, ptr %35, align 8, !tbaa !18
  %43 = fmul double %41, %42
  %44 = load double, ptr %36, align 8, !tbaa !18
  %45 = sext i32 %38 to i64
  %gep = getelementptr double, ptr %invariant.gep, i64 %45
  %46 = load double, ptr %gep, align 8, !tbaa !18
  %47 = tail call double @llvm.fmuladd.f64(double %43, double %44, double %46)
  store double %47, ptr %gep, align 8, !tbaa !18
  %48 = getelementptr inbounds i8, ptr %.025, i64 16
  %49 = load i32, ptr %48, align 8, !tbaa !26
  %.not = icmp eq i32 %49, -1
  br i1 %.not, label %._crit_edge28, label %37, !llvm.loop !29

._crit_edge28:                                    ; preds = %37, %31
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond38.not = icmp eq i64 %indvars.iv.next35, %wide.trip.count37
  br i1 %exitcond38.not, label %._crit_edge32, label %31, !llvm.loop !30

._crit_edge32:                                    ; preds = %._crit_edge28, %25
  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, !8, i64 16}
!6 = !{!"_ZTS11l2r_erm_fun", !7, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !8, i64 32, !11, i64 40, !12, i64 48}
!7 = !{!"_ZTS8function"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"double", !9, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTS7problem", !12, i64 0, !12, i64 4, !8, i64 8, !8, i64 16, !11, i64 24}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !10, i64 0}
!17 = !{!14, !8, i64 16}
!18 = !{!11, !11, i64 0}
!19 = distinct !{!19, !20, !21, !22}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!"llvm.loop.isvectorized", i32 1}
!22 = !{!"llvm.loop.unroll.runtime.disable"}
!23 = distinct !{!23, !20, !22, !21}
!24 = !{!6, !12, i64 48}
!25 = !{!8, !8, i64 0}
!26 = !{!27, !12, i64 0}
!27 = !{!"_ZTS12feature_node", !12, i64 0, !11, i64 8}
!28 = !{!27, !11, i64 8}
!29 = distinct !{!29, !20}
!30 = distinct !{!30, !20}


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