; LLVM IR from mtsamis/box2d-optimized :: src/dynamics/b2_joint.ll (ZN7b2JointC2EPK10b2JointDef)

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

%class.b2Joint = type { ptr, i32, ptr, ptr, %struct.b2JointEdge, %struct.b2JointEdge, ptr, ptr, i32, i8, i8, %struct.b2JointUserData }
%struct.b2JointEdge = type { ptr, ptr, ptr, ptr }
%struct.b2JointUserData = type { i64 }
%struct.b2JointDef = type <{ i32, [4 x i8], %struct.b2JointUserData, ptr, ptr, i8, [7 x i8] }>

@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@_ZTV7b2Joint = external dso_local unnamed_addr constant { [14 x ptr] }, align 8
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1
@__PRETTY_FUNCTION__._ZN7b2JointC2EPK10b2JointDef = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7b2JointC2EPK10b2JointDef(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr noundef %1) unnamed_addr #1 align 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
  store ptr getelementptr inbounds inrange(-16, 96) ({ [14 x ptr] }, ptr @_ZTV7b2Joint, i32 0, i32 0, i32 2), ptr %5, align 8, !tbaa !9
  %6 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 4
  %7 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 5
  %8 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 11
  call void @_ZN15b2JointUserDataC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %8)
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.b2JointDef, ptr %9, i32 0, i32 3
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.b2JointDef, ptr %12, i32 0, i32 4
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = icmp ne ptr %11, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  br label %19

17:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 227, ptr noundef @__PRETTY_FUNCTION__._ZN7b2JointC2EPK10b2JointDef) #4
  unreachable

18:                                               ; No predecessors!
  br label %19

