; LLVM IR from erincatto/box2d :: src (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.b2Joint = type { ptr, i32, i32, i32, [2 x %struct.b2JointEdge], i32, i32, i32, i32, float, i32, i16, i8, i8 }
%struct.b2JointEdge = type { i32, i32, i32 }

@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @b2GetJointFullId(ptr noundef, i64) #0

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

declare i32 @b2InternalAssertFcn(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: cold noreturn nounwind memory(inaccessiblemem: write)
declare void @llvm.trap() #3

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @b2GetJointSim(ptr noundef, ptr noundef) #0

declare ptr @b2GetWorld(i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local float @b2Joint_GetConstraintTorque(i64 %0) #0 {
  %2 = alloca float, align 4
  %3 = alloca %struct.b2JointId, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store i64 %0, ptr %3, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %8 = getelementptr inbounds %struct.b2JointId, ptr %3, i32 0, i32 1
  %9 = load i16, ptr %8, align 4, !tbaa !5
  %10 = zext i16 %9 to i32
  %11 = call ptr @b2GetWorld(i32 noundef %10)
  store ptr %11, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !11
  %13 = load i64, ptr %3, align 4
  %14 = call ptr @b2GetJointFullId(ptr noundef %12, i64 %13)
  store ptr %14, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %15 = load ptr, ptr %4, align 8, !tbaa !11
  %16 = load ptr, ptr %5, align 8, !tbaa !11
  %17 = call ptr @b2GetJointSim(ptr noundef %15, ptr noundef %16)
  store ptr %17, ptr %6, align 8, !tbaa !11
  %18 = load ptr, ptr %5, align 8, !tbaa !11
  %19 = getelementptr inbounds %struct.b2Joint, ptr %18, i32 0, i32 10
  %20 = load i32, ptr %19, align 8, !tbaa !13
  switch i32 %20, label %47 [
    i32 0, label %21
    i32 2, label %22
    i32 3, label %26
    i32 1, label %30
    i32 4, label %31
    i32 5, label %35
    i32 6, label %39
    i32 7, label %43
  ]

21:                                               ; preds = %1
  store float 0.000000e+00, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %55

22:                                               ; preds = %1
  %23 = load ptr, ptr %4, align 8, !tbaa !11
  %24 = load ptr, ptr %6, align 8, !tbaa !11
  %25 = call float @b2GetMotorJointTorque(ptr noundef %23, ptr noundef %24)
  store float %25, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %55

26:                                               ; preds = %1
  %27 = load ptr, ptr %4, align 8, !tbaa !11
  %28 = load ptr, ptr %6, align 8, !tbaa !11
  %29 = call float @b2GetMouseJointTorque(ptr noundef %27, ptr noundef %28)
  store float %29, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %55

30:                                               ; preds = %1
  store float 0.000000e+00, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %55

31:                                               ; preds = %1
  %32 = load ptr, ptr %4, align 8, !tbaa !11
  %33 = load ptr, ptr %6, align 8, !tbaa !11
  %34 = call float @b2GetPrismaticJointTorque(ptr noundef %32, ptr noundef %33)
  store float %34, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %55

35:                                               ; preds = %1
  %36 = load ptr, ptr %4, align 8, !tbaa !11
  %37 = load ptr, ptr %6, align 8, !tbaa !11
  %38 = call float @b2GetRevoluteJointTorque(ptr noundef %36, ptr noundef %37)
  store float %38, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %55

39:                                               ; preds = %1
  %40 = load ptr, ptr %4, align 8, !tbaa !11
  %41 = load ptr, ptr %6, align 8, !tbaa !11
  %42 = call float @b2GetWeldJointTorque(ptr noundef %40, ptr noundef %41)
  store float %42, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %55

43:                                               ; preds = %1
  %44 = load ptr, ptr %4, align 8, !tbaa !11
  %45 = load ptr, ptr %6, align 8, !tbaa !11
  %46 = call float @b2GetWheelJointTorque(ptr noundef %44, ptr noundef %45)
  store float %46, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %55

47:                                               ; preds = %1
  br label %48

48:                                               ; preds = %47
  %49 = call i32 @b2InternalAssertFcn(ptr noundef @.str.17, ptr noundef @.str.1, i32 noundef 1022)
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %48
  call void @llvm.trap()
  br label %52

52:                                               ; preds = %51, %48
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  store float 0.000000e+00, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %55

55:                                               ; preds = %54, %43, %39, %35, %31, %30, %26, %22, %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %56 = load float, ptr %2, align 4
  ret float %56
}

declare float @b2GetMotorJointTorque(ptr noundef, ptr noundef) #2

declare float @b2GetMouseJointTorque(ptr noundef, ptr noundef) #2

declare float @b2GetPrismaticJointTorque(ptr noundef, ptr noundef) #2

declare float @b2GetRevoluteJointTorque(ptr noundef, ptr noundef) #2

declare float @b2GetWeldJointTorque(ptr noundef, ptr noundef) #2

declare float @b2GetWheelJointTorque(ptr noundef, ptr noundef) #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 = { 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 = { cold noreturn nounwind memory(inaccessiblemem: write) }
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, !10, i64 4}
!6 = !{!"b2JointId", !7, i64 0, !10, i64 4, !10, i64 6}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!14, !7, i64 64}
!14 = !{!"b2Joint", !12, i64 0, !7, i64 8, !7, i64 12, !7, i64 16, !8, i64 20, !7, i64 44, !7, i64 48, !7, i64 52, !7, i64 56, !15, i64 60, !7, i64 64, !10, i64 68, !16, i64 70, !16, i64 71}
!15 = !{!"float", !8, i64 0}
!16 = !{!"_Bool", !8, i64 0}


