; LLVM IR from Samson-Mano/EM_Propogation_simulation :: EM_Propogation_simulation/src/ImGui (implot)

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

%struct.ImVec2 = type { float, float }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6ImVec2C2Eff(ptr noundef nonnull align 4 dereferenceable(8), float noundef, float noundef) unnamed_addr #1 align 2

; 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 float @llvm.fmuladd.f32(float, float, float) #2

declare noundef float @_ZN5ImGui17GetTextLineHeightEv() #3

declare <2 x float> @_ZN5ImGui12CalcTextSizeEPKcS1_bf(ptr noundef, ptr noundef, i1 noundef zeroext, float noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local <2 x float> @_ZN6ImPlot14CalcLegendSizeER15ImPlotItemGroupRK6ImVec2S4_b(ptr noundef nonnull align 8 dereferenceable(124) %0, ptr noundef nonnull align 4 dereferenceable(8) %1, ptr noundef nonnull align 4 dereferenceable(8) %2, i1 noundef zeroext %3) #4 {
  %5 = alloca %struct.ImVec2, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca float, align 4
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca float, align 4
  %18 = alloca %struct.ImVec2, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  %19 = zext i1 %3 to i8
  store i8 %19, ptr %9, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = call noundef i32 @_ZNK15ImPlotItemGroup14GetLegendCountEv(ptr noundef nonnull align 8 dereferenceable(124) %20)
  store i32 %21, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %22 = call noundef float @_ZN5ImGui17GetTextLineHeightEv()
  store float %22, ptr %11, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %23 = load float, ptr %11, align 4, !tbaa !13
  store float %23, ptr %12, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  store float 0.000000e+00, ptr %13, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  store float 0.000000e+00, ptr %14, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  store i32 0, ptr %15, align 4, !tbaa !11
  br label %24

24:                                               ; preds = %49, %4
  %25 = load i32, ptr %15, align 4, !tbaa !11
  %26 = load i32, ptr %10, align 4, !tbaa !11
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  br label %52

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #6
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load i32, ptr %15, align 4, !tbaa !11
  %32 = call noundef ptr @_ZN15ImPlotItemGroup14GetLegendLabelEi(ptr noundef nonnull align 8 dereferenceable(124) %30, i32 noundef %31)
  store ptr %32, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #6
  %33 = load ptr, ptr %16, align 8, !tbaa !5
  %34 = call <2 x float> @_ZN5ImGui12CalcTextSizeEPKcS1_bf(ptr noundef %33, ptr noundef null, i1 noundef zeroext true, float noundef -1.000000e+00)
  store <2 x float> %34, ptr %18, align 4
  %35 = getelementptr inbounds %struct.ImVec2, ptr %18, i32 0, i32 0
  %36 = load float, ptr %35, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  store float %36, ptr %17, align 4, !tbaa !13
  %37 = load float, ptr %17, align 4, !tbaa !13
  %38 = load float, ptr %13, align 4, !tbaa !13
  %39 = fcmp ogt float %37, %38
  br i1 %39, label %40, label %42

40:                                               ; preds = %29
  %41 = load float, ptr %17, align 4, !tbaa !13
  br label %44

42:                                               ; preds = %29
  %43 = load float, ptr %13, align 4, !tbaa !13
  br label %44

44:                                               ; preds = %42, %40
  %45 = phi float [ %41, %40 ], [ %43, %42 ]
  store float %45, ptr %13, align 4, !tbaa !13
  %46 = load float, ptr %17, align 4, !tbaa !13
  %47 = load float, ptr %14, align 4, !tbaa !13
  %48 = fadd float %47, %46
  store float %48, ptr %14, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  br label %49

49:                                               ; preds = %44
  %50 = load i32, ptr %15, align 4, !tbaa !11
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %15, align 4, !tbaa !11
  br label %24, !llvm.loop !17

52:                                               ; preds = %28
  %53 = load i8, ptr %9, align 1, !tbaa !9, !range !19, !noundef !20
  %54 = trunc i8 %53 to i1
  br i1 %54, label %55, label %78

55:                                               ; preds = %52
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ImVec2, ptr %56, i32 0, i32 0
  %58 = load float, ptr %57, align 4, !tbaa !15
  %59 = load float, ptr %12, align 4, !tbaa !13
  %60 = call float @llvm.fmuladd.f32(float %58, float 2.000000e+00, float %59)
  %61 = load float, ptr %13, align 4, !tbaa !13
  %62 = fadd float %60, %61
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.ImVec2, ptr %63, i32 0, i32 1
  %65 = load float, ptr %64, align 4, !tbaa !21
  %66 = load i32, ptr %10, align 4, !tbaa !11
  %67 = sitofp i32 %66 to float
  %68 = load float, ptr %11, align 4, !tbaa !13
  %69 = fmul float %67, %68
  %70 = call float @llvm.fmuladd.f32(float %65, float 2.000000e+00, float %69)
  %71 = load i32, ptr %10, align 4, !tbaa !11
  %72 = sub nsw i32 %71, 1
  %73 = sitofp i32 %72 to float
  %74 = load ptr, ptr %8, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.ImVec2, ptr %74, i32 0, i32 1
  %76 = load float, ptr %75, align 4, !tbaa !21
  %77 = call float @llvm.fmuladd.f32(float %73, float %76, float %70)
  call void @_ZN6ImVec2C2Eff(ptr noundef nonnull align 4 dereferenceable(8) %5, float noundef %62, float noundef %77)
  br label %101

78:                                               ; preds = %52
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.ImVec2, ptr %79, i32 0, i32 0
  %81 = load float, ptr %80, align 4, !tbaa !15
  %82 = load float, ptr %12, align 4, !tbaa !13
  %83 = load i32, ptr %10, align 4, !tbaa !11
  %84 = sitofp i32 %83 to float
  %85 = fmul float %82, %84
  %86 = call float @llvm.fmuladd.f32(float %81, float 2.000000e+00, float %85)
  %87 = load float, ptr %14, align 4, !tbaa !13
  %88 = fadd float %86, %87
  %89 = load i32, ptr %10, align 4, !tbaa !11
  %90 = sub nsw i32 %89, 1
  %91 = sitofp i32 %90 to float
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.ImVec2, ptr %92, i32 0, i32 0
  %94 = load float, ptr %93, align 4, !tbaa !15
  %95 = call float @llvm.fmuladd.f32(float %91, float %94, float %88)
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.ImVec2, ptr %96, i32 0, i32 1
  %98 = load float, ptr %97, align 4, !tbaa !21
  %99 = load float, ptr %11, align 4, !tbaa !13
  %100 = call float @llvm.fmuladd.f32(float %98, float 2.000000e+00, float %99)
  call void @_ZN6ImVec2C2Eff(ptr noundef nonnull align 4 dereferenceable(8) %5, float noundef %95, float noundef %100)
  br label %101

101:                                              ; preds = %78, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  %102 = load <2 x float>, ptr %5, align 4
  ret <2 x float> %102
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK15ImPlotItemGroup14GetLegendCountEv(ptr noundef nonnull align 8 dereferenceable(124)) #5 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN15ImPlotItemGroup14GetLegendLabelEi(ptr noundef nonnull align 8 dereferenceable(124), i32 noundef) #5 align 2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { "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 = { mustprogress uwtable "min-legal-vector-width"="64" "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 #5 = { 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 #6 = { 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 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!16, !14, i64 0}
!16 = !{!"_ZTS6ImVec2", !14, i64 0, !14, i64 4}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!16, !14, i64 4}


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

