; 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 @b2SolveJoint(ptr noundef %0, ptr noundef %1, i1 noundef zeroext %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %7 = zext i1 %2 to i8
  store i8 %7, ptr %6, align 1, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.b2JointSim, ptr %8, i32 0, i32 3
  %10 = load i32, ptr %9, align 4, !tbaa !11
  switch i32 %10, label %44 [
    i32 0, label %11
    i32 2, label %16
    i32 3, label %21
    i32 1, label %51
    i32 4, label %24
    i32 5, label %29
    i32 6, label %34
    i32 7, label %39
  ]

11:                                               ; preds = %3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load i8, ptr %6, align 1, !tbaa !9, !range !16, !noundef !17
  %15 = trunc i8 %14 to i1
  call void @b2SolveDistanceJoint(ptr noundef %12, ptr noundef %13, i1 noundef zeroext %15)
  br label %51

16:                                               ; preds = %3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load i8, ptr %6, align 1, !tbaa !9, !range !16, !noundef !17
  %20 = trunc i8 %19 to i1
  call void @b2SolveMotorJoint(ptr noundef %17, ptr noundef %18, i1 noundef zeroext %20)
  br label %51

21:                                               ; preds = %3
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  call void @b2SolveMouseJoint(ptr noundef %22, ptr noundef %23)
  br label %51

24:                                               ; preds = %3
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i8, ptr %6, align 1, !tbaa !9, !range !16, !noundef !17
  %28 = trunc i8 %27 to i1
  call void @b2SolvePrismaticJoint(ptr noundef %25, ptr noundef %26, i1 noundef zeroext %28)
  br label %51

29:                                               ; preds = %3
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i8, ptr %6, align 1, !tbaa !9, !range !16, !noundef !17
  %33 = trunc i8 %32 to i1
  call void @b2SolveRevoluteJoint(ptr noundef %30, ptr noundef %31, i1 noundef zeroext %33)
  br label %51

34:                                               ; preds = %3
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i8, ptr %6, align 1, !tbaa !9, !range !16, !noundef !17
  %38 = trunc i8 %37 to i1
  call void @b2SolveWeldJoint(ptr noundef %35, ptr noundef %36, i1 noundef zeroext %38)
  br label %51

39:                                               ; preds = %3
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i8, ptr %6, align 1, !tbaa !9, !range !16, !noundef !17
  %43 = trunc i8 %42 to i1
  call void @b2SolveWheelJoint(ptr noundef %40, ptr noundef %41, i1 noundef zeroext %43)
  br label %51

44:                                               ; preds = %3
  br label %45

45:                                               ; preds = %44
  %46 = call i32 @b2InternalAssertFcn(ptr noundef @.str.17, ptr noundef @.str.1, i32 noundef 1143)
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %49

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

49:                                               ; preds = %48, %45
  br label %50

50:                                               ; preds = %49
  br label %51

51:                                               ; preds = %50, %39, %34, %29, %24, %21, %16, %11, %3
  ret void
}

declare void @b2SolveDistanceJoint(ptr noundef, ptr noundef, i1 noundef zeroext) #0

declare void @b2SolveMotorJoint(ptr noundef, ptr noundef, i1 noundef zeroext) #0

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

declare void @b2SolvePrismaticJoint(ptr noundef, ptr noundef, i1 noundef zeroext) #0

declare void @b2SolveRevoluteJoint(ptr noundef, ptr noundef, i1 noundef zeroext) #0

declare void @b2SolveWeldJoint(ptr noundef, ptr noundef, i1 noundef zeroext) #0

declare void @b2SolveWheelJoint(ptr noundef, ptr noundef, i1 noundef zeroext) #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, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !13, i64 12}
!12 = !{!"b2JointSim", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !14, i64 16, !14, i64 24, !15, i64 32, !15, i64 36, !15, i64 40, !15, i64 44, !7, i64 48}
!13 = !{!"int", !7, i64 0}
!14 = !{!"b2Vec2", !15, i64 0, !15, i64 4}
!15 = !{!"float", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}


; 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 @b2SolveJoint(ptr noundef %0, ptr noundef %1, i1 noundef zeroext %2) local_unnamed_addr #2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %5 = load i32, ptr %4, align 4, !tbaa !5
  switch i32 %5, label %13 [
    i32 0, label %6
    i32 2, label %7
    i32 3, label %8
    i32 1, label %16
    i32 4, label %9
    i32 5, label %10
    i32 6, label %11
    i32 7, label %12
  ]

6:                                                ; preds = %3
  tail call void @b2SolveDistanceJoint(ptr noundef nonnull %0, ptr noundef %1, i1 noundef zeroext %2) #3
  br label %16

7:                                                ; preds = %3
  tail call void @b2SolveMotorJoint(ptr noundef nonnull %0, ptr noundef %1, i1 noundef zeroext %2) #3
  br label %16

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

9:                                                ; preds = %3
  tail call void @b2SolvePrismaticJoint(ptr noundef nonnull %0, ptr noundef %1, i1 noundef zeroext %2) #3
  br label %16

10:                                               ; preds = %3
  tail call void @b2SolveRevoluteJoint(ptr noundef nonnull %0, ptr noundef %1, i1 noundef zeroext %2) #3
  br label %16

11:                                               ; preds = %3
  tail call void @b2SolveWeldJoint(ptr noundef nonnull %0, ptr noundef %1, i1 noundef zeroext %2) #3
  br label %16

12:                                               ; preds = %3
  tail call void @b2SolveWheelJoint(ptr noundef nonnull %0, ptr noundef %1, i1 noundef zeroext %2) #3
  br label %16

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

15:                                               ; preds = %13
  tail call void @llvm.trap()
  unreachable

16:                                               ; preds = %13, %12, %11, %10, %9, %8, %7, %6, %3
  ret void
}

declare void @b2SolveDistanceJoint(ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

declare void @b2SolveMotorJoint(ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

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

declare void @b2SolvePrismaticJoint(ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

declare void @b2SolveRevoluteJoint(ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

declare void @b2SolveWeldJoint(ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

declare void @b2SolveWheelJoint(ptr noundef, ptr noundef, i1 noundef zeroext) 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,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass