; LLVM IR from erincatto/box2d :: src (geometry)

; 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.b2Polygon = type { [8 x %struct.b2Vec2], [8 x %struct.b2Vec2], %struct.b2Vec2, float, i32 }
%struct.b2Vec2 = type { float, float }
%struct.b2Transform = type { %struct.b2Vec2, %struct.b2Rot }
%struct.b2Rot = 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: 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: inlinehint nounwind uwtable
declare hidden <2 x float> @b2TransformPoint(<2 x float>, <2 x float>, <2 x float>) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @b2RotateVector(<2 x float>, <2 x float>) #2

; Function Attrs: nounwind uwtable
define dso_local void @b2TransformPolygon(ptr dead_on_unwind noalias writable sret(%struct.b2Polygon) align 4 %0, <2 x float> %1, <2 x float> %2, ptr noundef %3) #3 {
  %5 = alloca %struct.b2Transform, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca %struct.b2Vec2, align 4
  %9 = alloca %struct.b2Vec2, align 4
  %10 = alloca %struct.b2Vec2, align 4
  %11 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %5, i32 0, i32 0
  store <2 x float> %1, ptr %11, align 4
  %12 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %5, i32 0, i32 1
  store <2 x float> %2, ptr %12, align 4
  store ptr %3, ptr %6, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 4 %13, i64 144, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !13
  br label %14

14:                                               ; preds = %47, %4
  %15 = load i32, ptr %7, align 4, !tbaa !13
  %16 = getelementptr inbounds %struct.b2Polygon, ptr %0, i32 0, i32 4
  %17 = load i32, ptr %16, align 4, !tbaa !15
  %18 = icmp slt i32 %15, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %50

20:                                               ; preds = %14
  %21 = getelementptr inbounds %struct.b2Polygon, ptr %0, i32 0, i32 0
  %22 = load i32, ptr %7, align 4, !tbaa !13
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [8 x %struct.b2Vec2], ptr %21, i64 0, i64 %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %25 = getelementptr inbounds %struct.b2Polygon, ptr %0, i32 0, i32 0
  %26 = load i32, ptr %7, align 4, !tbaa !13
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [8 x %struct.b2Vec2], ptr %25, i64 0, i64 %27
  %29 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %5, i32 0, i32 0
  %30 = load <2 x float>, ptr %29, align 4
  %31 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %5, i32 0, i32 1
  %32 = load <2 x float>, ptr %31, align 4
  %33 = load <2 x float>, ptr %28, align 4
  %34 = call <2 x float> @b2TransformPoint(<2 x float> %30, <2 x float> %32, <2 x float> %33)
  store <2 x float> %34, ptr %8, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %24, ptr align 4 %8, i64 8, i1 false), !tbaa.struct !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %35 = getelementptr inbounds %struct.b2Polygon, ptr %0, i32 0, i32 1
  %36 = load i32, ptr %7, align 4, !tbaa !13
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [8 x %struct.b2Vec2], ptr %35, i64 0, i64 %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %39 = getelementptr inbounds %struct.b2Transform, ptr %5, i32 0, i32 1
  %40 = getelementptr inbounds %struct.b2Polygon, ptr %0, i32 0, i32 1
  %41 = load i32, ptr %7, align 4, !tbaa !13
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [8 x %struct.b2Vec2], ptr %40, i64 0, i64 %42
  %44 = load <2 x float>, ptr %39, align 4
  %45 = load <2 x float>, ptr %43, align 4
  %46 = call <2 x float> @b2RotateVector(<2 x float> %44, <2 x float> %45)
  store <2 x float> %46, ptr %9, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %38, ptr align 4 %9, i64 8, i1 false), !tbaa.struct !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %47

47:                                               ; preds = %20
  %48 = load i32, ptr %7, align 4, !tbaa !13
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %7, align 4, !tbaa !13
  br label %14, !llvm.loop !19

50:                                               ; preds = %19
  %51 = getelementptr inbounds %struct.b2Polygon, ptr %0, i32 0, i32 2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %52 = getelementptr inbounds %struct.b2Polygon, ptr %0, i32 0, i32 2
  %53 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %5, i32 0, i32 0
  %54 = load <2 x float>, ptr %53, align 4
  %55 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %5, i32 0, i32 1
  %56 = load <2 x float>, ptr %55, align 4
  %57 = load <2 x float>, ptr %52, align 4
  %58 = call <2 x float> @b2TransformPoint(<2 x float> %54, <2 x float> %56, <2 x float> %57)
  store <2 x float> %58, ptr %10, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %51, ptr align 4 %10, i64 8, i1 false), !tbaa.struct !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint nounwind uwtable "min-legal-vector-width"="64" "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 uwtable "min-legal-vector-width"="64" "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/C++ TBAA"}
!9 = !{i64 0, i64 64, !10, i64 64, i64 64, !10, i64 128, i64 4, !11, i64 132, i64 4, !11, i64 136, i64 4, !11, i64 140, i64 4, !13}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !14, i64 140}
!16 = !{!"b2Polygon", !7, i64 0, !7, i64 64, !17, i64 128, !12, i64 136, !14, i64 140}
!17 = !{!"b2Vec2", !12, i64 0, !12, i64 4}
!18 = !{i64 0, i64 4, !11, i64 4, i64 4, !11}
!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"

%struct.b2Polygon = type { [8 x %struct.b2Vec2], [8 x %struct.b2Vec2], %struct.b2Vec2, float, i32 }
%struct.b2Vec2 = type { float, float }

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @b2TransformPoint(<2 x float>, <2 x float>, <2 x float>) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden <2 x float> @b2RotateVector(<2 x float>, <2 x float>) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @b2TransformPolygon(ptr dead_on_unwind noalias nocapture writable sret(%struct.b2Polygon) align 4 %0, <2 x float> %1, <2 x float> %2, ptr nocapture noundef readonly %3) local_unnamed_addr #2 {
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(144) %0, ptr noundef nonnull align 4 dereferenceable(144) %3, i64 144, i1 false), !tbaa.struct !5
  %5 = getelementptr inbounds i8, ptr %0, i64 140
  %6 = load i32, ptr %5, align 4, !tbaa !13
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 64
  br label %12

._crit_edge:                                      ; preds = %12, %4
  %9 = getelementptr inbounds i8, ptr %0, i64 128
  %10 = load <2 x float>, ptr %9, align 4
  %11 = tail call <2 x float> @b2TransformPoint(<2 x float> %1, <2 x float> %2, <2 x float> %10)
  store <2 x float> %11, ptr %9, align 4
  ret void

12:                                               ; preds = %.lr.ph, %12
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %12 ]
  %13 = getelementptr inbounds [8 x %struct.b2Vec2], ptr %0, i64 0, i64 %indvars.iv
  %14 = load <2 x float>, ptr %13, align 4
  %15 = tail call <2 x float> @b2TransformPoint(<2 x float> %1, <2 x float> %2, <2 x float> %14)
  store <2 x float> %15, ptr %13, align 4
  %16 = getelementptr inbounds [8 x %struct.b2Vec2], ptr %8, i64 0, i64 %indvars.iv
  %17 = load <2 x float>, ptr %16, align 4
  %18 = tail call <2 x float> @b2RotateVector(<2 x float> %2, <2 x float> %17)
  store <2 x float> %18, ptr %16, align 4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = load i32, ptr %5, align 4, !tbaa !13
  %20 = sext i32 %19 to i64
  %21 = icmp slt i64 %indvars.iv.next, %20
  br i1 %21, label %12, label %._crit_edge, !llvm.loop !16
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint nounwind uwtable "min-legal-vector-width"="64" "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 uwtable "min-legal-vector-width"="64" "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 = !{i64 0, i64 64, !6, i64 64, i64 64, !6, i64 128, i64 4, !9, i64 132, i64 4, !9, i64 136, i64 4, !9, i64 140, i64 4, !11}
!6 = !{!7, !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 140}
!14 = !{!"b2Polygon", !7, i64 0, !7, i64 64, !15, i64 128, !10, i64 136, !12, i64 140}
!15 = !{!"b2Vec2", !10, i64 0, !10, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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