%struct.ImVec2 = type { float, float }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN6ImVec2C2Eff(ptr noundef nonnull align 4 dereferenceable(8), float noundef, float noundef) unnamed_addr #0 align 2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

declare noundef float @_ZN5ImGui17GetTextLineHeightEv() local_unnamed_addr #2

declare <2 x float> @_ZN5ImGui12CalcTextSizeEPKcS1_bf(ptr noundef, ptr noundef, i1 noundef zeroext, float noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local <2 x float> @_ZN6ImPlot14CalcLegendSizeER15ImPlotItemGroupRK6ImVec2S4_b(ptr noundef nonnull align 8 dereferenceable(124) %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(8) %1, ptr nocapture noundef nonnull readonly align 4 dereferenceable(8) %2, i1 noundef zeroext %3) local_unnamed_addr #3 {
  %5 = alloca %struct.ImVec2, align 8
  %6 = tail call noundef i32 @_ZNK15ImPlotItemGroup14GetLegendCountEv(ptr noundef nonnull align 8 dereferenceable(124) %0)
  %7 = tail call noundef float @_ZN5ImGui17GetTextLineHeightEv()
  %8 = icmp sgt i32 %6, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.030.lcssa = phi float [ 0.000000e+00, %4 ], [ %14, %.lr.ph ]
  %.0.lcssa = phi float [ 0.000000e+00, %4 ], [ %13, %.lr.ph ]
  %9 = load float, ptr %1, align 4, !tbaa !5
  br i1 %3, label %16, label %29

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.035 = phi float [ %13, %.lr.ph ], [ 0.000000e+00, %4 ]
  %.03034 = phi float [ %14, %.lr.ph ], [ 0.000000e+00, %4 ]
  %.03133 = phi i32 [ %15, %.lr.ph ], [ 0, %4 ]
  %10 = tail call noundef ptr @_ZN15ImPlotItemGroup14GetLegendLabelEi(ptr noundef nonnull align 8 dereferenceable(124) %0, i32 noundef %.03133)
  %11 = tail call <2 x float> @_ZN5ImGui12CalcTextSizeEPKcS1_bf(ptr noundef %10, ptr noundef null, i1 noundef zeroext true, float noundef -1.000000e+00)
  %.sroa.0.0.vec.extract = extractelement <2 x float> %11, i64 0
  %12 = fcmp ogt float %.sroa.0.0.vec.extract, %.035
  %13 = select i1 %12, float %.sroa.0.0.vec.extract, float %.035
  %14 = fadd float %.03034, %.sroa.0.0.vec.extract
  %15 = add nuw nsw i32 %.03133, 1
  %exitcond.not = icmp eq i32 %15, %6
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

16:                                               ; preds = %._crit_edge
  %17 = tail call float @llvm.fmuladd.f32(float %9, float 2.000000e+00, float %7)
  %18 = fadd float %.0.lcssa, %17
  %19 = getelementptr inbounds i8, ptr %1, i64 4
  %20 = load float, ptr %19, align 4, !tbaa !12
  %21 = sitofp i32 %6 to float
  %22 = fmul float %7, %21
  %23 = tail call float @llvm.fmuladd.f32(float %20, float 2.000000e+00, float %22)
  %24 = add nsw i32 %6, -1
  %25 = sitofp i32 %24 to float
  %26 = getelementptr inbounds i8, ptr %2, i64 4
  %27 = load float, ptr %26, align 4, !tbaa !12
  %28 = tail call float @llvm.fmuladd.f32(float %25, float %27, float %23)
  call void @_ZN6ImVec2C2Eff(ptr noundef nonnull align 4 dereferenceable(8) %5, float noundef %18, float noundef %28)
  br label %41

29:                                               ; preds = %._crit_edge
  %30 = sitofp i32 %6 to float
  %31 = fmul float %7, %30
  %32 = tail call float @llvm.fmuladd.f32(float %9, float 2.000000e+00, float %31)
  %33 = fadd float %.030.lcssa, %32
  %34 = add nsw i32 %6, -1
  %35 = sitofp i32 %34 to float
  %36 = load float, ptr %2, align 4, !tbaa !5
  %37 = tail call float @llvm.fmuladd.f32(float %35, float %36, float %33)
  %38 = getelementptr inbounds i8, ptr %1, i64 4
  %39 = load float, ptr %38, align 4, !tbaa !12
  %40 = tail call float @llvm.fmuladd.f32(float %39, float 2.000000e+00, float %7)
  call void @_ZN6ImVec2C2Eff(ptr noundef nonnull align 4 dereferenceable(8) %5, float noundef %37, float noundef %40)
  br label %41

41:                                               ; preds = %29, %16
  %42 = load <2 x float>, ptr %5, align 8
  ret <2 x float> %42
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK15ImPlotItemGroup14GetLegendCountEv(ptr noundef nonnull align 8 dereferenceable(124)) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_ZN15ImPlotItemGroup14GetLegendLabelEi(ptr noundef nonnull align 8 dereferenceable(124), i32 noundef) local_unnamed_addr #4 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { "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 uwtable "min-legal-vector-width"="64" "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 = { 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, !7, i64 0}
!6 = !{!"_ZTS6ImVec2", !7, i64 0, !7, i64 4}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!6, !7, i64 4}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass