; LLVM IR from mtsamis/box2d-optimized :: src/particle/b2_voronoi_diagram.ll (ZN16b2VoronoiDiagram12AddGeneratorERK6b2Vec2ib)

; 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.b2VoronoiDiagram = type { ptr, ptr, i32, i32, i32, i32, ptr }
%"struct.b2VoronoiDiagram::Generator" = type <{ %struct.b2Vec2, i32, i8, [3 x i8] }>
%struct.b2Vec2 = type { float, float }

@.str = external hidden unnamed_addr constant [39 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [93 x i8], align 1
@__PRETTY_FUNCTION__._ZN16b2VoronoiDiagram12AddGeneratorERK6b2Vec2ib = external hidden unnamed_addr constant [65 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN16b2VoronoiDiagram12AddGeneratorERK6b2Vec2ib(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 4 dereferenceable(8) %1, i32 noundef %2, i1 noundef zeroext %3) #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  %10 = zext i1 %3 to i8
  store i8 %10, ptr %8, align 1, !tbaa !11
  %11 = load ptr, ptr %5, align 8
  %12 = getelementptr inbounds %class.b2VoronoiDiagram, ptr %11, i32 0, i32 3
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = getelementptr inbounds %class.b2VoronoiDiagram, ptr %11, i32 0, i32 2
  %15 = load i32, ptr %14, align 8, !tbaa !15
  %16 = icmp slt i32 %13, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %4
  br label %20

18:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 48, ptr noundef @__PRETTY_FUNCTION__._ZN16b2VoronoiDiagram12AddGeneratorERK6b2Vec2ib) #4
  unreachable

19:                                               ; No predecessors!
  br label %20

20:                                               ; preds = %19, %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %21 = getelementptr inbounds %class.b2VoronoiDiagram, ptr %11, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = getelementptr inbounds %class.b2VoronoiDiagram, ptr %11, i32 0, i32 3
  %24 = load i32, ptr %23, align 4, !tbaa !13
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %23, align 4, !tbaa !13
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds %"struct.b2VoronoiDiagram::Generator", ptr %22, i64 %26
  store ptr %27, ptr %9, align 8, !tbaa !5
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %"struct.b2VoronoiDiagram::Generator", ptr %29, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %30, ptr align 4 %28, i64 8, i1 false), !tbaa.struct !17
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = getelementptr inbounds %"struct.b2VoronoiDiagram::Generator", ptr %32, i32 0, i32 1
  store i32 %31, ptr %33, align 4, !tbaa !20
  %34 = load i8, ptr %8, align 1, !tbaa !11, !range !23, !noundef !24
  %35 = trunc i8 %34 to i1
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds %"struct.b2VoronoiDiagram::Generator", ptr %36, i32 0, i32 2
  %38 = zext i1 %35 to i8
  store i8 %38, ptr %37, align 4, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { noreturn nounwind }
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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !10, i64 20}
!14 = !{!"_ZTS16b2VoronoiDiagram", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !6, i64 32}
!15 = !{!14, !10, i64 16}
!16 = !{!14, !6, i64 8}
!17 = !{i64 0, i64 4, !18, i64 4, i64 4, !18}
!18 = !{!19, !19, i64 0}
!19 = !{!"float", !7, i64 0}
!20 = !{!21, !10, i64 8}
!21 = !{!"_ZTSN16b2VoronoiDiagram9GeneratorE", !22, i64 0, !10, i64 8, !12, i64 12}
!22 = !{!"_ZTS6b2Vec2", !19, i64 0, !19, i64 4}
!23 = !{i8 0, i8 2}
!24 = !{}
!25 = !{!21, !12, i64 12}


; 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.b2VoronoiDiagram::Generator" = type <{ %struct.b2Vec2, i32, i8, [3 x i8] }>
%struct.b2Vec2 = type { float, float }

@.str = external hidden unnamed_addr constant [39 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [93 x i8], align 1
@__PRETTY_FUNCTION__._ZN16b2VoronoiDiagram12AddGeneratorERK6b2Vec2ib = external hidden unnamed_addr constant [65 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN16b2VoronoiDiagram12AddGeneratorERK6b2Vec2ib(ptr nocapture noundef nonnull align 8 dereferenceable(40) %0, ptr nocapture noundef nonnull readonly align 4 dereferenceable(8) %1, i32 noundef %2, i1 noundef zeroext %3) local_unnamed_addr #0 align 2 {
  %5 = getelementptr inbounds i8, ptr %0, i64 20
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = icmp slt i32 %6, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 48, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN16b2VoronoiDiagram12AddGeneratorERK6b2Vec2ib) #2
  unreachable

11:                                               ; preds = %4
  %12 = zext i1 %3 to i8
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = add nsw i32 %6, 1
  store i32 %15, ptr %5, align 4, !tbaa !5
  %16 = sext i32 %6 to i64
  %17 = getelementptr inbounds %"struct.b2VoronoiDiagram::Generator", ptr %14, i64 %16
  %18 = load i64, ptr %1, align 4
  store i64 %18, ptr %17, align 4
  %19 = getelementptr inbounds i8, ptr %17, i64 8
  store i32 %2, ptr %19, align 4, !tbaa !13
  %20 = getelementptr inbounds i8, ptr %17, i64 12
  store i8 %12, ptr %20, align 4, !tbaa !18
  ret void
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

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 = { noreturn nounwind "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 = { noreturn 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, !10, i64 20}
!6 = !{!"_ZTS16b2VoronoiDiagram", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !7, i64 8}
!13 = !{!14, !10, i64 8}
!14 = !{!"_ZTSN16b2VoronoiDiagram9GeneratorE", !15, i64 0, !10, i64 8, !17, i64 12}
!15 = !{!"_ZTS6b2Vec2", !16, i64 0, !16, i64 4}
!16 = !{!"float", !8, i64 0}
!17 = !{!"bool", !8, i64 0}
!18 = !{!14, !17, i64 12}


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