; LLVM IR from tyoma/agge :: src/agge/vector_rasterizer.ll (ZN4agge17vector_rasterizer7compactEv)

; 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"

%"class.agge::vector_rasterizer" = type <{ %"class.agge::pod_vector", %"class.agge::pod_vector.0", %"class.agge::pod_vector.0", %"class.agge::pod_vector", i32, i32, i32, i32, i32, [4 x i8] }>
%"class.agge::pod_vector.0" = type { ptr, ptr, ptr }
%"class.agge::pod_vector" = type { ptr, ptr, ptr }
%"struct.agge::vector_rasterizer::cell" = type <{ i16, i16, i32, 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 dso_local noundef ptr @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE3endEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4agge17vector_rasterizer4sortEb(ptr noundef nonnull align 8 dereferenceable(116), i1 noundef zeroext) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE6resizeEj(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) #3 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; 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) #4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4agge17vector_rasterizer7compactEv(ptr noundef nonnull align 8 dereferenceable(116) %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  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) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @_ZN4agge17vector_rasterizer4sortEb(ptr noundef nonnull align 8 dereferenceable(116) %5, i1 noundef zeroext false)
  %6 = getelementptr inbounds %"class.agge::vector_rasterizer", ptr %5, i32 0, i32 0
  %7 = call noundef ptr @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %6)
  store ptr %7, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %8, ptr %4, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %67, %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %"class.agge::vector_rasterizer", ptr %5, i32 0, i32 0
  %12 = call noundef ptr @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %11)
  %13 = icmp ne ptr %10, %12
  br i1 %13, label %14, label %70

14:                                               ; preds = %9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %"struct.agge::vector_rasterizer::cell", ptr %15, i32 1
  store ptr %16, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %17, ptr align 1 %15, i64 10, i1 false), !tbaa.struct !9
  br label %18

18:                                               ; preds = %63, %14
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %"class.agge::vector_rasterizer", ptr %5, i32 0, i32 0
  %21 = call noundef ptr @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %20)
  %22 = icmp ne ptr %19, %21
  br i1 %22, label %23, label %43

23:                                               ; preds = %18
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.agge::vector_rasterizer::cell", ptr %24, i32 0, i32 0
  %26 = load i16, ptr %25, align 1, !tbaa !14
  %27 = sext i16 %26 to i32
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %"struct.agge::vector_rasterizer::cell", ptr %28, i32 0, i32 0
  %30 = load i16, ptr %29, align 1, !tbaa !14
  %31 = sext i16 %30 to i32
  %32 = icmp eq i32 %27, %31
  br i1 %32, label %33, label %43

33:                                               ; preds = %23
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.agge::vector_rasterizer::cell", ptr %34, i32 0, i32 1
  %36 = load i16, ptr %35, align 1, !tbaa !16
  %37 = sext i16 %36 to i32
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.agge::vector_rasterizer::cell", ptr %38, i32 0, i32 1
  %40 = load i16, ptr %39, align 1, !tbaa !16
  %41 = sext i16 %40 to i32
  %42 = icmp eq i32 %37, %41
  br label %43

43:                                               ; preds = %33, %23, %18
  %44 = phi i1 [ false, %23 ], [ false, %18 ], [ %42, %33 ]
  br i1 %44, label %45, label %66

45:                                               ; preds = %43
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %"struct.agge::vector_rasterizer::cell", ptr %46, i32 0, i32 2
  %48 = load i32, ptr %47, align 1, !tbaa !17
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %"struct.agge::vector_rasterizer::cell", ptr %49, i32 0, i32 2
  %51 = load i32, ptr %50, align 1, !tbaa !17
  %52 = add nsw i32 %51, %48
  store i32 %52, ptr %50, align 1, !tbaa !17
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %"struct.agge::vector_rasterizer::cell", ptr %53, i32 0, i32 3
  %55 = load i16, ptr %54, align 1, !tbaa !18
  %56 = sext i16 %55 to i32
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %"struct.agge::vector_rasterizer::cell", ptr %57, i32 0, i32 3
  %59 = load i16, ptr %58, align 1, !tbaa !18
  %60 = sext i16 %59 to i32
  %61 = add nsw i32 %60, %56
  %62 = trunc i32 %61 to i16
  store i16 %62, ptr %58, align 1, !tbaa !18
  br label %63

