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

; 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 nounwind uwtable
define dso_local void @_ZN14ImTriangulator12FlipNodeListEv(ptr noundef nonnull align 8 dereferenceable(48) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %7 = getelementptr inbounds %struct.ImTriangulator, ptr %6, i32 0, i32 1
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %8, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %9 = getelementptr inbounds %struct.ImTriangulator, ptr %6, i32 0, i32 1
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr %10, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %11 = getelementptr inbounds %struct.ImTriangulator, ptr %6, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %12, i32 0, i32 3
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  store ptr %14, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %16, i32 0, i32 3
  store ptr %15, ptr %17, align 8, !tbaa !13
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %19, i32 0, i32 4
  store ptr %18, ptr %20, align 8, !tbaa !18
  br label %21

21:                                               ; preds = %26, %1
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.ImTriangulator, ptr %6, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = icmp ne ptr %22, %24
  br i1 %25, label %26, label %46

26:                                               ; preds = %21
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %27, i32 0, i32 3
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  store ptr %29, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %31, i32 0, i32 3
  store ptr %30, ptr %32, align 8, !tbaa !13
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %34, i32 0, i32 4
  store ptr %33, ptr %35, align 8, !tbaa !18
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.ImTriangulator, ptr %6, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %38, i32 0, i32 3
  store ptr %36, ptr %39, align 8, !tbaa !13
  %40 = getelementptr inbounds %struct.ImTriangulator, ptr %6, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !9
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.ImTriangulatorNode, ptr %42, i32 0, i32 4
  store ptr %41, ptr %43, align 8, !tbaa !18
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %44, ptr %3, align 8, !tbaa !5
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %45, ptr %5, align 8, !tbaa !5
  br label %21, !llvm.loop !19

46:                                               ; preds = %21
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.ImTriangulator, ptr %6, i32 0, i32 1
  store ptr %47, ptr %48, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret void
}

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 = { 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 = !{!14, !6, i64 16}
!14 = !{!"_ZTS18ImTriangulatorNode", !15, i64 0, !11, i64 4, !16, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!"_ZTS22ImTriangulatorNodeType", !7, i64 0}
!16 = !{!"_ZTS6ImVec2", !17, i64 0, !17, i64 4}
!17 = !{!"float", !7, i64 0}
!18 = !{!14, !6, i64 24}
!19 = distinct !{!19, !20}
!20 = !{!"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 nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN14ImTriangulator12FlipNodeListEv(ptr nocapture noundef nonnull align 8 dereferenceable(48) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !12
  store ptr %3, ptr %4, align 8, !tbaa !12
  %6 = getelementptr inbounds i8, ptr %3, i64 24
  store ptr %3, ptr %6, align 8, !tbaa !17
  %.not17 = icmp eq ptr %5, %3
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.019 = phi ptr [ %8, %.lr.ph ], [ %5, %1 ]
  %.01618 = phi ptr [ %.019, %.lr.ph ], [ %3, %1 ]
  %7 = getelementptr inbounds i8, ptr %.019, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !12
  store ptr %.01618, ptr %7, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %.01618, i64 24
  store ptr %.019, ptr %9, align 8, !tbaa !17
  store ptr %.019, ptr %4, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %.019, i64 24
  store ptr %3, ptr %10, align 8, !tbaa !17
  %.not = icmp eq ptr %8, %3
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph, %1
  %.016.lcssa = phi ptr [ %3, %1 ], [ %.019, %.lr.ph ]
  store ptr %.016.lcssa, ptr %2, align 8, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(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 16}
!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 24}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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