; 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.b2Transform = type { %struct.b2Vec2, %struct.b2Rot }
%struct.b2Vec2 = type { float, float }
%struct.b2Rot = type { float, float }
%struct.b2ShapeProxy = type { [8 x %struct.b2Vec2], i32, float }
%struct.b2DistanceOutput = type { %struct.b2Vec2, %struct.b2Vec2, %struct.b2Vec2, float, i32, i32 }
%struct.b2PlaneResult = type { %struct.b2Plane, i8 }
%struct.b2Plane = type { %struct.b2Vec2, float }
%struct.b2DistanceInput = type { %struct.b2ShapeProxy, %struct.b2ShapeProxy, %struct.b2Transform, %struct.b2Transform, i8 }
%struct.b2SimplexCache = type { i16, [3 x i8], [3 x i8] }
%struct.b2Polygon = type { [8 x %struct.b2Vec2], [8 x %struct.b2Vec2], %struct.b2Vec2, float, i32 }
%struct.b2Capsule = type { %struct.b2Vec2, %struct.b2Vec2, float }

@b2Transform_identity = external hidden constant %struct.b2Transform, align 4

; 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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

declare void @b2MakeProxy(ptr dead_on_unwind writable sret(%struct.b2ShapeProxy) align 4, ptr noundef, i32 noundef, float noundef) #3

declare void @b2ShapeDistance(ptr dead_on_unwind writable sret(%struct.b2DistanceOutput) align 4, ptr noundef, ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local { <2 x float>, i64 } @b2CollideMoverAndPolygon(ptr noundef %0, ptr noundef %1) #4 {
  %3 = alloca %struct.b2PlaneResult, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.b2DistanceInput, align 4
  %7 = alloca %struct.b2ShapeProxy, align 4
  %8 = alloca %struct.b2ShapeProxy, align 4
  %9 = alloca float, align 4
  %10 = alloca %struct.b2SimplexCache, align 2
  %11 = alloca %struct.b2DistanceOutput, align 4
  %12 = alloca %struct.b2Plane, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 180, ptr %6) #5
  %14 = getelementptr inbounds %struct.b2DistanceInput, ptr %6, i32 0, i32 0
  call void @llvm.lifetime.start.p0(i64 72, ptr %7) #5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.b2Polygon, ptr %15, i32 0, i32 0
  %17 = getelementptr inbounds [8 x %struct.b2Vec2], ptr %16, i64 0, i64 0
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.b2Polygon, ptr %18, i32 0, i32 4
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.b2Polygon, ptr %21, i32 0, i32 3
  %23 = load float, ptr %22, align 4, !tbaa !14
  call void @b2MakeProxy(ptr dead_on_unwind writable sret(%struct.b2ShapeProxy) align 4 %7, ptr noundef %17, i32 noundef %20, float noundef %23)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %7, i64 72, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 72, ptr %7) #5
  %24 = getelementptr inbounds %struct.b2DistanceInput, ptr %6, i32 0, i32 1
  call void @llvm.lifetime.start.p0(i64 72, ptr %8) #5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.b2Capsule, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.b2Capsule, ptr %27, i32 0, i32 2
  %29 = load float, ptr %28, align 4, !tbaa !19
  call void @b2MakeProxy(ptr dead_on_unwind writable sret(%struct.b2ShapeProxy) align 4 %8, ptr noundef %26, i32 noundef 2, float noundef %29)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %24, ptr align 4 %8, i64 72, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 72, ptr %8) #5
  %30 = getelementptr inbounds %struct.b2DistanceInput, ptr %6, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %30, ptr align 4 @b2Transform_identity, i64 16, i1 false), !tbaa.struct !21
  %31 = getelementptr inbounds %struct.b2DistanceInput, ptr %6, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %31, ptr align 4 @b2Transform_identity, i64 16, i1 false), !tbaa.struct !21
  %32 = getelementptr inbounds %struct.b2DistanceInput, ptr %6, i32 0, i32 4
  store i8 0, ptr %32, align 4, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.b2Capsule, ptr %33, i32 0, i32 2
  %35 = load float, ptr %34, align 4, !tbaa !19
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.b2Polygon, ptr %36, i32 0, i32 3
  %38 = load float, ptr %37, align 4, !tbaa !14
  %39 = fadd float %35, %38
  store float %39, ptr %9, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.memset.p0.i64(ptr align 2 %10, i8 0, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 36, ptr %11) #5
  call void @b2ShapeDistance(ptr dead_on_unwind writable sret(%struct.b2DistanceOutput) align 4 %11, ptr noundef %6, ptr noundef %10, ptr noundef null, i32 noundef 0)
  %40 = getelementptr inbounds %struct.b2DistanceOutput, ptr %11, i32 0, i32 3
  %41 = load float, ptr %40, align 4, !tbaa !28
  %42 = load float, ptr %9, align 4, !tbaa !18
  %43 = fcmp ole float %41, %42
  br i1 %43, label %44, label %54

44:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 12, ptr %12) #5
  %45 = getelementptr inbounds %struct.b2Plane, ptr %12, i32 0, i32 0
  %46 = getelementptr inbounds %struct.b2DistanceOutput, ptr %11, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %45, ptr align 4 %46, i64 8, i1 false), !tbaa.struct !30
  %47 = getelementptr inbounds %struct.b2Plane, ptr %12, i32 0, i32 1
  %48 = load float, ptr %9, align 4, !tbaa !18
  %49 = getelementptr inbounds %struct.b2DistanceOutput, ptr %11, i32 0, i32 3
  %50 = load float, ptr %49, align 4, !tbaa !28
  %51 = fsub float %48, %50
  store float %51, ptr %47, align 4, !tbaa !31
  %52 = getelementptr inbounds %struct.b2PlaneResult, ptr %3, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %52, ptr align 4 %12, i64 12, i1 false), !tbaa.struct !33
  %53 = getelementptr inbounds %struct.b2PlaneResult, ptr %3, i32 0, i32 1
  store i8 1, ptr %53, align 4, !tbaa !34
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 12, ptr %12) #5
  br label %61

54:                                               ; preds = %2
  %55 = getelementptr inbounds %struct.b2PlaneResult, ptr %3, i32 0, i32 0
  %56 = getelementptr inbounds %struct.b2Plane, ptr %55, i32 0, i32 0
  %57 = getelementptr inbounds %struct.b2Vec2, ptr %56, i32 0, i32 0
  store float 0.000000e+00, ptr %57, align 4, !tbaa !36
  %58 = getelementptr inbounds %struct.b2Vec2, ptr %56, i32 0, i32 1
  store float 0.000000e+00, ptr %58, align 4, !tbaa !37
  %59 = getelementptr inbounds %struct.b2Plane, ptr %55, i32 0, i32 1
  store float 0.000000e+00, ptr %59, align 4, !tbaa !31
  %60 = getelementptr inbounds %struct.b2PlaneResult, ptr %3, i32 0, i32 1
  store i8 0, ptr %60, align 4, !tbaa !34
  store i32 1, ptr %13, align 4
  br label %61

