; LLVM IR from buresjan/optim_lbm :: nomad/ext/sgtelib/src/TrainingSet.ll (ZN7SGTELIB11TrainingSet13compute_f_minEv)

; 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.SGTELIB::TrainingSet" = type { ptr, i32, i32, i32, i8, ptr, i8, i32, double, double, i32, %"class.SGTELIB::Matrix", %"class.SGTELIB::Matrix", %"class.SGTELIB::Matrix", %"class.SGTELIB::Matrix", %"class.SGTELIB::Matrix", i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, double }
%"class.SGTELIB::Matrix" = type { ptr, %"class.std::__cxx11::basic_string", i32, i32, ptr }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

; 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 uwtable
define dso_local void @_ZN7SGTELIB11TrainingSet13compute_f_minEv(ptr noundef nonnull align 8 dereferenceable(504) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca double, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %8 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #4
  %9 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %8, i32 0, i32 8
  store double 0x7FEFFFFFFFFFFFFF, ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %8, i32 0, i32 10
  store i32 0, ptr %10, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !19
  br label %11

11:                                               ; preds = %65, %1
  %12 = load i32, ptr %5, align 4, !tbaa !19
  %13 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %8, i32 0, i32 1
  %14 = load i32, ptr %13, align 8, !tbaa !20
  %15 = icmp slt i32 %12, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %11
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %68

17:                                               ; preds = %11
  %18 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %8, i32 0, i32 12
  %19 = load i32, ptr %5, align 4, !tbaa !19
  %20 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %8, i32 0, i32 7
  %21 = load i32, ptr %20, align 4, !tbaa !21
  %22 = call noundef double @_ZNK7SGTELIB6Matrix3getEii(ptr noundef nonnull align 8 dereferenceable(56) %18, i32 noundef %19, i32 noundef %21)
  store double %22, ptr %3, align 8, !tbaa !22
  %23 = load double, ptr %3, align 8, !tbaa !22
  %24 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %8, i32 0, i32 8
  %25 = load double, ptr %24, align 8, !tbaa !9
  %26 = fcmp olt double %23, %25
  br i1 %26, label %27, label %64

27:                                               ; preds = %17
  store i8 1, ptr %4, align 1, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !19
  br label %28

28:                                               ; preds = %51, %27
  %29 = load i32, ptr %7, align 4, !tbaa !19
  %30 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %8, i32 0, i32 3
  %31 = load i32, ptr %30, align 8, !tbaa !24
  %32 = icmp slt i32 %29, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %28
  store i32 5, ptr %6, align 4
  br label %54

34:                                               ; preds = %28
  %35 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %8, i32 0, i32 5
  %36 = load ptr, ptr %35, align 8, !tbaa !25
  %37 = load i32, ptr %7, align 4, !tbaa !19
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr %36, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !26
  %41 = icmp eq i32 %40, 1
  br i1 %41, label %42, label %50

42:                                               ; preds = %34
  %43 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %8, i32 0, i32 12
  %44 = load i32, ptr %5, align 4, !tbaa !19
  %45 = load i32, ptr %7, align 4, !tbaa !19
  %46 = call noundef double @_ZNK7SGTELIB6Matrix3getEii(ptr noundef nonnull align 8 dereferenceable(56) %43, i32 noundef %44, i32 noundef %45)
  %47 = fcmp ogt double %46, 0.000000e+00
  br i1 %47, label %48, label %49

48:                                               ; preds = %42
  store i8 0, ptr %4, align 1, !tbaa !23
  store i32 5, ptr %6, align 4
  br label %54

49:                                               ; preds = %42
  br label %50

50:                                               ; preds = %49, %34
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %7, align 4, !tbaa !19
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %7, align 4, !tbaa !19
  br label %28, !llvm.loop !28

54:                                               ; preds = %48, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %55

55:                                               ; preds = %54
  %56 = load i8, ptr %4, align 1, !tbaa !23, !range !30, !noundef !31
  %57 = trunc i8 %56 to i1
  br i1 %57, label %58, label %63

58:                                               ; preds = %55
  %59 = load double, ptr %3, align 8, !tbaa !22
  %60 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %8, i32 0, i32 8
  store double %59, ptr %60, align 8, !tbaa !9
  %61 = load i32, ptr %5, align 4, !tbaa !19
  %62 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %8, i32 0, i32 10
  store i32 %61, ptr %62, align 8, !tbaa !18
  br label %63

63:                                               ; preds = %58, %55
  br label %64

64:                                               ; preds = %63, %17
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %5, align 4, !tbaa !19
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %5, align 4, !tbaa !19
  br label %11, !llvm.loop !32

68:                                               ; preds = %16
  %69 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %8, i32 0, i32 8
  %70 = load double, ptr %69, align 8, !tbaa !9
  %71 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %8, i32 0, i32 7
  %72 = load i32, ptr %71, align 4, !tbaa !21
  %73 = call noundef double @_ZNK7SGTELIB11TrainingSet7Z_scaleEdi(ptr noundef nonnull align 8 dereferenceable(504) %8, double noundef %70, i32 noundef %72)
  %74 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %8, i32 0, i32 9
  store double %73, ptr %74, align 8, !tbaa !33
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK7SGTELIB6Matrix3getEii(ptr noundef nonnull align 8 dereferenceable(56), i32 noundef, i32 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK7SGTELIB11TrainingSet7Z_scaleEdi(ptr noundef nonnull align 8 dereferenceable(504), double noundef, i32 noundef) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { inlinehint 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 #3 = { 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 #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++ TBAA"}
!9 = !{!10, !13, i64 40}
!10 = !{!"_ZTSN7SGTELIB11TrainingSetE", !11, i64 8, !11, i64 12, !11, i64 16, !12, i64 20, !6, i64 24, !12, i64 32, !11, i64 36, !13, i64 40, !13, i64 48, !11, i64 56, !14, i64 64, !14, i64 120, !14, i64 176, !14, i64 232, !14, i64 288, !11, i64 344, !11, i64 348, !11, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !6, i64 392, !6, i64 400, !6, i64 408, !11, i64 416, !11, i64 420, !6, i64 424, !6, i64 432, !6, i64 440, !6, i64 448, !6, i64 456, !6, i64 464, !6, i64 472, !6, i64 480, !6, i64 488, !13, i64 496}
!11 = !{!"int", !7, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = !{!"_ZTSN7SGTELIB6MatrixE", !15, i64 8, !11, i64 40, !11, i64 44, !6, i64 48}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !16, i64 0, !17, i64 8, !7, i64 16}
!16 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!10, !11, i64 56}
!19 = !{!11, !11, i64 0}
!20 = !{!10, !11, i64 8}
!21 = !{!10, !11, i64 36}
!22 = !{!13, !13, i64 0}
!23 = !{!12, !12, i64 0}
!24 = !{!10, !11, i64 16}
!25 = !{!10, !6, i64 24}
!26 = !{!27, !27, i64 0}
!27 = !{!"_ZTSN7SGTELIB5bbo_tE", !7, i64 0}
!28 = distinct !{!28, !29}
!29 = !{!"llvm.loop.mustprogress"}
!30 = !{i8 0, i8 2}
!31 = !{}
!32 = distinct !{!32, !29}
!33 = !{!10, !13, i64 48}


; 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 nounwind uwtable
define dso_local void @_ZN7SGTELIB11TrainingSet13compute_f_minEv(ptr noundef nonnull align 8 dereferenceable(504) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 40
  store double 0x7FEFFFFFFFFFFFFF, ptr %2, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 0, ptr %3, align 8, !tbaa !17
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !18
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph18, label %._crit_edge

.lr.ph18:                                         ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 120
  %8 = getelementptr inbounds i8, ptr %0, i64 36
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  br label %16

._crit_edge.loopexit:                             ; preds = %.loopexit
  %.pre21 = load double, ptr %2, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %11 = phi double [ %.pre21, %._crit_edge.loopexit ], [ 0x7FEFFFFFFFFFFFFF, %1 ]
  %12 = getelementptr inbounds i8, ptr %0, i64 36
  %13 = load i32, ptr %12, align 4, !tbaa !19
  %14 = tail call noundef double @_ZNK7SGTELIB11TrainingSet7Z_scaleEdi(ptr noundef nonnull align 8 dereferenceable(504) %0, double noundef %11, i32 noundef %13)
  %15 = getelementptr inbounds i8, ptr %0, i64 48
  store double %14, ptr %15, align 8, !tbaa !20
  ret void

16:                                               ; preds = %.lr.ph18, %.loopexit
  %.01217 = phi i32 [ 0, %.lr.ph18 ], [ %34, %.loopexit ]
  %17 = load i32, ptr %8, align 4, !tbaa !19
  %18 = tail call noundef double @_ZNK7SGTELIB6Matrix3getEii(ptr noundef nonnull align 8 dereferenceable(56) %7, i32 noundef %.01217, i32 noundef %17)
  %19 = load double, ptr %2, align 8, !tbaa !5
  %20 = fcmp olt double %18, %19
  br i1 %20, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %16
  %21 = load i32, ptr %9, align 8, !tbaa !21
  %.not15 = icmp sgt i32 %21, 0
  br i1 %.not15, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.preheader, %31
  %22 = phi i32 [ %32, %31 ], [ %21, %.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %31 ], [ 0, %.preheader ]
  %23 = load ptr, ptr %10, align 8, !tbaa !22
  %24 = getelementptr inbounds i32, ptr %23, i64 %indvars.iv
  %25 = load i32, ptr %24, align 4, !tbaa !23
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %31

27:                                               ; preds = %.lr.ph
  %28 = trunc nuw nsw i64 %indvars.iv to i32
  %29 = tail call noundef double @_ZNK7SGTELIB6Matrix3getEii(ptr noundef nonnull align 8 dereferenceable(56) %7, i32 noundef %.01217, i32 noundef %28)
  %30 = fcmp ogt double %29, 0.000000e+00
  br i1 %30, label %.loopexit, label %._crit_edge20

._crit_edge20:                                    ; preds = %27
  %.pre = load i32, ptr %9, align 8, !tbaa !21
  br label %31

31:                                               ; preds = %._crit_edge20, %.lr.ph
  %32 = phi i32 [ %.pre, %._crit_edge20 ], [ %22, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %33 = sext i32 %32 to i64
  %.not = icmp slt i64 %indvars.iv.next, %33
  br i1 %.not, label %.lr.ph, label %.critedge, !llvm.loop !25

.critedge:                                        ; preds = %31, %.preheader
  store double %18, ptr %2, align 8, !tbaa !5
  store i32 %.01217, ptr %3, align 8, !tbaa !17
  br label %.loopexit

.loopexit:                                        ; preds = %27, %16, %.critedge
  %34 = add nuw nsw i32 %.01217, 1
  %35 = load i32, ptr %4, align 8, !tbaa !18
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %16, label %._crit_edge.loopexit, !llvm.loop !27
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK7SGTELIB6Matrix3getEii(ptr noundef nonnull align 8 dereferenceable(56), i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZNK7SGTELIB11TrainingSet7Z_scaleEdi(ptr noundef nonnull align 8 dereferenceable(504), double noundef, i32 noundef) local_unnamed_addr #0 align 2

attributes #0 = { 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 #1 = { inlinehint 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" }

!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, !12, i64 40}
!6 = !{!"_ZTSN7SGTELIB11TrainingSetE", !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 20, !11, i64 24, !10, i64 32, !7, i64 36, !12, i64 40, !12, i64 48, !7, i64 56, !13, i64 64, !13, i64 120, !13, i64 176, !13, i64 232, !13, i64 288, !7, i64 344, !7, i64 348, !7, i64 352, !11, i64 360, !11, i64 368, !11, i64 376, !11, i64 384, !11, i64 392, !11, i64 400, !11, i64 408, !7, i64 416, !7, i64 420, !11, i64 424, !11, i64 432, !11, i64 440, !11, i64 448, !11, i64 456, !11, i64 464, !11, i64 472, !11, i64 480, !11, i64 488, !12, i64 496}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = !{!"_ZTSN7SGTELIB6MatrixE", !14, i64 8, !7, i64 40, !7, i64 44, !11, i64 48}
!14 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !15, i64 0, !16, i64 8, !8, i64 16}
!15 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !11, i64 0}
!16 = !{!"long", !8, i64 0}
!17 = !{!6, !7, i64 56}
!18 = !{!6, !7, i64 8}
!19 = !{!6, !7, i64 36}
!20 = !{!6, !12, i64 48}
!21 = !{!6, !7, i64 16}
!22 = !{!6, !11, i64 24}
!23 = !{!24, !24, i64 0}
!24 = !{!"_ZTSN7SGTELIB5bbo_tE", !8, i64 0}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = distinct !{!27, !26}


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