; LLVM IR from xhub/reshop :: gui/external/imgui/imgui_draw.ll (ZN14ImTriangulator13BuildReflexesEv)

; 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.ImTriangulator = type { i32, ptr, %struct.ImTriangulatorNodeSpan, %struct.ImTriangulatorNodeSpan }
%struct.ImTriangulatorNodeSpan = type <{ ptr, i32, [4 x i8] }>
%struct.ImTriangulatorNode = type { i32, i32, %struct.ImVec2, ptr, ptr }
%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: 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 @_ZN14ImTriangulator13BuildReflexesEv(ptr noundef nonnull align 8 dereferenceable(48) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %6 = getelementptr inbounds %struct.ImTriangulator, ptr %5, i32 0, i32 1
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %8 = getelementptr inbounds %struct.ImTriangulator, ptr %5, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !13
  store i32 %9, ptr %4, align 4, !tbaa !14
  br label %10

10:                                               ; preds = %32, %1
  %11 = load i32, ptr %4, align 4, !tbaa !14
  %12 = icmp sge i32 %11, 0
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %38

14:                                               ; preds = %10
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %15, i32 0, i32 4
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %17, i32 0, i32 2
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %21, i32 0, i32 3
  %23 = load ptr, ptr %22, align 8, !tbaa !20
  %24 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %23, i32 0, i32 2
  %25 = call noundef zeroext i1 @_Z21ImTriangleIsClockwiseRK6ImVec2S1_S1_(ptr noundef nonnull align 4 dereferenceable(8) %18, ptr noundef nonnull align 4 dereferenceable(8) %20, ptr noundef nonnull align 4 dereferenceable(8) %24)
  br i1 %25, label %26, label %27

26:                                               ; preds = %14
  br label %32

27:                                               ; preds = %14
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %28, i32 0, i32 0
  store i32 2, ptr %29, align 8, !tbaa !21
  %30 = getelementptr inbounds %struct.ImTriangulator, ptr %5, i32 0, i32 3
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_ZN22ImTriangulatorNodeSpan9push_backEP18ImTriangulatorNode(ptr noundef nonnull align 8 dereferenceable(12) %30, ptr noundef %31)
  br label %32

32:                                               ; preds = %27, %26
  %33 = load i32, ptr %4, align 4, !tbaa !14
  %34 = add nsw i32 %33, -1
  store i32 %34, ptr %4, align 4, !tbaa !14
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %35, i32 0, i32 3
  %37 = load ptr, ptr %36, align 8, !tbaa !20
  store ptr %37, ptr %3, align 8, !tbaa !5
  br label %10, !llvm.loop !22

38:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z21ImTriangleIsClockwiseRK6ImVec2S1_S1_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN22ImTriangulatorNodeSpan9push_backEP18ImTriangulatorNode(ptr noundef nonnull align 8 dereferenceable(12), ptr 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, !6, i64 8}
!10 = !{!"_ZTS14ImTriangulator", !11, i64 0, !6, i64 8, !12, i64 16, !12, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS22ImTriangulatorNodeSpan", !6, i64 0, !11, i64 8}
!13 = !{!10, !11, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!16, !6, i64 24}
!16 = !{!"_ZTS18ImTriangulatorNode", !17, i64 0, !11, i64 4, !18, i64 8, !6, i64 16, !6, i64 24}
!17 = !{!"_ZTS22ImTriangulatorNodeType", !7, i64 0}
!18 = !{!"_ZTS6ImVec2", !19, i64 0, !19, i64 4}
!19 = !{!"float", !7, i64 0}
!20 = !{!16, !6, i64 16}
!21 = !{!16, !17, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; 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 @_ZN14ImTriangulator13BuildReflexesEv(ptr noundef nonnull align 8 dereferenceable(48) %0) local_unnamed_addr #0 align 2 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = icmp sgt i32 %2, -1
  br i1 %3, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  br label %6

._crit_edge:                                      ; preds = %16, %1
  ret void

6:                                                ; preds = %.lr.ph, %16
  %.0811.in = phi ptr [ %4, %.lr.ph ], [ %11, %16 ]
  %.010 = phi i32 [ %2, %.lr.ph ], [ %17, %16 ]
  %.0811 = load ptr, ptr %.0811.in, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %.0811, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = getelementptr inbounds i8, ptr %.0811, i64 8
  %11 = getelementptr inbounds i8, ptr %.0811, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !18
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = tail call noundef zeroext i1 @_Z21ImTriangleIsClockwiseRK6ImVec2S1_S1_(ptr noundef nonnull align 4 dereferenceable(8) %9, ptr noundef nonnull align 4 dereferenceable(8) %10, ptr noundef nonnull align 4 dereferenceable(8) %13)
  br i1 %14, label %16, label %15

15:                                               ; preds = %6
  store i32 2, ptr %.0811, align 8, !tbaa !19
  tail call void @_ZN22ImTriangulatorNodeSpan9push_backEP18ImTriangulatorNode(ptr noundef nonnull align 8 dereferenceable(12) %5, ptr noundef nonnull %.0811)
  br label %16

16:                                               ; preds = %6, %15
  %17 = add nsw i32 %.010, -1
  %18 = icmp sgt i32 %.010, 0
  br i1 %18, label %6, label %._crit_edge, !llvm.loop !20
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z21ImTriangleIsClockwiseRK6ImVec2S1_S1_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN22ImTriangulatorNodeSpan9push_backEP18ImTriangulatorNode(ptr noundef nonnull align 8 dereferenceable(12), ptr 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, !7, i64 0}
!6 = !{!"_ZTS14ImTriangulator", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTS22ImTriangulatorNodeSpan", !10, i64 0, !7, i64 8}
!12 = !{!10, !10, i64 0}
!13 = !{!14, !10, i64 24}
!14 = !{!"_ZTS18ImTriangulatorNode", !15, i64 0, !7, i64 4, !16, i64 8, !10, i64 16, !10, i64 24}
!15 = !{!"_ZTS22ImTriangulatorNodeType", !8, i64 0}
!16 = !{!"_ZTS6ImVec2", !17, i64 0, !17, i64 4}
!17 = !{!"float", !8, i64 0}
!18 = !{!14, !10, i64 16}
!19 = !{!14, !15, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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