61:                                               ; preds = %54, %44
  call void @llvm.lifetime.end.p0(i64 36, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 180, ptr %6) #5
  %62 = load { <2 x float>, i64 }, ptr %3, align 4
  ret { <2 x float>, i64 } %62
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 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 #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/C++ TBAA"}
!9 = !{!10, !13, i64 140}
!10 = !{!"b2Polygon", !7, i64 0, !7, i64 64, !11, i64 128, !12, i64 136, !13, i64 140}
!11 = !{!"b2Vec2", !12, i64 0, !12, i64 4}
!12 = !{!"float", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!10, !12, i64 136}
!15 = !{i64 0, i64 64, !16, i64 64, i64 4, !17, i64 68, i64 4, !18}
!16 = !{!7, !7, i64 0}
!17 = !{!13, !13, i64 0}
!18 = !{!12, !12, i64 0}
!19 = !{!20, !12, i64 16}
!20 = !{!"b2Capsule", !11, i64 0, !11, i64 8, !12, i64 16}
!21 = !{i64 0, i64 4, !18, i64 4, i64 4, !18, i64 8, i64 4, !18, i64 12, i64 4, !18}
!22 = !{!23, !27, i64 176}
!23 = !{!"b2DistanceInput", !24, i64 0, !24, i64 72, !25, i64 144, !25, i64 160, !27, i64 176}
!24 = !{!"b2ShapeProxy", !7, i64 0, !13, i64 64, !12, i64 68}
!25 = !{!"b2Transform", !11, i64 0, !26, i64 8}
!26 = !{!"b2Rot", !12, i64 0, !12, i64 4}
!27 = !{!"_Bool", !7, i64 0}
!28 = !{!29, !12, i64 24}
!29 = !{!"b2DistanceOutput", !11, i64 0, !11, i64 8, !11, i64 16, !12, i64 24, !13, i64 28, !13, i64 32}
!30 = !{i64 0, i64 4, !18, i64 4, i64 4, !18}
!31 = !{!32, !12, i64 8}
!32 = !{!"b2Plane", !11, i64 0, !12, i64 8}
!33 = !{i64 0, i64 4, !18, i64 4, i64 4, !18, i64 8, i64 4, !18}
!34 = !{!35, !27, i64 12}
!35 = !{!"b2PlaneResult", !32, i64 0, !27, i64 12}
!36 = !{!11, !12, i64 0}
!37 = !{!11, !12, i64 4}


; 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.b2Transform = type { %struct.b2Vec2, %struct.b2Rot }
%struct.b2Vec2 = type { float, float }
%struct.b2Rot = type { float, float }
%struct.b2ShapeProxy = type { [8 x %struct.b2Vec2], i32, float }
%struct.b2DistanceOutput = type { %struct.b2Vec2, %struct.b2Vec2, %struct.b2Vec2, float, i32, i32 }
%struct.b2DistanceInput = type { %struct.b2ShapeProxy, %struct.b2ShapeProxy, %struct.b2Transform, %struct.b2Transform, i8 }
%struct.b2SimplexCache = type { i16, [3 x i8], [3 x i8] }

@b2Transform_identity = external hidden local_unnamed_addr constant %struct.b2Transform, align 4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

declare void @b2MakeProxy(ptr dead_on_unwind writable sret(%struct.b2ShapeProxy) align 4, ptr noundef, i32 noundef, float noundef) local_unnamed_addr #2

