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

; 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.b2ShapeId = type { i32, i16, i16 }
%struct.b2BodyId = type { i32, i16, i16 }
%struct.b2Circle = type { %struct.b2Vec2, float }
%struct.b2Vec2 = type { float, float }
%struct.b2Capsule = type { %struct.b2Vec2, %struct.b2Vec2, float }

@b2_lengthUnitsPerMeter = external global float, align 4

; Function Attrs: nounwind uwtable
declare hidden i64 @b2CreateShape(i64, ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @b2CreateCapsuleShape(i64 %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca %struct.b2ShapeId, align 4
  %5 = alloca %struct.b2BodyId, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = alloca %struct.b2Circle, align 4
  %10 = alloca i32, align 4
  store i64 %0, ptr %5, align 4
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.b2Capsule, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.b2Capsule, ptr %13, i32 0, i32 1
  %15 = load <2 x float>, ptr %12, align 4
  %16 = load <2 x float>, ptr %14, align 4
  %17 = call float @b2DistanceSquared(<2 x float> %15, <2 x float> %16)
  store float %17, ptr %8, align 4, !tbaa !9
  %18 = load float, ptr %8, align 4, !tbaa !9
  %19 = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !9
  %20 = fmul float 0x3F747AE140000000, %19
  %21 = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !9
  %22 = fmul float 0x3F747AE140000000, %21
  %23 = fmul float %20, %22
  %24 = fcmp ole float %18, %23
  br i1 %24, label %25, label %41

25:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 12, ptr %9) #3
  %26 = getelementptr inbounds %struct.b2Circle, ptr %9, i32 0, i32 0
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.b2Capsule, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.b2Capsule, ptr %29, i32 0, i32 1
  %31 = load <2 x float>, ptr %28, align 4
  %32 = load <2 x float>, ptr %30, align 4
  %33 = call <2 x float> @b2Lerp(<2 x float> %31, <2 x float> %32, float noundef 5.000000e-01)
  store <2 x float> %33, ptr %26, align 4
  %34 = getelementptr inbounds %struct.b2Circle, ptr %9, i32 0, i32 1
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.b2Capsule, ptr %35, i32 0, i32 2
  %37 = load float, ptr %36, align 4, !tbaa !11
  store float %37, ptr %34, align 4, !tbaa !14
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load i64, ptr %5, align 4
  %40 = call i64 @b2CreateShape(i64 %39, ptr noundef %38, ptr noundef %9, i32 noundef 0)
  store i64 %40, ptr %4, align 4
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 12, ptr %9) #3
  br label %46

41:                                               ; preds = %3
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load i64, ptr %5, align 4
  %45 = call i64 @b2CreateShape(i64 %44, ptr noundef %42, ptr noundef %43, i32 noundef 1)
  store i64 %45, ptr %4, align 4
  store i32 1, ptr %10, align 4
  br label %46

46:                                               ; preds = %41, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %47 = load i64, ptr %4, align 4
  ret i64 %47
}

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

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

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync 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 }

!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, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"b2Capsule", !13, i64 0, !13, i64 8, !10, i64 16}
!13 = !{!"b2Vec2", !10, i64 0, !10, i64 4}
!14 = !{!15, !10, i64 8}
!15 = !{!"b2Circle", !13, i64 0, !10, i64 8}


; 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.b2Circle = type { %struct.b2Vec2, float }
%struct.b2Vec2 = type { float, float }

@b2_lengthUnitsPerMeter = external local_unnamed_addr global float, align 4

; Function Attrs: nounwind uwtable
declare hidden i64 @b2CreateShape(i64, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i64 @b2CreateCapsuleShape(i64 %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.b2Circle, align 8
  %5 = getelementptr inbounds i8, ptr %2, i64 8
  %6 = load <2 x float>, ptr %2, align 4
  %7 = load <2 x float>, ptr %5, align 4
  %8 = tail call float @b2DistanceSquared(<2 x float> %6, <2 x float> %7)
  %9 = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !5
  %10 = fmul float %9, 0x3F747AE140000000
  %11 = fmul float %10, %10
  %12 = fcmp ugt float %8, %11
  br i1 %12, label %21, label %13

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #3
  %14 = load <2 x float>, ptr %2, align 4
  %15 = load <2 x float>, ptr %5, align 4
  %16 = tail call <2 x float> @b2Lerp(<2 x float> %14, <2 x float> %15, float noundef 5.000000e-01)
  store <2 x float> %16, ptr %4, align 8
  %17 = getelementptr inbounds i8, ptr %4, i64 8
  %18 = getelementptr inbounds i8, ptr %2, i64 16
  %19 = load float, ptr %18, align 4, !tbaa !9
  store float %19, ptr %17, align 8, !tbaa !12
  %20 = call i64 @b2CreateShape(i64 %0, ptr noundef %1, ptr noundef nonnull %4, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #3
  br label %23

21:                                               ; preds = %3
  %22 = tail call i64 @b2CreateShape(i64 %0, ptr noundef %1, ptr noundef nonnull %2, i32 noundef 1)
  br label %23

23:                                               ; preds = %21, %13
  %.sroa.010.0 = phi i64 [ %20, %13 ], [ %22, %21 ]
  ret i64 %.sroa.010.0
}

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

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

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

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

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync 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 }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"b2Capsule", !11, i64 0, !11, i64 8, !6, i64 16}
!11 = !{!"b2Vec2", !6, i64 0, !6, i64 4}
!12 = !{!13, !6, i64 8}
!13 = !{!"b2Circle", !11, i64 0, !6, i64 8}


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