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

; 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 nounwind uwtable
define dso_local noundef double @_ZNK7SGTELIB11TrainingSet9Z_unscaleEdi(ptr noundef nonnull align 8 dereferenceable(504) %0, double noundef %1, i32 noundef %2) #1 align 2 {
  %4 = alloca double, align 8
  %5 = alloca ptr, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store double %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  %9 = load ptr, ptr %5, align 8
  %10 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %9, i32 0, i32 36
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = load i32, ptr %7, align 4, !tbaa !11
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i32, ptr %11, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp eq i32 %15, 2
  br i1 %16, label %17, label %43

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store double 0.000000e+00, ptr %8, align 8, !tbaa !9
  %18 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %9, i32 0, i32 35
  %19 = load ptr, ptr %18, align 8, !tbaa !20
  %20 = load i32, ptr %7, align 4, !tbaa !11
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds double, ptr %19, i64 %21
  %23 = load double, ptr %22, align 8, !tbaa !9
  store double %23, ptr %8, align 8, !tbaa !9
  %24 = load double, ptr %6, align 8, !tbaa !9
  %25 = load double, ptr %8, align 8, !tbaa !9
  %26 = fcmp ogt double %24, %25
  br i1 %26, label %27, label %34

27:                                               ; preds = %17
  %28 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %9, i32 0, i32 29
  %29 = load ptr, ptr %28, align 8, !tbaa !21
  %30 = load i32, ptr %7, align 4, !tbaa !11
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds double, ptr %29, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !9
  br label %41

34:                                               ; preds = %17
  %35 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %9, i32 0, i32 28
  %36 = load ptr, ptr %35, align 8, !tbaa !22
  %37 = load i32, ptr %7, align 4, !tbaa !11
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %36, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !9
  br label %41

41:                                               ; preds = %34, %27
  %42 = phi double [ %33, %27 ], [ %40, %34 ]
  store double %42, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %59

43:                                               ; preds = %3
  %44 = load double, ptr %6, align 8, !tbaa !9
  %45 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %9, i32 0, i32 32
  %46 = load ptr, ptr %45, align 8, !tbaa !23
  %47 = load i32, ptr %7, align 4, !tbaa !11
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %46, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !9
  %51 = fsub double %44, %50
  %52 = getelementptr inbounds %"class.SGTELIB::TrainingSet", ptr %9, i32 0, i32 31
  %53 = load ptr, ptr %52, align 8, !tbaa !24
  %54 = load i32, ptr %7, align 4, !tbaa !11
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds double, ptr %53, i64 %55
  %57 = load double, ptr %56, align 8, !tbaa !9
  %58 = fdiv double %51, %57
  store double %58, ptr %4, align 8
  br label %59

59:                                               ; preds = %43, %41
  %60 = load double, ptr %4, align 8
  ret double %60
}

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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 488}
!14 = !{!"_ZTSN7SGTELIB11TrainingSetE", !12, i64 8, !12, i64 12, !12, i64 16, !15, i64 20, !6, i64 24, !15, i64 32, !12, i64 36, !10, i64 40, !10, i64 48, !12, i64 56, !16, i64 64, !16, i64 120, !16, i64 176, !16, i64 232, !16, i64 288, !12, i64 344, !12, i64 348, !12, i64 352, !6, i64 360, !6, i64 368, !6, i64 376, !6, i64 384, !6, i64 392, !6, i64 400, !6, i64 408, !12, i64 416, !12, 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, !10, i64 496}
!15 = !{!"bool", !7, i64 0}
!16 = !{!"_ZTSN7SGTELIB6MatrixE", !17, i64 8, !12, i64 40, !12, i64 44, !6, i64 48}
!17 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE", !18, i64 0, !19, i64 8, !7, i64 16}
!18 = !{!"_ZTSNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_Alloc_hiderE", !6, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = !{!14, !6, i64 480}
!21 = !{!14, !6, i64 432}
!22 = !{!14, !6, i64 424}
!23 = !{!14, !6, i64 456}
!24 = !{!14, !6, i64 448}


; 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 @_ZNK7SGTELIB11TrainingSet9Z_unscaleEdi(ptr nocapture noundef nonnull readonly align 8 dereferenceable(504) %0, double noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 488
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = sext i32 %2 to i64
  %7 = getelementptr inbounds i32, ptr %5, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !17
  %9 = icmp eq i32 %8, 2
  br i1 %9, label %10, label %17

10:                                               ; preds = %3
  %11 = getelementptr inbounds i8, ptr %0, i64 480
  %12 = load ptr, ptr %11, align 8, !tbaa !18
  %13 = getelementptr inbounds double, ptr %12, i64 %6
  %14 = load double, ptr %13, align 8, !tbaa !19
  %15 = fcmp olt double %14, %1
  %.pn.in.v = select i1 %15, i64 432, i64 424
  %.pn.in = getelementptr inbounds i8, ptr %0, i64 %.pn.in.v
  %.pn = load ptr, ptr %.pn.in, align 8, !tbaa !20
  %.in = getelementptr inbounds double, ptr %.pn, i64 %6
  %16 = load double, ptr %.in, align 8, !tbaa !19
  br label %28

17:                                               ; preds = %3
  %18 = getelementptr inbounds i8, ptr %0, i64 456
  %19 = load ptr, ptr %18, align 8, !tbaa !21
  %20 = getelementptr inbounds double, ptr %19, i64 %6
  %21 = load double, ptr %20, align 8, !tbaa !19
  %22 = fsub double %1, %21
  %23 = getelementptr inbounds i8, ptr %0, i64 448
  %24 = load ptr, ptr %23, align 8, !tbaa !22
  %25 = getelementptr inbounds double, ptr %24, i64 %6
  %26 = load double, ptr %25, align 8, !tbaa !19
  %27 = fdiv double %22, %26
  br label %28

28:                                               ; preds = %17, %10
  %.0 = phi double [ %16, %10 ], [ %27, %17 ]
  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, !11, i64 488}
!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 = !{!7, !7, i64 0}
!18 = !{!6, !11, i64 480}
!19 = !{!12, !12, i64 0}
!20 = !{!11, !11, i64 0}
!21 = !{!6, !11, i64 456}
!22 = !{!6, !11, i64 448}


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