63:                                               ; preds = %45
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %"struct.agge::vector_rasterizer::cell", ptr %64, i32 1
  store ptr %65, ptr %3, align 8, !tbaa !5
  br label %18, !llvm.loop !19

66:                                               ; preds = %43
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %"struct.agge::vector_rasterizer::cell", ptr %68, i32 1
  store ptr %69, ptr %4, align 8, !tbaa !5
  br label %9, !llvm.loop !21

70:                                               ; preds = %9
  %71 = getelementptr inbounds %"class.agge::vector_rasterizer", ptr %5, i32 0, i32 0
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = getelementptr inbounds %"class.agge::vector_rasterizer", ptr %5, i32 0, i32 0
  %74 = call noundef ptr @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %73)
  %75 = ptrtoint ptr %72 to i64
  %76 = ptrtoint ptr %74 to i64
  %77 = sub i64 %75, %76
  %78 = sdiv exact i64 %77, 10
  %79 = trunc i64 %78 to i32
  call void @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE6resizeEj(ptr noundef nonnull align 8 dereferenceable(24) %71, i32 noundef %79)
  %80 = getelementptr inbounds %"class.agge::vector_rasterizer", ptr %5, i32 0, i32 8
  store i32 0, ptr %80, align 8, !tbaa !22
  call void @_ZN4agge17vector_rasterizer4sortEb(ptr noundef nonnull align 8 dereferenceable(116) %5, i1 noundef zeroext false)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret void
}

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"="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 = { inlinehint 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 = !{i64 0, i64 2, !10, i64 2, i64 2, !10, i64 4, i64 4, !12, i64 8, i64 2, !10}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !11, i64 0}
!15 = !{!"_ZTSN4agge17vector_rasterizer4cellE", !11, i64 0, !11, i64 2, !13, i64 4, !11, i64 8}
!16 = !{!15, !11, i64 2}
!17 = !{!15, !13, i64 4}
!18 = !{!15, !11, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}
!22 = !{!23, !13, i64 112}
!23 = !{!"_ZTSN4agge17vector_rasterizerE", !24, i64 0, !25, i64 24, !25, i64 48, !24, i64 72, !13, i64 96, !13, i64 100, !13, i64 104, !13, i64 108, !13, i64 112}
!24 = !{!"_ZTSN4agge10pod_vectorINS_17vector_rasterizer4cellEEE", !6, i64 0, !6, i64 8, !6, i64 16}
!25 = !{!"_ZTSN4agge10pod_vectorIjEE", !6, i64 0, !6, i64 8, !6, i64 16}


; 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 dso_local noundef ptr @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE3endEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4agge17vector_rasterizer4sortEb(ptr noundef nonnull align 8 dereferenceable(116), i1 noundef zeroext) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE6resizeEj(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress 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) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4agge17vector_rasterizer7compactEv(ptr noundef nonnull align 8 dereferenceable(116) %0) local_unnamed_addr #1 align 2 {
  tail call void @_ZN4agge17vector_rasterizer4sortEb(ptr noundef nonnull align 8 dereferenceable(116) %0, i1 noundef zeroext false)
  %2 = tail call noundef ptr @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %3 = tail call noundef ptr @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %.not27 = icmp eq ptr %2, %3
  br i1 %.not27, label %._crit_edge, label %.lr.ph30

.lr.ph30:                                         ; preds = %1, %.critedge
  %.029 = phi ptr [ %27, %.critedge ], [ %2, %1 ]
  %.01728 = phi ptr [ %.1.lcssa, %.critedge ], [ %2, %1 ]
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(10) %.029, ptr noundef nonnull align 1 dereferenceable(10) %.01728, i64 10, i1 false), !tbaa.struct !5
  %.119 = getelementptr inbounds i8, ptr %.01728, i64 10
  %4 = tail call noundef ptr @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %.not1820 = icmp eq ptr %.119, %4
  br i1 %.not1820, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph30
  %5 = getelementptr inbounds i8, ptr %.029, i64 2
  %6 = getelementptr inbounds i8, ptr %.029, i64 4
  %7 = getelementptr inbounds i8, ptr %.029, i64 8
  br label %8

8:                                                ; preds = %.lr.ph, %17
  %.122 = phi ptr [ %.119, %.lr.ph ], [ %.1, %17 ]
  %.017.pn21 = phi ptr [ %.01728, %.lr.ph ], [ %.122, %17 ]
  %9 = load i16, ptr %.122, align 1, !tbaa !12
  %10 = load i16, ptr %.029, align 1, !tbaa !12
  %11 = icmp eq i16 %9, %10
  br i1 %11, label %12, label %.critedge

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %.017.pn21, i64 12
  %14 = load i16, ptr %13, align 1, !tbaa !14
  %15 = load i16, ptr %5, align 1, !tbaa !14
  %16 = icmp eq i16 %14, %15
  br i1 %16, label %17, label %.critedge

17:                                               ; preds = %12
  %18 = getelementptr inbounds i8, ptr %.017.pn21, i64 14
  %19 = load i32, ptr %18, align 1, !tbaa !15
  %20 = load i32, ptr %6, align 1, !tbaa !15
  %21 = add nsw i32 %20, %19
  store i32 %21, ptr %6, align 1, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %.017.pn21, i64 18
  %23 = load i16, ptr %22, align 1, !tbaa !16
  %24 = load i16, ptr %7, align 1, !tbaa !16
  %25 = add i16 %24, %23
  store i16 %25, ptr %7, align 1, !tbaa !16
  %.1 = getelementptr inbounds i8, ptr %.122, i64 10
  %26 = tail call noundef ptr @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %.not18 = icmp eq ptr %.1, %26
  br i1 %.not18, label %.critedge, label %8, !llvm.loop !17

.critedge:                                        ; preds = %8, %17, %12, %.lr.ph30
  %.1.lcssa = phi ptr [ %.119, %.lr.ph30 ], [ %.122, %12 ], [ %.1, %17 ], [ %.122, %8 ]
  %27 = getelementptr inbounds i8, ptr %.029, i64 10
  %28 = tail call noundef ptr @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %.not = icmp eq ptr %.1.lcssa, %28
  br i1 %.not, label %._crit_edge, label %.lr.ph30, !llvm.loop !19

._crit_edge:                                      ; preds = %.critedge, %1
  %.0.lcssa = phi ptr [ %2, %1 ], [ %27, %.critedge ]
  %29 = tail call noundef ptr @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %0)
  %30 = ptrtoint ptr %.0.lcssa to i64
  %31 = ptrtoint ptr %29 to i64
  %32 = sub i64 %30, %31
  %33 = sdiv exact i64 %32, 10
  %34 = trunc i64 %33 to i32
  tail call void @_ZN4agge10pod_vectorINS_17vector_rasterizer4cellEE6resizeEj(ptr noundef nonnull align 8 dereferenceable(24) %0, i32 noundef %34)
  %35 = getelementptr inbounds i8, ptr %0, i64 112
  store i32 0, ptr %35, align 8, !tbaa !20
  tail call void @_ZN4agge17vector_rasterizer4sortEb(ptr noundef nonnull align 8 dereferenceable(116) %0, i1 noundef zeroext false)
  ret void
}

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"="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 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }

!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 = !{i64 0, i64 2, !6, i64 2, i64 2, !6, i64 4, i64 4, !10, i64 8, i64 2, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"_ZTSN4agge17vector_rasterizer4cellE", !7, i64 0, !7, i64 2, !11, i64 4, !7, i64 8}
!14 = !{!13, !7, i64 2}
!15 = !{!13, !11, i64 4}
!16 = !{!13, !7, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = !{!21, !11, i64 112}
!21 = !{!"_ZTSN4agge17vector_rasterizerE", !22, i64 0, !24, i64 24, !24, i64 48, !22, i64 72, !11, i64 96, !11, i64 100, !11, i64 104, !11, i64 108, !11, i64 112}
!22 = !{!"_ZTSN4agge10pod_vectorINS_17vector_rasterizer4cellEEE", !23, i64 0, !23, i64 8, !23, i64 16}
!23 = !{!"any pointer", !8, i64 0}
!24 = !{!"_ZTSN4agge10pod_vectorIjEE", !23, i64 0, !23, i64 8, !23, i64 16}


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