; 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.1 = external hidden unnamed_addr constant [61 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @b2GetJointFullId(ptr noundef, i64) local_unnamed_addr #0

declare i32 @b2InternalAssertFcn(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: cold noreturn nounwind memory(inaccessiblemem: write)
declare void @llvm.trap() #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @b2GetJointSim(ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @b2GetWorld(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local float @b2Joint_GetConstraintTorque(i64 %0) local_unnamed_addr #0 {
  %.sroa.2.0.extract.shift = lshr i64 %0, 32
  %2 = trunc nuw i64 %.sroa.2.0.extract.shift to i32
  %3 = and i32 %2, 65535
  %4 = tail call ptr @b2GetWorld(i32 noundef %3) #3
  %5 = tail call ptr @b2GetJointFullId(ptr noundef %4, i64 %0)
  %6 = tail call ptr @b2GetJointSim(ptr noundef %4, ptr noundef %5)
  %7 = getelementptr inbounds i8, ptr %5, i64 64
  %8 = load i32, ptr %7, align 8, !tbaa !5
  switch i32 %8, label %21 [
    i32 0, label %24
    i32 2, label %9
    i32 3, label %11
    i32 1, label %24
    i32 4, label %13
    i32 5, label %15
    i32 6, label %17
    i32 7, label %19
  ]

9:                                                ; preds = %1
  %10 = tail call float @b2GetMotorJointTorque(ptr noundef %4, ptr noundef %6) #3
  br label %24

11:                                               ; preds = %1
  %12 = tail call float @b2GetMouseJointTorque(ptr noundef %4, ptr noundef %6) #3
  br label %24

13:                                               ; preds = %1
  %14 = tail call float @b2GetPrismaticJointTorque(ptr noundef %4, ptr noundef %6) #3
  br label %24

15:                                               ; preds = %1
  %16 = tail call float @b2GetRevoluteJointTorque(ptr noundef %4, ptr noundef %6) #3
  br label %24

17:                                               ; preds = %1
  %18 = tail call float @b2GetWeldJointTorque(ptr noundef %4, ptr noundef %6) #3
  br label %24

19:                                               ; preds = %1
  %20 = tail call float @b2GetWheelJointTorque(ptr noundef %4, ptr noundef %6) #3
  br label %24

21:                                               ; preds = %1
  %22 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.17, ptr noundef nonnull @.str.1, i32 noundef 1022) #3
  %.not = icmp eq i32 %22, 0
  br i1 %.not, label %24, label %23

23:                                               ; preds = %21
  tail call void @llvm.trap()
  unreachable

24:                                               ; preds = %21, %1, %1, %19, %17, %15, %13, %11, %9
  %.0 = phi float [ %20, %19 ], [ %18, %17 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ], [ %10, %9 ], [ 0.000000e+00, %1 ], [ 0.000000e+00, %1 ], [ 0.000000e+00, %21 ]
  ret float %.0
}

declare float @b2GetMotorJointTorque(ptr noundef, ptr noundef) local_unnamed_addr #1

declare float @b2GetMouseJointTorque(ptr noundef, ptr noundef) local_unnamed_addr #1

declare float @b2GetPrismaticJointTorque(ptr noundef, ptr noundef) local_unnamed_addr #1

declare float @b2GetRevoluteJointTorque(ptr noundef, ptr noundef) local_unnamed_addr #1

declare float @b2GetWeldJointTorque(ptr noundef, ptr noundef) local_unnamed_addr #1

declare float @b2GetWheelJointTorque(ptr noundef, ptr noundef) local_unnamed_addr #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 = { "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 = { cold noreturn nounwind memory(inaccessiblemem: write) }
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, !10, i64 64}
!6 = !{!"b2Joint", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !8, i64 20, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !11, i64 60, !10, i64 64, !12, i64 68, !13, i64 70, !13, i64 71}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"_Bool", !8, i64 0}


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