19:                                               ; preds = %18, %16
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.b2JointDef, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !18
  %23 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 1
  store i32 %22, ptr %23, align 8, !tbaa !19
  %24 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 2
  store ptr null, ptr %24, align 8, !tbaa !23
  %25 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 3
  store ptr null, ptr %25, align 8, !tbaa !24
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.b2JointDef, ptr %26, i32 0, i32 3
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 6
  store ptr %28, ptr %29, align 8, !tbaa !25
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.b2JointDef, ptr %30, i32 0, i32 4
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 7
  store ptr %32, ptr %33, align 8, !tbaa !26
  %34 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 8
  store i32 0, ptr %34, align 8, !tbaa !27
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.b2JointDef, ptr %35, i32 0, i32 5
  %37 = load i8, ptr %36, align 8, !tbaa !28, !range !29, !noundef !30
  %38 = trunc i8 %37 to i1
  %39 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 10
  %40 = zext i1 %38 to i8
  store i8 %40, ptr %39, align 1, !tbaa !31
  %41 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 9
  store i8 0, ptr %41, align 4, !tbaa !32
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.b2JointDef, ptr %42, i32 0, i32 2
  %44 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 11
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %44, ptr align 8 %43, i64 8, i1 false), !tbaa.struct !33
  %45 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 4
  %46 = getelementptr inbounds %struct.b2JointEdge, ptr %45, i32 0, i32 1
  store ptr null, ptr %46, align 8, !tbaa !35
  %47 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 4
  %48 = getelementptr inbounds %struct.b2JointEdge, ptr %47, i32 0, i32 0
  store ptr null, ptr %48, align 8, !tbaa !36
  %49 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 4
  %50 = getelementptr inbounds %struct.b2JointEdge, ptr %49, i32 0, i32 2
  store ptr null, ptr %50, align 8, !tbaa !37
  %51 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 4
  %52 = getelementptr inbounds %struct.b2JointEdge, ptr %51, i32 0, i32 3
  store ptr null, ptr %52, align 8, !tbaa !38
  %53 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 5
  %54 = getelementptr inbounds %struct.b2JointEdge, ptr %53, i32 0, i32 1
  store ptr null, ptr %54, align 8, !tbaa !39
  %55 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 5
  %56 = getelementptr inbounds %struct.b2JointEdge, ptr %55, i32 0, i32 0
  store ptr null, ptr %56, align 8, !tbaa !40
  %57 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 5
  %58 = getelementptr inbounds %struct.b2JointEdge, ptr %57, i32 0, i32 2
  store ptr null, ptr %58, align 8, !tbaa !41
  %59 = getelementptr inbounds %class.b2Joint, ptr %5, i32 0, i32 5
  %60 = getelementptr inbounds %struct.b2JointEdge, ptr %59, i32 0, i32 3
  store ptr null, ptr %60, align 8, !tbaa !42
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN15b2JointUserDataC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { noreturn nounwind "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 = { mustprogress 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 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { noreturn 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS10b2JointDef", !13, i64 0, !14, i64 8, !6, i64 16, !6, i64 24, !16, i64 32}
!13 = !{!"_ZTS11b2JointType", !7, i64 0}
!14 = !{!"_ZTS15b2JointUserData", !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"bool", !7, i64 0}
!17 = !{!12, !6, i64 24}
!18 = !{!12, !13, i64 0}
!19 = !{!20, !13, i64 8}
!20 = !{!"_ZTS7b2Joint", !13, i64 8, !6, i64 16, !6, i64 24, !21, i64 32, !21, i64 64, !6, i64 96, !6, i64 104, !22, i64 112, !16, i64 116, !16, i64 117, !14, i64 120}
!21 = !{!"_ZTS11b2JointEdge", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!22 = !{!"int", !7, i64 0}
!23 = !{!20, !6, i64 16}
!24 = !{!20, !6, i64 24}
!25 = !{!20, !6, i64 96}
!26 = !{!20, !6, i64 104}
!27 = !{!20, !22, i64 112}
!28 = !{!12, !16, i64 32}
!29 = !{i8 0, i8 2}
!30 = !{}
!31 = !{!20, !16, i64 117}
!32 = !{!20, !16, i64 116}
!33 = !{i64 0, i64 8, !34}
!34 = !{!15, !15, i64 0}
!35 = !{!20, !6, i64 40}
!36 = !{!20, !6, i64 32}
!37 = !{!20, !6, i64 48}
!38 = !{!20, !6, i64 56}
!39 = !{!20, !6, i64 72}
!40 = !{!20, !6, i64 64}
!41 = !{!20, !6, i64 80}
!42 = !{!20, !6, i64 88}


; 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 [83 x i8], align 1
@_ZTV7b2Joint = external dso_local unnamed_addr constant { [14 x ptr] }, align 8
@.str.2 = external hidden unnamed_addr constant [25 x i8], align 1
@__PRETTY_FUNCTION__._ZN7b2JointC2EPK10b2JointDef = external hidden unnamed_addr constant [37 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7b2JointC2EPK10b2JointDef(ptr noundef nonnull align 8 dereferenceable(128) %0, ptr nocapture noundef readonly %1) unnamed_addr #1 align 2 {
  store ptr getelementptr inbounds inrange(-16, 96) (i8, ptr @_ZTV7b2Joint, i64 16), ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 120
  tail call void @_ZN15b2JointUserDataC2Ev(ptr noundef nonnull align 8 dereferenceable(8) %3)
  %4 = getelementptr inbounds i8, ptr %1, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !8
  %6 = getelementptr inbounds i8, ptr %1, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !16
  %.not = icmp eq ptr %5, %7
  br i1 %.not, label %8, label %9

8:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 227, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN7b2JointC2EPK10b2JointDef) #3
  unreachable

9:                                                ; preds = %2
  %10 = load i32, ptr %1, align 8, !tbaa !17
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %10, ptr %11, align 8, !tbaa !18
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = getelementptr inbounds i8, ptr %0, i64 96
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %12, i8 0, i64 16, i1 false)
  store ptr %5, ptr %13, align 8, !tbaa !22
  %14 = getelementptr inbounds i8, ptr %0, i64 104
  store ptr %7, ptr %14, align 8, !tbaa !23
  %15 = getelementptr inbounds i8, ptr %0, i64 112
  store i32 0, ptr %15, align 8, !tbaa !24
  %16 = getelementptr inbounds i8, ptr %1, i64 32
  %17 = load i8, ptr %16, align 8, !tbaa !25, !range !26, !noundef !27
  %18 = getelementptr inbounds i8, ptr %0, i64 117
  store i8 %17, ptr %18, align 1, !tbaa !28
  %19 = getelementptr inbounds i8, ptr %0, i64 116
  store i8 0, ptr %19, align 4, !tbaa !29
  %20 = getelementptr inbounds i8, ptr %1, i64 8
  %21 = load i64, ptr %20, align 8, !tbaa !30
  store i64 %21, ptr %3, align 8, !tbaa !30
  %22 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(64) %22, i8 0, i64 64, i1 false)
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN15b2JointUserDataC2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #1 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { noreturn nounwind "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 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { noreturn 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !14, i64 16}
!9 = !{!"_ZTS10b2JointDef", !10, i64 0, !12, i64 8, !14, i64 16, !14, i64 24, !15, i64 32}
!10 = !{!"_ZTS11b2JointType", !11, i64 0}
!11 = !{!"omnipotent char", !7, i64 0}
!12 = !{!"_ZTS15b2JointUserData", !13, i64 0}
!13 = !{!"long", !11, i64 0}
!14 = !{!"any pointer", !11, i64 0}
!15 = !{!"bool", !11, i64 0}
!16 = !{!9, !14, i64 24}
!17 = !{!9, !10, i64 0}
!18 = !{!19, !10, i64 8}
!19 = !{!"_ZTS7b2Joint", !10, i64 8, !14, i64 16, !14, i64 24, !20, i64 32, !20, i64 64, !14, i64 96, !14, i64 104, !21, i64 112, !15, i64 116, !15, i64 117, !12, i64 120}
!20 = !{!"_ZTS11b2JointEdge", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24}
!21 = !{!"int", !11, i64 0}
!22 = !{!19, !14, i64 96}
!23 = !{!19, !14, i64 104}
!24 = !{!19, !21, i64 112}
!25 = !{!9, !15, i64 32}
!26 = !{i8 0, i8 2}
!27 = !{}
!28 = !{!19, !15, i64 117}
!29 = !{!19, !15, i64 116}
!30 = !{!13, !13, i64 0}


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