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

; 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_svr_fun = type { %class.l2r_l2_svc_fun.base, double }
%class.l2r_l2_svc_fun.base = type <{ %class.l2r_erm_fun.base, [4 x i8], ptr, i32 }>
%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: mustprogress nounwind uwtable
define dso_local noundef double @_ZN14l2r_l2_svr_fun12C_times_lossEid(ptr noundef nonnull align 8 dereferenceable(80) %0, i32 noundef %1, double noundef %2) unnamed_addr #1 align 2 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store double %2, ptr %7, align 8, !tbaa !11
  %10 = load ptr, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %11 = load double, ptr %7, align 8, !tbaa !11
  %12 = getelementptr inbounds %class.l2r_erm_fun, ptr %10, i32 0, i32 2
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds %struct.problem, ptr %13, i32 0, i32 2
  %15 = load ptr, ptr %14, align 8, !tbaa !16
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds double, ptr %15, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !11
  %20 = fsub double %11, %19
  store double %20, ptr %8, align 8, !tbaa !11
  %21 = load double, ptr %8, align 8, !tbaa !11
  %22 = getelementptr inbounds %class.l2r_l2_svr_fun, ptr %10, i32 0, i32 1
  %23 = load double, ptr %22, align 8, !tbaa !18
  %24 = fneg double %23
  %25 = fcmp olt double %21, %24
  br i1 %25, label %26, label %43

26:                                               ; preds = %3
  %27 = getelementptr inbounds %class.l2r_erm_fun, ptr %10, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !21
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds double, ptr %28, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !11
  %33 = load double, ptr %8, align 8, !tbaa !11
  %34 = getelementptr inbounds %class.l2r_l2_svr_fun, ptr %10, i32 0, i32 1
  %35 = load double, ptr %34, align 8, !tbaa !18
  %36 = fadd double %33, %35
  %37 = fmul double %32, %36
  %38 = load double, ptr %8, align 8, !tbaa !11
  %39 = getelementptr inbounds %class.l2r_l2_svr_fun, ptr %10, i32 0, i32 1
  %40 = load double, ptr %39, align 8, !tbaa !18
  %41 = fadd double %38, %40
  %42 = fmul double %37, %41
  store double %42, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %67

43:                                               ; preds = %3
  %44 = load double, ptr %8, align 8, !tbaa !11
  %45 = getelementptr inbounds %class.l2r_l2_svr_fun, ptr %10, i32 0, i32 1
  %46 = load double, ptr %45, align 8, !tbaa !18
  %47 = fcmp ogt double %44, %46
  br i1 %47, label %48, label %65

48:                                               ; preds = %43
  %49 = getelementptr inbounds %class.l2r_erm_fun, ptr %10, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !21
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds double, ptr %50, i64 %52
  %54 = load double, ptr %53, align 8, !tbaa !11
  %55 = load double, ptr %8, align 8, !tbaa !11
  %56 = getelementptr inbounds %class.l2r_l2_svr_fun, ptr %10, i32 0, i32 1
  %57 = load double, ptr %56, align 8, !tbaa !18
  %58 = fsub double %55, %57
  %59 = fmul double %54, %58
  %60 = load double, ptr %8, align 8, !tbaa !11
  %61 = getelementptr inbounds %class.l2r_l2_svr_fun, ptr %10, i32 0, i32 1
  %62 = load double, ptr %61, align 8, !tbaa !18
  %63 = fsub double %60, %62
  %64 = fmul double %59, %63
  store double %64, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %67

65:                                               ; preds = %43
  br label %66

66:                                               ; preds = %65
  store double 0.000000e+00, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %67

67:                                               ; preds = %66, %48, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %68 = load double, ptr %4, align 8
  ret double %68
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !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, !12, i64 40, !10, i64 48}
!15 = !{!"_ZTS8function"}
!16 = !{!17, !6, i64 8}
!17 = !{!"_ZTS7problem", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !12, i64 24}
!18 = !{!19, !12, i64 72}
!19 = !{!"_ZTS14l2r_l2_svr_fun", !20, i64 0, !12, i64 72}
!20 = !{!"_ZTS14l2r_l2_svc_fun", !14, i64 0, !6, i64 56, !10, i64 64}
!21 = !{!14, !6, i64 8}


; 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 nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef double @_ZN14l2r_l2_svr_fun12C_times_lossEid(ptr nocapture noundef nonnull readonly align 8 dereferenceable(80) %0, i32 noundef %1, double noundef %2) unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !13
  %8 = sext i32 %1 to i64
  %9 = getelementptr inbounds double, ptr %7, i64 %8
  %10 = load double, ptr %9, align 8, !tbaa !15
  %11 = fsub double %2, %10
  %12 = getelementptr inbounds i8, ptr %0, i64 72
  %13 = load double, ptr %12, align 8, !tbaa !16
  %14 = fneg double %13
  %15 = fcmp olt double %11, %14
  br i1 %15, label %16, label %24

16:                                               ; preds = %3
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load ptr, ptr %17, align 8, !tbaa !19
  %19 = getelementptr inbounds double, ptr %18, i64 %8
  %20 = load double, ptr %19, align 8, !tbaa !15
  %21 = fadd double %11, %13
  %22 = fmul double %21, %20
  %23 = fmul double %21, %22
  br label %34

24:                                               ; preds = %3
  %25 = fcmp ogt double %11, %13
  br i1 %25, label %26, label %34

26:                                               ; preds = %24
  %27 = getelementptr inbounds i8, ptr %0, i64 8
  %28 = load ptr, ptr %27, align 8, !tbaa !19
  %29 = getelementptr inbounds double, ptr %28, i64 %8
  %30 = load double, ptr %29, align 8, !tbaa !15
  %31 = fsub double %11, %13
  %32 = fmul double %31, %30
  %33 = fmul double %31, %32
  br label %34

34:                                               ; preds = %24, %26, %16
  %.0 = phi double [ %23, %16 ], [ %33, %26 ], [ 0.000000e+00, %24 ]
  ret double %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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, !8, i64 8}
!14 = !{!"_ZTS7problem", !12, i64 0, !12, i64 4, !8, i64 8, !8, i64 16, !11, i64 24}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !11, i64 72}
!17 = !{!"_ZTS14l2r_l2_svr_fun", !18, i64 0, !11, i64 72}
!18 = !{!"_ZTS14l2r_l2_svc_fun", !6, i64 0, !8, i64 56, !12, i64 64}
!19 = !{!6, !8, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass