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

; 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.d2Constraint = type { ptr, ptr, ptr, %struct.d2Vec2, %struct.d2Vec2, ptr, ptr }
%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] }

declare void @_ZN16d2BlockAllocator4FreeEPvi(ptr noundef nonnull align 8 dereferenceable(128), ptr noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7d2World12DestroyJointEP12d2Constraint(ptr noundef nonnull align 8 dereferenceable(184) %0, ptr noundef %1) #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
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %class.d2Constraint, ptr %6, i32 0, i32 6
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %18

10:                                               ; preds = %2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %class.d2Constraint, ptr %11, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %class.d2Constraint, ptr %14, i32 0, i32 6
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds %class.d2Constraint, ptr %16, i32 0, i32 5
  store ptr %13, ptr %17, align 8, !tbaa !13
  br label %18

18:                                               ; preds = %10, %2
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %class.d2Constraint, ptr %19, i32 0, i32 5
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %31

23:                                               ; preds = %18
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %class.d2Constraint, ptr %24, i32 0, i32 6
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %class.d2Constraint, ptr %27, 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 %26, ptr %30, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %23, %18
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %class.d2World, ptr %5, i32 0, i32 5
  %34 = load ptr, ptr %33, align 8, !tbaa !14
  %35 = icmp eq ptr %32, %34
  br i1 %35, label %36, label %41

36:                                               ; preds = %31
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %class.d2Constraint, ptr %37, i32 0, i32 5
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = getelementptr inbounds %class.d2World, ptr %5, i32 0, i32 5
  store ptr %39, ptr %40, align 8, !tbaa !14
  br label %41

41:                                               ; preds = %36, %31
  %42 = getelementptr inbounds %class.d2World, ptr %5, i32 0, i32 6
  %43 = load i32, ptr %42, align 8, !tbaa !18
  %44 = add nsw i32 %43, -1
  store i32 %44, ptr %42, align 8, !tbaa !18
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load ptr, ptr %45, align 8, !tbaa !19
  %47 = getelementptr inbounds ptr, ptr %46, i64 0
  %48 = load ptr, ptr %47, align 8
  call void %48(ptr noundef nonnull align 8 dereferenceable(56) %45) #2
  %49 = getelementptr inbounds %class.d2World, ptr %5, i32 0, i32 2
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN16d2BlockAllocator4FreeEPvi(ptr noundef nonnull align 8 dereferenceable(128) %49, ptr noundef %50, i32 noundef 56)
  ret void
}

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"="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 = { 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 = !{!10, !6, i64 40}
!14 = !{!15, !6, i64 160}
!15 = !{!"_ZTS7d2World", !11, i64 0, !6, i64 8, !16, i64 16, !6, i64 144, !17, i64 152, !6, i64 160, !17, i64 168, !6, i64 176}
!16 = !{!"_ZTS16d2BlockAllocator", !6, i64 0, !17, i64 8, !17, i64 12, !7, i64 16}
!17 = !{!"int", !7, i64 0}
!18 = !{!15, !17, i64 168}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !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"

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7d2World12DestroyJointEP12d2Constraint(ptr noundef nonnull align 8 dereferenceable(184) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 48
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %.not = icmp eq ptr %4, null
  %.phi.trans.insert = getelementptr inbounds i8, ptr %1, i64 40
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !12
  br i1 %.not, label %._crit_edge, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %4, i64 40
  store ptr %.pre, ptr %6, align 8, !tbaa !12
  br label %._crit_edge

._crit_edge:                                      ; preds = %2, %5
  %.not12 = icmp eq ptr %.pre, null
  br i1 %.not12, label %9, label %7

7:                                                ; preds = %._crit_edge
  %8 = getelementptr inbounds i8, ptr %.pre, i64 48
  store ptr %4, ptr %8, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %7, %._crit_edge
  %10 = getelementptr inbounds i8, ptr %0, i64 160
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = icmp eq ptr %11, %1
  br i1 %12, label %13, label %14

13:                                               ; preds = %9
  store ptr %.pre, ptr %10, align 8, !tbaa !13
  br label %14

14:                                               ; preds = %13, %9
  %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
  %18 = load ptr, ptr %1, align 8, !tbaa !18
  %19 = load ptr, ptr %18, align 8
  tail call void %19(ptr noundef nonnull align 8 dereferenceable(56) %1) #2
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @_ZN16d2BlockAllocator4FreeEPvi(ptr noundef nonnull align 8 dereferenceable(128) %20, ptr noundef nonnull %1, i32 noundef 56)
  ret void
}

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"="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 = { 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 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 = !{!6, !7, i64 40}
!13 = !{!14, !7, i64 160}
!14 = !{!"_ZTS7d2World", !10, i64 0, !7, i64 8, !15, i64 16, !7, i64 144, !16, i64 152, !7, i64 160, !16, i64 168, !7, i64 176}
!15 = !{!"_ZTS16d2BlockAllocator", !7, i64 0, !16, i64 8, !16, i64 12, !8, i64 16}
!16 = !{!"int", !8, i64 0}
!17 = !{!14, !16, i64 168}
!18 = !{!19, !19, i64 0}
!19 = !{!"vtable pointer", !9, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass