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

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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 void @_ZN14ImTriangulator10BuildNodesEPK6ImVec2i(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1, i32 noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %62, %3
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = load i32, ptr %6, align 4, !tbaa !9
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %65

14:                                               ; preds = %9
  %15 = getelementptr inbounds %struct.ImTriangulator, ptr %8, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %16, i64 %18
  %20 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %19, i32 0, i32 0
  store i32 0, ptr %20, align 8, !tbaa !14
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = getelementptr inbounds %struct.ImTriangulator, ptr %8, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %23, i64 %25
  %27 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %26, i32 0, i32 1
  store i32 %21, ptr %27, align 4, !tbaa !19
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %struct.ImVec2, ptr %28, i64 %30
  %32 = getelementptr inbounds %struct.ImTriangulator, ptr %8, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %33, i64 %35
  %37 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %36, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %37, ptr align 4 %31, i64 8, i1 false), !tbaa.struct !20
  %38 = getelementptr inbounds %struct.ImTriangulator, ptr %8, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %39, i64 %41
  %43 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %42, i64 1
  %44 = getelementptr inbounds %struct.ImTriangulator, ptr %8, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %45, i64 %47
  %49 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %48, i32 0, i32 3
  store ptr %43, ptr %49, align 8, !tbaa !22
  %50 = getelementptr inbounds %struct.ImTriangulator, ptr %8, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !11
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %51, i64 %53
  %55 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %54, i64 -1
  %56 = getelementptr inbounds %struct.ImTriangulator, ptr %8, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %57, i64 %59
  %61 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %60, i32 0, i32 4
  store ptr %55, ptr %61, align 8, !tbaa !23
  br label %62

62:                                               ; preds = %14
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %7, align 4, !tbaa !9
  br label %9, !llvm.loop !24

65:                                               ; preds = %13
  %66 = getelementptr inbounds %struct.ImTriangulator, ptr %8, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !11
  %68 = load i32, ptr %6, align 4, !tbaa !9
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %67, i64 %69
  %71 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %70, i64 -1
  %72 = getelementptr inbounds %struct.ImTriangulator, ptr %8, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !11
  %74 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %73, i64 0
  %75 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %74, i32 0, i32 4
  store ptr %71, ptr %75, align 8, !tbaa !23
  %76 = getelementptr inbounds %struct.ImTriangulator, ptr %8, i32 0, i32 1
  %77 = load ptr, ptr %76, align 8, !tbaa !11
  %78 = getelementptr inbounds %struct.ImTriangulator, ptr %8, i32 0, i32 1
  %79 = load ptr, ptr %78, align 8, !tbaa !11
  %80 = load i32, ptr %6, align 4, !tbaa !9
  %81 = sub nsw i32 %80, 1
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %79, i64 %82
  %84 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %83, i32 0, i32 3
  store ptr %77, ptr %84, align 8, !tbaa !22
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS14ImTriangulator", !10, i64 0, !6, i64 8, !13, i64 16, !13, i64 32}
!13 = !{!"_ZTS22ImTriangulatorNodeSpan", !6, i64 0, !10, i64 8}
!14 = !{!15, !16, i64 0}
!15 = !{!"_ZTS18ImTriangulatorNode", !16, i64 0, !10, i64 4, !17, i64 8, !6, i64 16, !6, i64 24}
!16 = !{!"_ZTS22ImTriangulatorNodeType", !7, i64 0}
!17 = !{!"_ZTS6ImVec2", !18, i64 0, !18, i64 4}
!18 = !{!"float", !7, i64 0}
!19 = !{!15, !10, i64 4}
!20 = !{i64 0, i64 4, !21, i64 4, i64 4, !21}
!21 = !{!18, !18, i64 0}
!22 = !{!15, !6, i64 16}
!23 = !{!15, !6, i64 24}
!24 = distinct !{!24, !25}
!25 = !{!"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"

%struct.ImTriangulatorNode = type { i32, i32, %struct.ImVec2, ptr, ptr }
%struct.ImVec2 = type { float, float }

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN14ImTriangulator10BuildNodesEPK6ImVec2i(ptr nocapture noundef nonnull readonly align 8 dereferenceable(48) %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = icmp sgt i32 %2, 0
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  br i1 %4, label %.lr.ph, label %.._crit_edge_crit_edge

.._crit_edge_crit_edge:                           ; preds = %3
  %.pre18 = load ptr, ptr %5, align 8, !tbaa !5
  br label %._crit_edge

.lr.ph:                                           ; preds = %3
  %wide.trip.count = zext nneg i32 %2 to i64
  %.pre = load ptr, ptr %5, align 8, !tbaa !5
  br label %12

._crit_edge:                                      ; preds = %12, %.._crit_edge_crit_edge
  %6 = phi ptr [ %.pre18, %.._crit_edge_crit_edge ], [ %20, %12 ]
  %7 = sext i32 %2 to i64
  %8 = getelementptr %struct.ImTriangulatorNode, ptr %6, i64 %7
  %9 = getelementptr inbounds i8, ptr %8, i64 -32
  %10 = getelementptr inbounds i8, ptr %6, i64 24
  store ptr %9, ptr %10, align 8, !tbaa !12
  %11 = getelementptr i8, ptr %8, i64 -16
  store ptr %6, ptr %11, align 8, !tbaa !17
  ret void

12:                                               ; preds = %.lr.ph, %12
  %13 = phi ptr [ %.pre, %.lr.ph ], [ %20, %12 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %12 ]
  %14 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %13, i64 %indvars.iv
  store i32 0, ptr %14, align 8, !tbaa !18
  %15 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %13, i64 %indvars.iv, i32 1
  %16 = trunc nuw nsw i64 %indvars.iv to i32
  store i32 %16, ptr %15, align 4, !tbaa !19
  %17 = getelementptr inbounds %struct.ImVec2, ptr %1, i64 %indvars.iv
  %18 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %13, i64 %indvars.iv, i32 2
  %19 = load i64, ptr %17, align 4
  store i64 %19, ptr %18, align 8
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %20, i64 %indvars.iv
  %22 = getelementptr inbounds i8, ptr %21, i64 32
  %23 = getelementptr inbounds i8, ptr %21, i64 16
  store ptr %22, ptr %23, align 8, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %21, i64 -32
  %25 = getelementptr inbounds i8, ptr %21, i64 24
  store ptr %24, ptr %25, align 8, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %12, !llvm.loop !20
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(write, argmem: readwrite, 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, !10, i64 8}
!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 = !{!13, !10, i64 24}
!13 = !{!"_ZTS18ImTriangulatorNode", !14, i64 0, !7, i64 4, !15, i64 8, !10, i64 16, !10, i64 24}
!14 = !{!"_ZTS22ImTriangulatorNodeType", !8, i64 0}
!15 = !{!"_ZTS6ImVec2", !16, i64 0, !16, i64 4}
!16 = !{!"float", !8, i64 0}
!17 = !{!13, !10, i64 16}
!18 = !{!13, !14, i64 0}
!19 = !{!13, !7, i64 4}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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