; 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: nounwind uwtable
define dso_local void @b2DistanceJoint_SetLength(i64 %0, float noundef %1) #0 {
  %3 = alloca %struct.b2JointId, align 4
  %4 = alloca float, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store i64 %0, ptr %3, align 4
  store float %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %7 = load i64, ptr %3, align 4
  %8 = call ptr @b2GetJointSimCheckType(i64 %7, i32 noundef 0)
  store ptr %8, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %9 = load ptr, ptr %5, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.b2JointSim, ptr %9, i32 0, i32 10
  store ptr %10, ptr %6, align 8, !tbaa !9
  %11 = load float, ptr %4, align 4, !tbaa !5
  %12 = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !5
  %13 = fmul float 0x3F747AE140000000, %12
  %14 = load float, ptr @b2_lengthUnitsPerMeter, align 4, !tbaa !5
  %15 = fmul float 1.000000e+05, %14
  %16 = call float @b2ClampFloat(float noundef %11, float noundef %13, float noundef %15)
  %17 = load ptr, ptr %6, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.b2DistanceJoint, ptr %17, i32 0, i32 0
  store float %16, ptr %18, align 4, !tbaa !11
  %19 = load ptr, ptr %6, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.b2DistanceJoint, ptr %19, i32 0, i32 7
  store float 0.000000e+00, ptr %20, align 4, !tbaa !17
  %21 = load ptr, ptr %6, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.b2DistanceJoint, ptr %21, i32 0, i32 8
  store float 0.000000e+00, ptr %22, align 4, !tbaa !18
  %23 = load ptr, ptr %6, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.b2DistanceJoint, ptr %23, i32 0, i32 9
  store float 0.000000e+00, ptr %24, align 4, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

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

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

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

; 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"="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 = { nocallback nofree nosync 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 = { 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 #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 0}
!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 28}
!18 = !{!12, !6, i64 32}
!19 = !{!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

; Function Attrs: nounwind uwtable
define dso_local void @b2DistanceJoint_SetLength(i64 %0, float noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @b2GetJointSimCheckType(i64 %0, i32 noundef 0) #3
  %4 = getelementptr inbounds i8, ptr %3, i64 48
  %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)
  store float %8, ptr %4, align 4, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %3, i64 76
  store <2 x float> zeroinitializer, ptr %9, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %3, i64 84
  store float 0.000000e+00, ptr %10, align 4, !tbaa !15
  ret void
}

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

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

attributes #0 = { 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 = { "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 }

!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 0}
!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 36}


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