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

; 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.b2JointId = type { i32, i16, i16 }
%struct.b2JointSim = type { i32, i32, i32, i32, %struct.b2Vec2, %struct.b2Vec2, float, float, float, float, %union.anon }
%struct.b2Vec2 = type { float, float }
%union.anon = type { %struct.b2PrismaticJoint }
%struct.b2PrismaticJoint = type { %struct.b2Vec2, %struct.b2Vec2, float, float, float, float, float, float, float, float, float, float, float, i32, i32, %struct.b2Vec2, %struct.b2Vec2, %struct.b2Vec2, %struct.b2Vec2, float, float, %struct.b2Softness, i8, i8, i8 }
%struct.b2Softness = type { float, float, float }
%struct.b2DistanceJoint = type { float, float, float, float, float, float, float, float, float, float, float, i32, i32, %struct.b2Vec2, %struct.b2Vec2, %struct.b2Vec2, %struct.b2Softness, float, i8, i8, i8 }

@b2_lengthUnitsPerMeter = external global float, align 4

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

declare ptr @b2GetJointSimCheckType(i64, i32 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @b2ClampFloat(float noundef, float noundef, float noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local void @b2DistanceJoint_SetLengthRange(i64 %0, float noundef %1, float noundef %2) #3 {
  %4 = alloca %struct.b2JointId, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store i64 %0, ptr %4, align 4
  store float %1, ptr %5, align 4, !tbaa !5
  store float %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %9 = load i64, ptr %4, align 4
  %10 = call ptr @b2GetJointSimCheckType(i64 %9, i32 noundef 0)
  store ptr %10, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %11 = load ptr, ptr %7, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.b2JointSim, ptr %11, i32 0, i32 10
  store ptr %12, ptr %8, align 8, !tbaa !9
  %13 = load float, ptr %5, align 4, !tbaa !5
  %14 = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !5
  %15 = fmul float 0x3F747AE140000000, %14
  %16 = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !5
  %17 = fmul float 1.000000e+05, %16
  %18 = call float @b2ClampFloat(float noundef %13, float noundef %15, float noundef %17)
  store float %18, ptr %5, align 4, !tbaa !5
  %19 = load float, ptr %6, align 4, !tbaa !5
  %20 = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !5
  %21 = fmul float 0x3F747AE140000000, %20
  %22 = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !5
  %23 = fmul float 1.000000e+05, %22
  %24 = call float @b2ClampFloat(float noundef %19, float noundef %21, float noundef %23)
  store float %24, ptr %6, align 4, !tbaa !5
  %25 = load float, ptr %5, align 4, !tbaa !5
  %26 = load float, ptr %6, align 4, !tbaa !5
  %27 = call float @b2MinFloat(float noundef %25, float noundef %26)
  %28 = load ptr, ptr %8, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.b2DistanceJoint, ptr %28, i32 0, i32 3
  store float %27, ptr %29, align 4, !tbaa !11
  %30 = load float, ptr %5, align 4, !tbaa !5
  %31 = load float, ptr %6, align 4, !tbaa !5
  %32 = call float @b2MaxFloat(float noundef %30, float noundef %31)
  %33 = load ptr, ptr %8, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.b2DistanceJoint, ptr %33, i32 0, i32 4
  store float %32, ptr %34, align 4, !tbaa !17
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.b2DistanceJoint, ptr %35, i32 0, i32 7
  store float 0.000000e+00, ptr %36, align 4, !tbaa !18
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.b2DistanceJoint, ptr %37, i32 0, i32 8
  store float 0.000000e+00, ptr %38, align 4, !tbaa !19
  %39 = load ptr, ptr %8, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.b2DistanceJoint, ptr %39, i32 0, i32 9
  store float 0.000000e+00, ptr %40, align 4, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @b2MinFloat(float noundef, float noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @b2MaxFloat(float noundef, float noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { inlinehint 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 #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, !6, i64 0}
!6 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 12}
!12 = !{!"b2DistanceJoint", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !13, i64 44, !13, i64 48, !14, i64 52, !14, i64 60, !14, i64 68, !15, i64 76, !6, i64 88, !16, i64 92, !16, i64 93, !16, i64 94}
!13 = !{!"int", !7, i64 0}
!14 = !{!"b2Vec2", !6, i64 0, !6, i64 4}
!15 = !{!"b2Softness", !6, i64 0, !6, i64 4, !6, i64 8}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!12, !6, i64 16}
!18 = !{!12, !6, i64 28}
!19 = !{!12, !6, i64 32}
!20 = !{!12, !6, i64 36}


; 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"

@b2_lengthUnitsPerMeter = external local_unnamed_addr global float, align 4

declare ptr @b2GetJointSimCheckType(i64, i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @b2ClampFloat(float noundef, float noundef, float noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @b2DistanceJoint_SetLengthRange(i64 %0, float noundef %1, float noundef %2) local_unnamed_addr #2 {
  %4 = tail call ptr @b2GetJointSimCheckType(i64 %0, i32 noundef 0) #3
  %5 = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !5
  %6 = fmul float %5, 0x3F747AE140000000
  %7 = fmul float %5, 1.000000e+05
  %8 = tail call float @b2ClampFloat(float noundef %1, float noundef %6, float noundef %7)
  %9 = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !5
  %10 = fmul float %9, 0x3F747AE140000000
  %11 = fmul float %9, 1.000000e+05
  %12 = tail call float @b2ClampFloat(float noundef %2, float noundef %10, float noundef %11)
  %13 = tail call float @b2MinFloat(float noundef %8, float noundef %12)
  %14 = getelementptr inbounds i8, ptr %4, i64 60
  store float %13, ptr %14, align 4, !tbaa !9
  %15 = tail call float @b2MaxFloat(float noundef %8, float noundef %12)
  %16 = getelementptr inbounds i8, ptr %4, i64 64
  store float %15, ptr %16, align 4, !tbaa !15
  %17 = getelementptr inbounds i8, ptr %4, i64 76
  store <2 x float> zeroinitializer, ptr %17, align 4, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %4, i64 84
  store float 0.000000e+00, ptr %18, align 4, !tbaa !16
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @b2MinFloat(float noundef, float noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden float @b2MaxFloat(float noundef, float noundef) local_unnamed_addr #1

attributes #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 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 = { 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 #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 12}
!10 = !{!"b2DistanceJoint", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !11, i64 44, !11, i64 48, !12, i64 52, !12, i64 60, !12, i64 68, !13, i64 76, !6, i64 88, !14, i64 92, !14, i64 93, !14, i64 94}
!11 = !{!"int", !7, i64 0}
!12 = !{!"b2Vec2", !6, i64 0, !6, i64 4}
!13 = !{!"b2Softness", !6, i64 0, !6, i64 4, !6, i64 8}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!10, !6, i64 16}
!16 = !{!10, !6, i64 36}


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