; 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.b2JointSim = type { i32, i32, i32, i32, %struct.b2Vec2, %struct.b2Vec2, float, float, float, float, %union.anon.0 }
%struct.b2Vec2 = type { float, float }
%union.anon.0 = 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 }

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @b2PrepareJoint(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.b2JointSim, ptr %5, i32 0, i32 3
  %7 = load i32, ptr %6, align 4, !tbaa !9
  switch i32 %7, label %29 [
    i32 0, label %8
    i32 2, label %11
    i32 3, label %14
    i32 1, label %36
    i32 4, label %17
    i32 5, label %20
    i32 6, label %23
    i32 7, label %26
  ]

8:                                                ; preds = %2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  call void @b2PrepareDistanceJoint(ptr noundef %9, ptr noundef %10)
  br label %36

11:                                               ; preds = %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  call void @b2PrepareMotorJoint(ptr noundef %12, ptr noundef %13)
  br label %36

14:                                               ; preds = %2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  call void @b2PrepareMouseJoint(ptr noundef %15, ptr noundef %16)
  br label %36

17:                                               ; preds = %2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  call void @b2PreparePrismaticJoint(ptr noundef %18, ptr noundef %19)
  br label %36

20:                                               ; preds = %2
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  call void @b2PrepareRevoluteJoint(ptr noundef %21, ptr noundef %22)
  br label %36

23:                                               ; preds = %2
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  call void @b2PrepareWeldJoint(ptr noundef %24, ptr noundef %25)
  br label %36

26:                                               ; preds = %2
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  call void @b2PrepareWheelJoint(ptr noundef %27, ptr noundef %28)
  br label %36

29:                                               ; preds = %2
  br label %30

30:                                               ; preds = %29
  %31 = call i32 @b2InternalAssertFcn(ptr noundef @.str.17, ptr noundef @.str.1, i32 noundef 1063)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %30
  call void @llvm.trap()
  br label %34

34:                                               ; preds = %33, %30
  br label %35

35:                                               ; preds = %34
  br label %36

36:                                               ; preds = %35, %26, %23, %20, %17, %14, %11, %8, %2
  ret void
}

declare void @b2PrepareDistanceJoint(ptr noundef, ptr noundef) #0

declare void @b2PrepareMotorJoint(ptr noundef, ptr noundef) #0

declare void @b2PrepareMouseJoint(ptr noundef, ptr noundef) #0

declare void @b2PreparePrismaticJoint(ptr noundef, ptr noundef) #0

declare void @b2PrepareRevoluteJoint(ptr noundef, ptr noundef) #0

declare void @b2PrepareWeldJoint(ptr noundef, ptr noundef) #0

declare void @b2PrepareWheelJoint(ptr noundef, ptr noundef) #0

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 = { cold noreturn nounwind memory(inaccessiblemem: write) }
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" }

!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, !11, i64 12}
!10 = !{!"b2JointSim", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !12, i64 16, !12, i64 24, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !7, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!"b2Vec2", !13, i64 0, !13, i64 4}
!13 = !{!"float", !7, 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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @b2PrepareJoint(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 12
  %4 = load i32, ptr %3, align 4, !tbaa !5
  switch i32 %4, label %12 [
    i32 0, label %5
    i32 2, label %6
    i32 3, label %7
    i32 1, label %15
    i32 4, label %8
    i32 5, label %9
    i32 6, label %10
    i32 7, label %11
  ]

5:                                                ; preds = %2
  tail call void @b2PrepareDistanceJoint(ptr noundef nonnull %0, ptr noundef %1) #3
  br label %15

6:                                                ; preds = %2
  tail call void @b2PrepareMotorJoint(ptr noundef nonnull %0, ptr noundef %1) #3
  br label %15

7:                                                ; preds = %2
  tail call void @b2PrepareMouseJoint(ptr noundef nonnull %0, ptr noundef %1) #3
  br label %15

8:                                                ; preds = %2
  tail call void @b2PreparePrismaticJoint(ptr noundef nonnull %0, ptr noundef %1) #3
  br label %15

9:                                                ; preds = %2
  tail call void @b2PrepareRevoluteJoint(ptr noundef nonnull %0, ptr noundef %1) #3
  br label %15

10:                                               ; preds = %2
  tail call void @b2PrepareWeldJoint(ptr noundef nonnull %0, ptr noundef %1) #3
  br label %15

11:                                               ; preds = %2
  tail call void @b2PrepareWheelJoint(ptr noundef nonnull %0, ptr noundef %1) #3
  br label %15

12:                                               ; preds = %2
  %13 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.17, ptr noundef nonnull @.str.1, i32 noundef 1063) #3
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %15, label %14

14:                                               ; preds = %12
  tail call void @llvm.trap()
  unreachable

15:                                               ; preds = %12, %11, %10, %9, %8, %7, %6, %5, %2
  ret void
}

declare void @b2PrepareDistanceJoint(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @b2PrepareMotorJoint(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @b2PrepareMouseJoint(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @b2PreparePrismaticJoint(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @b2PrepareRevoluteJoint(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @b2PrepareWeldJoint(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @b2PrepareWheelJoint(ptr noundef, ptr noundef) local_unnamed_addr #0

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 = { cold noreturn nounwind memory(inaccessiblemem: write) }
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, !7, i64 12}
!6 = !{!"b2JointSim", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !8, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"b2Vec2", !11, i64 0, !11, i64 4}
!11 = !{!"float", !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass