; LLVM IR from DarrenSweeney/3D-Physics-Engine :: Physics Engine/Imgui/imgui.ll (ZN18ImGuiTextEditState18UpdateScrollOffsetEv)

; 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 }
%struct.ImGuiTextEditState = type <{ i32, [1024 x i16], [3073 x i8], [3 x i8], i64, float, float, %struct.STB_TexteditState, float, %struct.ImVec2, i8, [7 x i8], ptr, float, [4 x i8] }>
%struct.STB_TexteditState = type { i32, i32, i32, i8, i8, i8, i8, i8, i8, i8, i8, float, %struct.StbUndoState }
%struct.StbUndoState = type { [99 x %struct.StbUndoRecord], [999 x i16], i16, i16, i16, i16 }
%struct.StbUndoRecord = type { i32, i16, i16, i16 }

; 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: inlinehint mustprogress nounwind uwtable
declare hidden noundef float @_ZL5ImMaxff(float noundef, float noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN18ImGuiTextEditState18UpdateScrollOffsetEv(ptr noundef nonnull align 8 dereferenceable(8396) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca %struct.ImVec2, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %7 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %6, i32 0, i32 5
  %8 = load float, ptr %7, align 8, !tbaa !9
  %9 = fmul float %8, 2.500000e-01
  store float %9, ptr %3, align 4, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %10 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %6, i32 0, i32 12
  %11 = load ptr, ptr %10, align 8, !tbaa !20
  %12 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %6, i32 0, i32 13
  %13 = load float, ptr %12, align 8, !tbaa !21
  %14 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %6, i32 0, i32 1
  %15 = getelementptr inbounds [1024 x i16], ptr %14, i64 0, i64 0
  %16 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %6, i32 0, i32 1
  %17 = getelementptr inbounds [1024 x i16], ptr %16, i64 0, i64 0
  %18 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %6, i32 0, i32 7
  %19 = getelementptr inbounds %struct.STB_TexteditState, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !22
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i16, ptr %17, i64 %21
  %23 = call <2 x float> @_ZNK6ImFont13CalcTextSizeWEffPKtS1_PS1_(ptr noundef nonnull align 8 dereferenceable(120) %11, float noundef %13, float noundef 0x47EFFFFFE0000000, ptr noundef %15, ptr noundef %22, ptr noundef null)
  store <2 x float> %23, ptr %5, align 4
  %24 = getelementptr inbounds %struct.ImVec2, ptr %5, i32 0, i32 0
  %25 = load float, ptr %24, align 4, !tbaa !23
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  store float %25, ptr %4, align 4, !tbaa !19
  %26 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %6, i32 0, i32 6
  %27 = load float, ptr %26, align 4, !tbaa !24
  %28 = load float, ptr %4, align 4, !tbaa !19
  %29 = fcmp ogt float %27, %28
  br i1 %29, label %30, label %36

30:                                               ; preds = %1
  %31 = load float, ptr %4, align 4, !tbaa !19
  %32 = load float, ptr %3, align 4, !tbaa !19
  %33 = fsub float %31, %32
  %34 = call noundef float @_ZL5ImMaxff(float noundef 0.000000e+00, float noundef %33)
  %35 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %6, i32 0, i32 6
  store float %34, ptr %35, align 4, !tbaa !24
  br label %53

36:                                               ; preds = %1
  %37 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %6, i32 0, i32 6
  %38 = load float, ptr %37, align 4, !tbaa !24
  %39 = load float, ptr %4, align 4, !tbaa !19
  %40 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %6, i32 0, i32 5
  %41 = load float, ptr %40, align 8, !tbaa !9
  %42 = fsub float %39, %41
  %43 = fcmp olt float %38, %42
  br i1 %43, label %44, label %52

44:                                               ; preds = %36
  %45 = load float, ptr %4, align 4, !tbaa !19
  %46 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %6, i32 0, i32 5
  %47 = load float, ptr %46, align 8, !tbaa !9
  %48 = fsub float %45, %47
  %49 = load float, ptr %3, align 4, !tbaa !19
  %50 = fadd float %48, %49
  %51 = getelementptr inbounds %struct.ImGuiTextEditState, ptr %6, i32 0, i32 6
  store float %50, ptr %51, align 4, !tbaa !24
  br label %52

52:                                               ; preds = %44, %36
  br label %53

53:                                               ; preds = %52, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local <2 x float> @_ZNK6ImFont13CalcTextSizeWEffPKtS1_PS1_(ptr noundef nonnull align 8 dereferenceable(120), float noundef, float noundef, ptr noundef, ptr noundef, ptr noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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 #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, !13, i64 5136}
!10 = !{!"_ZTS18ImGuiTextEditState", !11, i64 0, !7, i64 4, !7, i64 2052, !12, i64 5128, !13, i64 5136, !13, i64 5140, !14, i64 5144, !13, i64 8364, !17, i64 8368, !18, i64 8376, !6, i64 8384, !13, i64 8392}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"float", !7, i64 0}
!14 = !{!"_ZTS17STB_TexteditState", !11, i64 0, !11, i64 4, !11, i64 8, !7, i64 12, !7, i64 13, !7, i64 14, !7, i64 15, !7, i64 16, !7, i64 17, !7, i64 18, !7, i64 19, !13, i64 20, !15, i64 24}
!15 = !{!"_ZTS12StbUndoState", !7, i64 0, !7, i64 1188, !16, i64 3186, !16, i64 3188, !16, i64 3190, !16, i64 3192}
!16 = !{!"short", !7, i64 0}
!17 = !{!"_ZTS6ImVec2", !13, i64 0, !13, i64 4}
!18 = !{!"bool", !7, i64 0}
!19 = !{!13, !13, i64 0}
!20 = !{!10, !6, i64 8384}
!21 = !{!10, !13, i64 8392}
!22 = !{!10, !11, i64 5144}
!23 = !{!17, !13, i64 0}
!24 = !{!10, !13, i64 5140}


; 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: inlinehint mustprogress nounwind uwtable
declare hidden noundef float @_ZL5ImMaxff(float noundef, float noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN18ImGuiTextEditState18UpdateScrollOffsetEv(ptr noundef nonnull align 8 dereferenceable(8396) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 5136
  %3 = load float, ptr %2, align 8, !tbaa !5
  %4 = fmul float %3, 2.500000e-01
  %5 = getelementptr inbounds i8, ptr %0, i64 8384
  %6 = load ptr, ptr %5, align 8, !tbaa !18
  %7 = getelementptr inbounds i8, ptr %0, i64 8392
  %8 = load float, ptr %7, align 8, !tbaa !19
  %9 = getelementptr inbounds i8, ptr %0, i64 4
  %10 = getelementptr inbounds i8, ptr %0, i64 5144
  %11 = load i32, ptr %10, align 8, !tbaa !20
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i16, ptr %9, i64 %12
  %14 = tail call <2 x float> @_ZNK6ImFont13CalcTextSizeWEffPKtS1_PS1_(ptr noundef nonnull align 8 dereferenceable(120) %6, float noundef %8, float noundef 0x47EFFFFFE0000000, ptr noundef nonnull %9, ptr noundef nonnull %13, ptr noundef null)
  %.sroa.0.0.vec.extract = extractelement <2 x float> %14, i64 0
  %15 = getelementptr inbounds i8, ptr %0, i64 5140
  %16 = load float, ptr %15, align 4, !tbaa !21
  %17 = fcmp ogt float %16, %.sroa.0.0.vec.extract
  br i1 %17, label %18, label %21

18:                                               ; preds = %1
  %19 = fsub float %.sroa.0.0.vec.extract, %4
  %20 = tail call noundef float @_ZL5ImMaxff(float noundef 0.000000e+00, float noundef %19)
  br label %.sink.split

21:                                               ; preds = %1
  %22 = load float, ptr %2, align 8, !tbaa !5
  %23 = fsub float %.sroa.0.0.vec.extract, %22
  %24 = fcmp olt float %16, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %21
  %26 = fadd float %4, %23
  br label %.sink.split

.sink.split:                                      ; preds = %18, %25
  %.sink = phi float [ %26, %25 ], [ %20, %18 ]
  store float %.sink, ptr %15, align 4, !tbaa !21
  br label %27

27:                                               ; preds = %.sink.split, %21
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local <2 x float> @_ZNK6ImFont13CalcTextSizeWEffPKtS1_PS1_(ptr noundef nonnull align 8 dereferenceable(120), float noundef, float noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1 align 2

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

!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 5136}
!6 = !{!"_ZTS18ImGuiTextEditState", !7, i64 0, !8, i64 4, !8, i64 2052, !10, i64 5128, !11, i64 5136, !11, i64 5140, !12, i64 5144, !11, i64 8364, !15, i64 8368, !16, i64 8376, !17, i64 8384, !11, i64 8392}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!"_ZTS17STB_TexteditState", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12, !8, i64 13, !8, i64 14, !8, i64 15, !8, i64 16, !8, i64 17, !8, i64 18, !8, i64 19, !11, i64 20, !13, i64 24}
!13 = !{!"_ZTS12StbUndoState", !8, i64 0, !8, i64 1188, !14, i64 3186, !14, i64 3188, !14, i64 3190, !14, i64 3192}
!14 = !{!"short", !8, i64 0}
!15 = !{!"_ZTS6ImVec2", !11, i64 0, !11, i64 4}
!16 = !{!"bool", !8, i64 0}
!17 = !{!"any pointer", !8, i64 0}
!18 = !{!6, !17, i64 8384}
!19 = !{!6, !11, i64 8392}
!20 = !{!6, !7, i64 5144}
!21 = !{!6, !11, i64 5140}


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