; LLVM IR from mtsamis/box2d-optimized :: src/collision/b2_distance.ll (ZN15b2DistanceProxy3SetEPK7b2Shape)

; 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.b2CircleShape = type { %class.b2Shape, %struct.b2Vec2 }
%class.b2Shape = type { ptr, i32, float }
%struct.b2Vec2 = type { float, float }
%struct.b2DistanceProxy = type { [2 x %struct.b2Vec2], ptr, i32, float }
%class.b2PolygonShape = type <{ %class.b2Shape, %struct.b2Vec2, [8 x %struct.b2Vec2], [8 x %struct.b2Vec2], i32, [4 x i8] }>
%class.b2EdgeShape = type <{ %class.b2Shape, %struct.b2Vec2, %struct.b2Vec2, %struct.b2Vec2, %struct.b2Vec2, i8, [7 x i8] }>

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@__PRETTY_FUNCTION__._ZN15b2DistanceProxy3SetEPK7b2Shape = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN15b2DistanceProxy3SetEPK7b2Shape(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call noundef i32 @_ZNK7b2Shape7GetTypeEv(ptr noundef nonnull align 8 dereferenceable(16) %9)
  switch i32 %10, label %45 [
    i32 0, label %11
    i32 2, label %21
    i32 1, label %35
  ]

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %12, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %class.b2CircleShape, ptr %13, i32 0, i32 1
  %15 = getelementptr inbounds %struct.b2DistanceProxy, ptr %8, i32 0, i32 1
  store ptr %14, ptr %15, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.b2DistanceProxy, ptr %8, i32 0, i32 2
  store i32 1, ptr %16, align 8, !tbaa !13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.b2Shape, ptr %17, i32 0, i32 2
  %19 = load float, ptr %18, align 4, !tbaa !14
  %20 = getelementptr inbounds %struct.b2DistanceProxy, ptr %8, i32 0, i32 3
  store float %19, ptr %20, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %46

21:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %22, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %class.b2PolygonShape, ptr %23, i32 0, i32 2
  %25 = getelementptr inbounds [8 x %struct.b2Vec2], ptr %24, i64 0, i64 0
  %26 = getelementptr inbounds %struct.b2DistanceProxy, ptr %8, i32 0, i32 1
  store ptr %25, ptr %26, align 8, !tbaa !9
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %class.b2PolygonShape, ptr %27, i32 0, i32 4
  %29 = load i32, ptr %28, align 8, !tbaa !18
  %30 = getelementptr inbounds %struct.b2DistanceProxy, ptr %8, i32 0, i32 2
  store i32 %29, ptr %30, align 8, !tbaa !13
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.b2Shape, ptr %31, i32 0, i32 2
  %33 = load float, ptr %32, align 4, !tbaa !14
  %34 = getelementptr inbounds %struct.b2DistanceProxy, ptr %8, i32 0, i32 3
  store float %33, ptr %34, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %46

35:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %36, ptr %7, align 8, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %class.b2EdgeShape, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds %struct.b2DistanceProxy, ptr %8, i32 0, i32 1
  store ptr %38, ptr %39, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.b2DistanceProxy, ptr %8, i32 0, i32 2
  store i32 2, ptr %40, align 8, !tbaa !13
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = getelementptr inbounds %class.b2Shape, ptr %41, i32 0, i32 2
  %43 = load float, ptr %42, align 4, !tbaa !14
  %44 = getelementptr inbounds %struct.b2DistanceProxy, ptr %8, i32 0, i32 3
  store float %43, ptr %44, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %46

45:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 63, ptr noundef @__PRETTY_FUNCTION__._ZN15b2DistanceProxy3SetEPK7b2Shape) #5
  unreachable

46:                                               ; preds = %35, %21, %11
  ret void
}

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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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

attributes #0 = { 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { nounwind }
attributes #5 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"_ZTS15b2DistanceProxy", !7, i64 0, !6, i64 16, !11, i64 24, !12, i64 28}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!10, !11, i64 24}
!14 = !{!15, !12, i64 12}
!15 = !{!"_ZTS7b2Shape", !16, i64 8, !12, i64 12}
!16 = !{!"_ZTSN7b2Shape4TypeE", !7, i64 0}
!17 = !{!10, !12, i64 28}
!18 = !{!19, !11, i64 152}
!19 = !{!"_ZTS14b2PolygonShape", !15, i64 0, !20, i64 16, !7, i64 24, !7, i64 88, !11, i64 152}
!20 = !{!"_ZTS6b2Vec2", !12, i64 0, !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"

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [87 x i8], align 1
@__PRETTY_FUNCTION__._ZN15b2DistanceProxy3SetEPK7b2Shape = external hidden unnamed_addr constant [43 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN15b2DistanceProxy3SetEPK7b2Shape(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(32) %0, ptr noundef nonnull %1) local_unnamed_addr #0 align 2 {
  %3 = tail call noundef i32 @_ZNK7b2Shape7GetTypeEv(ptr noundef nonnull align 8 dereferenceable(16) %1)
  switch i32 %3, label %15 [
    i32 0, label %4
    i32 2, label %7
    i32 1, label %12
  ]

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %5, ptr %6, align 8, !tbaa !5
  br label %16

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %1, i64 24
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %8, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %1, i64 152
  %11 = load i32, ptr %10, align 8, !tbaa !12
  br label %16

12:                                               ; preds = %2
  %13 = getelementptr inbounds i8, ptr %1, i64 16
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %13, ptr %14, align 8, !tbaa !5
  br label %16

15:                                               ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 63, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN15b2DistanceProxy3SetEPK7b2Shape) #3
  unreachable

16:                                               ; preds = %12, %7, %4
  %.sink = phi i32 [ 2, %12 ], [ %11, %7 ], [ 1, %4 ]
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %.sink, ptr %17, align 8, !tbaa !17
  %18 = getelementptr inbounds i8, ptr %1, i64 12
  %19 = load float, ptr %18, align 4, !tbaa !18
  %20 = getelementptr inbounds i8, ptr %0, i64 28
  store float %19, ptr %20, align 4, !tbaa !19
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZNK7b2Shape7GetTypeEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #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 = { 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 = { 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 #3 = { 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, !9, i64 16}
!6 = !{!"_ZTS15b2DistanceProxy", !7, i64 0, !9, i64 16, !10, i64 24, !11, i64 28}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"float", !7, i64 0}
!12 = !{!13, !10, i64 152}
!13 = !{!"_ZTS14b2PolygonShape", !14, i64 0, !16, i64 16, !7, i64 24, !7, i64 88, !10, i64 152}
!14 = !{!"_ZTS7b2Shape", !15, i64 8, !11, i64 12}
!15 = !{!"_ZTSN7b2Shape4TypeE", !7, i64 0}
!16 = !{!"_ZTS6b2Vec2", !11, i64 0, !11, i64 4}
!17 = !{!6, !10, i64 24}
!18 = !{!14, !11, i64 12}
!19 = !{!6, !11, i64 28}


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