; LLVM IR from NotManyIdeasDev/double-pendulum-sim :: double-pendulum-sim/Libraries/raygui-2.8/examples/text_box_selection (GuiTextBoxGetSelection)

; 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.GuiTextBoxState = type { i32, i32, i32, i32 }
%struct.Vector2 = type { float, float }

@guiTextBoxState = external hidden global %struct.GuiTextBoxState, align 4

; Function Attrs: nounwind uwtable
define dso_local <2 x float> @GuiTextBoxGetSelection() #0 {
  %1 = alloca %struct.Vector2, align 4
  %2 = load i32, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 3), align 4, !tbaa !5
  %3 = icmp eq i32 %2, -1
  br i1 %3, label %8, label %4

4:                                                ; preds = %0
  %5 = load i32, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 3), align 4, !tbaa !5
  %6 = load i32, ptr @guiTextBoxState, align 4, !tbaa !10
  %7 = icmp eq i32 %5, %6
  br i1 %7, label %8, label %11

8:                                                ; preds = %4, %0
  %9 = getelementptr inbounds %struct.Vector2, ptr %1, i32 0, i32 0
  store float 0.000000e+00, ptr %9, align 4, !tbaa !11
  %10 = getelementptr inbounds %struct.Vector2, ptr %1, i32 0, i32 1
  store float 0.000000e+00, ptr %10, align 4, !tbaa !14
  br label %34

11:                                               ; preds = %4
  %12 = load i32, ptr @guiTextBoxState, align 4, !tbaa !10
  %13 = load i32, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 3), align 4, !tbaa !5
  %14 = icmp sgt i32 %12, %13
  br i1 %14, label %15, label %24

15:                                               ; preds = %11
  %16 = getelementptr inbounds %struct.Vector2, ptr %1, i32 0, i32 0
  %17 = load i32, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 3), align 4, !tbaa !5
  %18 = sitofp i32 %17 to float
  store float %18, ptr %16, align 4, !tbaa !11
  %19 = getelementptr inbounds %struct.Vector2, ptr %1, i32 0, i32 1
  %20 = load i32, ptr @guiTextBoxState, align 4, !tbaa !10
  %21 = load i32, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 3), align 4, !tbaa !5
  %22 = sub nsw i32 %20, %21
  %23 = sitofp i32 %22 to float
  store float %23, ptr %19, align 4, !tbaa !14
  br label %34

24:                                               ; preds = %11
  br label %25

25:                                               ; preds = %24
  %26 = getelementptr inbounds %struct.Vector2, ptr %1, i32 0, i32 0
  %27 = load i32, ptr @guiTextBoxState, align 4, !tbaa !10
  %28 = sitofp i32 %27 to float
  store float %28, ptr %26, align 4, !tbaa !11
  %29 = getelementptr inbounds %struct.Vector2, ptr %1, i32 0, i32 1
  %30 = load i32, ptr getelementptr inbounds (%struct.GuiTextBoxState, ptr @guiTextBoxState, i32 0, i32 3), align 4, !tbaa !5
  %31 = load i32, ptr @guiTextBoxState, align 4, !tbaa !10
  %32 = sub nsw i32 %30, %31
  %33 = sitofp i32 %32 to float
  store float %33, ptr %29, align 4, !tbaa !14
  br label %34

34:                                               ; preds = %25, %15, %8
  %35 = load <2 x float>, ptr %1, align 4
  ret <2 x float> %35
}

attributes #0 = { nounwind 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, !7, i64 12}
!6 = !{!"GuiTextBoxState", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"Vector2", !13, i64 0, !13, i64 4}
!13 = !{!"float", !8, i64 0}
!14 = !{!12, !13, 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.GuiTextBoxState = type { i32, i32, i32, i32 }

@guiTextBoxState = external hidden local_unnamed_addr global %struct.GuiTextBoxState, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local <2 x float> @GuiTextBoxGetSelection() local_unnamed_addr #0 {
  %1 = load i32, ptr getelementptr inbounds (i8, ptr @guiTextBoxState, i64 12), align 4, !tbaa !5
  %2 = icmp eq i32 %1, -1
  br i1 %2, label %18, label %3

3:                                                ; preds = %0
  %4 = load i32, ptr @guiTextBoxState, align 4, !tbaa !10
  %5 = icmp eq i32 %1, %4
  br i1 %5, label %18, label %6

6:                                                ; preds = %3
  %7 = icmp sgt i32 %4, %1
  br i1 %7, label %8, label %13

8:                                                ; preds = %6
  %9 = sub nsw i32 %4, %1
  %10 = insertelement <2 x i32> poison, i32 %1, i64 0
  %11 = insertelement <2 x i32> %10, i32 %9, i64 1
  %12 = sitofp <2 x i32> %11 to <2 x float>
  br label %18

13:                                               ; preds = %6
  %14 = sub nsw i32 %1, %4
  %15 = insertelement <2 x i32> poison, i32 %4, i64 0
  %16 = insertelement <2 x i32> %15, i32 %14, i64 1
  %17 = sitofp <2 x i32> %16 to <2 x float>
  br label %18

18:                                               ; preds = %0, %3, %13, %8
  %.sroa.0.0 = phi <2 x float> [ %12, %8 ], [ %17, %13 ], [ zeroinitializer, %3 ], [ zeroinitializer, %0 ]
  ret <2 x float> %.sroa.0.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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, !7, i64 12}
!6 = !{!"GuiTextBoxState", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 0}


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