declare void @b2ShapeDistance(ptr dead_on_unwind writable sret(%struct.b2DistanceOutput) align 4, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local { <2 x float>, i64 } @b2CollideMoverAndPolygon(ptr noundef %0, ptr noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.b2DistanceInput, align 4
  %4 = alloca %struct.b2ShapeProxy, align 4
  %5 = alloca %struct.b2SimplexCache, align 8
  %6 = alloca %struct.b2DistanceOutput, align 4
  call void @llvm.lifetime.start.p0(i64 180, ptr nonnull %3) #4
  %7 = getelementptr inbounds i8, ptr %0, i64 140
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 136
  %10 = load float, ptr %9, align 4, !tbaa !12
  call void @b2MakeProxy(ptr dead_on_unwind nonnull writable sret(%struct.b2ShapeProxy) align 4 %3, ptr noundef %0, i32 noundef %8, float noundef %10) #4
  %11 = getelementptr inbounds i8, ptr %3, i64 72
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %4) #4
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  %13 = load float, ptr %12, align 4, !tbaa !13
  call void @b2MakeProxy(ptr dead_on_unwind nonnull writable sret(%struct.b2ShapeProxy) align 4 %4, ptr noundef %1, i32 noundef 2, float noundef %13) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(72) %11, ptr noundef nonnull align 4 dereferenceable(72) %4, i64 72, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %4) #4
  %14 = getelementptr inbounds i8, ptr %3, i64 144
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %14, ptr noundef nonnull align 4 dereferenceable(16) @b2Transform_identity, i64 16, i1 false), !tbaa.struct !19
  %15 = getelementptr inbounds i8, ptr %3, i64 160
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %15, ptr noundef nonnull align 4 dereferenceable(16) @b2Transform_identity, i64 16, i1 false), !tbaa.struct !19
  %16 = getelementptr inbounds i8, ptr %3, i64 176
  store i8 0, ptr %16, align 4, !tbaa !20
  %17 = load float, ptr %12, align 4, !tbaa !13
  %18 = load float, ptr %9, align 4, !tbaa !12
  %19 = fadd float %17, %18
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store i64 0, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 36, ptr nonnull %6) #4
  call void @b2ShapeDistance(ptr dead_on_unwind nonnull writable sret(%struct.b2DistanceOutput) align 4 %6, ptr noundef nonnull %3, ptr noundef nonnull %5, ptr noundef null, i32 noundef 0) #4
  %20 = getelementptr inbounds i8, ptr %6, i64 24
  %21 = load float, ptr %20, align 4, !tbaa !26
  %22 = fcmp ugt float %21, %19
  %23 = getelementptr inbounds i8, ptr %6, i64 16
  %.sroa.0.sroa.0.0.copyload = load <2 x float>, ptr %23, align 4
  %24 = fsub float %19, %21
  %25 = bitcast float %24 to i32
  %26 = zext i32 %25 to i64
  %.sroa.09.0 = select i1 %22, <2 x float> zeroinitializer, <2 x float> %.sroa.0.sroa.0.0.copyload
  call void @llvm.lifetime.end.p0(i64 36, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 180, ptr nonnull %3) #4
  %.fca.0.insert = insertvalue { <2 x float>, i64 } poison, <2 x float> %.sroa.09.0, 0
  %27 = or disjoint i64 %26, 4294967296
  %.sroa.411.8.insert.insert = select i1 %22, i64 0, i64 %27
  %.fca.1.insert = insertvalue { <2 x float>, i64 } %.fca.0.insert, i64 %.sroa.411.8.insert.insert, 1
  ret { <2 x float>, i64 } %.fca.1.insert
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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"="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 = { 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, !11, i64 140}
!6 = !{!"b2Polygon", !7, i64 0, !7, i64 64, !9, i64 128, !10, i64 136, !11, i64 140}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"b2Vec2", !10, i64 0, !10, i64 4}
!10 = !{!"float", !7, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!6, !10, i64 136}
!13 = !{!14, !10, i64 16}
!14 = !{!"b2Capsule", !9, i64 0, !9, i64 8, !10, i64 16}
!15 = !{i64 0, i64 64, !16, i64 64, i64 4, !17, i64 68, i64 4, !18}
!16 = !{!7, !7, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!10, !10, i64 0}
!19 = !{i64 0, i64 4, !18, i64 4, i64 4, !18, i64 8, i64 4, !18, i64 12, i64 4, !18}
!20 = !{!21, !25, i64 176}
!21 = !{!"b2DistanceInput", !22, i64 0, !22, i64 72, !23, i64 144, !23, i64 160, !25, i64 176}
!22 = !{!"b2ShapeProxy", !7, i64 0, !11, i64 64, !10, i64 68}
!23 = !{!"b2Transform", !9, i64 0, !24, i64 8}
!24 = !{!"b2Rot", !10, i64 0, !10, i64 4}
!25 = !{!"_Bool", !7, i64 0}
!26 = !{!27, !10, i64 24}
!27 = !{!"b2DistanceOutput", !9, i64 0, !9, i64 8, !9, i64 16, !10, i64 24, !11, i64 28, !11, i64 32}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass