; LLVM IR from SOHNE/Dura2D :: src/kinetics/d2World.ll (ZN7d2World11CreateJointEP6d2BodyS1_6d2Vec2)

; 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.d2Vec2 = type { float, float }
%class.d2World = type { %struct.d2Vec2, ptr, %class.d2BlockAllocator, ptr, i32, ptr, i32, ptr }
%class.d2BlockAllocator = type { ptr, i32, i32, [14 x ptr] }
%class.d2Constraint = type { ptr, ptr, ptr, %struct.d2Vec2, %struct.d2Vec2, ptr, ptr }

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

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

declare noundef ptr @_ZN16d2BlockAllocator8AllocateEi(ptr noundef nonnull align 8 dereferenceable(128), i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN7d2World11CreateJointEP6d2BodyS1_6d2Vec2(ptr noundef nonnull align 8 dereferenceable(184) %0, ptr noundef %1, ptr noundef %2, <2 x float> %3) #2 align 2 {
  %5 = alloca %struct.d2Vec2, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store <2 x float> %3, ptr %5, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %12 = getelementptr inbounds %class.d2World, ptr %11, i32 0, i32 2
  %13 = call noundef ptr @_ZN16d2BlockAllocator8AllocateEi(ptr noundef nonnull align 8 dereferenceable(128) %12, i32 noundef 96)
  store ptr %13, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  call void @_ZN17d2JointConstraintC1EP6d2BodyS1_RK6d2Vec2(ptr noundef nonnull align 8 dereferenceable(92) %14, ptr noundef %15, ptr noundef %16, ptr noundef nonnull align 4 dereferenceable(8) %5)
  store ptr %14, ptr %10, align 8, !tbaa !5
  %17 = load ptr, ptr %10, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.d2Constraint, ptr %17, i32 0, i32 6
  store ptr null, ptr %18, align 8, !tbaa !9
  %19 = getelementptr inbounds %class.d2World, ptr %11, i32 0, i32 5
  %20 = load ptr, ptr %19, align 8, !tbaa !13
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = getelementptr inbounds %class.d2Constraint, ptr %21, i32 0, i32 5
  store ptr %20, ptr %22, align 8, !tbaa !17
  %23 = getelementptr inbounds %class.d2World, ptr %11, i32 0, i32 5
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %31

26:                                               ; preds = %4
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = getelementptr inbounds %class.d2World, ptr %11, i32 0, i32 5
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = getelementptr inbounds %class.d2Constraint, ptr %29, i32 0, i32 6
  store ptr %27, ptr %30, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %26, %4
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = getelementptr inbounds %class.d2World, ptr %11, i32 0, i32 5
  store ptr %32, ptr %33, align 8, !tbaa !13
  %34 = getelementptr inbounds %class.d2World, ptr %11, i32 0, i32 6
  %35 = load i32, ptr %34, align 8, !tbaa !18
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %34, align 8, !tbaa !18
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret ptr %37
}

declare void @_ZN17d2JointConstraintC1EP6d2BodyS1_RK6d2Vec2(ptr noundef nonnull align 8 dereferenceable(92), ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(8)) unnamed_addr #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 48}
!10 = !{!"_ZTS12d2Constraint", !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 32, !6, i64 40, !6, i64 48}
!11 = !{!"_ZTS6d2Vec2", !12, i64 0, !12, i64 4}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !6, i64 160}
!14 = !{!"_ZTS7d2World", !11, i64 0, !6, i64 8, !15, i64 16, !6, i64 144, !16, i64 152, !6, i64 160, !16, i64 168, !6, i64 176}
!15 = !{!"_ZTS16d2BlockAllocator", !6, i64 0, !16, i64 8, !16, i64 12, !7, i64 16}
!16 = !{!"int", !7, i64 0}
!17 = !{!10, !6, i64 40}
!18 = !{!14, !16, i64 168}


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

%struct.d2Vec2 = type { float, float }

declare noundef ptr @_ZN16d2BlockAllocator8AllocateEi(ptr noundef nonnull align 8 dereferenceable(128), i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN7d2World11CreateJointEP6d2BodyS1_6d2Vec2(ptr noundef nonnull align 8 dereferenceable(184) %0, ptr noundef %1, ptr noundef %2, <2 x float> %3) local_unnamed_addr #1 align 2 {
  %5 = alloca %struct.d2Vec2, align 8
  store <2 x float> %3, ptr %5, align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = tail call noundef ptr @_ZN16d2BlockAllocator8AllocateEi(ptr noundef nonnull align 8 dereferenceable(128) %6, i32 noundef 96)
  call void @_ZN17d2JointConstraintC1EP6d2BodyS1_RK6d2Vec2(ptr noundef nonnull align 8 dereferenceable(92) %7, ptr noundef %1, ptr noundef %2, ptr noundef nonnull align 4 dereferenceable(8) %5)
  %8 = getelementptr inbounds i8, ptr %7, i64 48
  store ptr null, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 160
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %7, i64 40
  store ptr %10, ptr %11, align 8, !tbaa !16
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %14, label %12

12:                                               ; preds = %4
  %13 = getelementptr inbounds i8, ptr %10, i64 48
  store ptr %7, ptr %13, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %12, %4
  store ptr %7, ptr %9, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %0, i64 168
  %16 = load i32, ptr %15, align 8, !tbaa !17
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %15, align 8, !tbaa !17
  ret ptr %7
}

declare void @_ZN17d2JointConstraintC1EP6d2BodyS1_RK6d2Vec2(ptr noundef nonnull align 8 dereferenceable(92), ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(8)) 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 = { mustprogress uwtable "min-legal-vector-width"="64" "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, !7, i64 48}
!6 = !{!"_ZTS12d2Constraint", !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS6d2Vec2", !11, i64 0, !11, i64 4}
!11 = !{!"float", !8, i64 0}
!12 = !{!13, !7, i64 160}
!13 = !{!"_ZTS7d2World", !10, i64 0, !7, i64 8, !14, i64 16, !7, i64 144, !15, i64 152, !7, i64 160, !15, i64 168, !7, i64 176}
!14 = !{!"_ZTS16d2BlockAllocator", !7, i64 0, !15, i64 8, !15, i64 12, !8, i64 16}
!15 = !{!"int", !8, i64 0}
!16 = !{!6, !7, i64 40}
!17 = !{!13, !15, i64 168}


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