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

; 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.d2World = type { %struct.d2Vec2, ptr, %class.d2BlockAllocator, ptr, i32, ptr, i32, ptr }
%struct.d2Vec2 = type { float, float }
%class.d2BlockAllocator = type { ptr, i32, i32, [14 x ptr] }
%class.d2Body = type <{ i16, [2 x i8], i32, %struct.d2Transform, %struct.d2Vec2, %struct.d2Vec2, float, float, float, %struct.d2Vec2, float, float, float, float, float, float, float, ptr, ptr, ptr, ptr, ptr, float, [4 x i8] }>
%struct.d2Transform = type { %struct.d2Vec2, %struct.d2Rot }
%struct.d2Rot = type { float, float }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7d2World11DestroyBodyEP6d2Body(ptr noundef nonnull align 8 dereferenceable(184) %0, ptr noundef %1) #0 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 = getelementptr inbounds %class.d2World, ptr %5, i32 0, i32 1
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = load ptr, ptr %7, align 8, !tbaa !15
  %10 = getelementptr inbounds ptr, ptr %9, i64 3
  %11 = load ptr, ptr %10, align 8
  call void %11(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef %8)
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %class.d2Body, ptr %12, i32 0, i32 20
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %24

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.d2Body, ptr %17, i32 0, i32 21
  %19 = load ptr, ptr %18, align 8, !tbaa !23
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %class.d2Body, ptr %20, i32 0, i32 20
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = getelementptr inbounds %class.d2Body, ptr %22, i32 0, i32 21
  store ptr %19, ptr %23, align 8, !tbaa !23
  br label %24

24:                                               ; preds = %16, %2
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %class.d2Body, ptr %25, i32 0, i32 21
  %27 = load ptr, ptr %26, align 8, !tbaa !23
  %28 = icmp ne ptr %27, null
  br i1 %28, label %29, label %37

29:                                               ; preds = %24
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %class.d2Body, ptr %30, i32 0, i32 20
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %class.d2Body, ptr %33, i32 0, i32 21
  %35 = load ptr, ptr %34, align 8, !tbaa !23
  %36 = getelementptr inbounds %class.d2Body, ptr %35, i32 0, i32 20
  store ptr %32, ptr %36, align 8, !tbaa !17
  br label %37

37:                                               ; preds = %29, %24
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %class.d2World, ptr %5, i32 0, i32 3
  %40 = load ptr, ptr %39, align 8, !tbaa !24
  %41 = icmp eq ptr %38, %40
  br i1 %41, label %42, label %47

42:                                               ; preds = %37
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %class.d2Body, ptr %43, i32 0, i32 21
  %45 = load ptr, ptr %44, align 8, !tbaa !23
  %46 = getelementptr inbounds %class.d2World, ptr %5, i32 0, i32 3
  store ptr %45, ptr %46, align 8, !tbaa !24
  br label %47

47:                                               ; preds = %42, %37
  %48 = getelementptr inbounds %class.d2World, ptr %5, i32 0, i32 4
  %49 = load i32, ptr %48, align 8, !tbaa !25
  %50 = add nsw i32 %49, -1
  store i32 %50, ptr %48, align 8, !tbaa !25
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN6d2BodyD1Ev(ptr noundef nonnull align 8 dereferenceable(132) %51) #3
  %52 = getelementptr inbounds %class.d2World, ptr %5, i32 0, i32 2
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN16d2BlockAllocator4FreeEPvi(ptr noundef nonnull align 8 dereferenceable(128) %52, ptr noundef %53, i32 noundef 136)
  ret void
}

; Function Attrs: nounwind
declare void @_ZN6d2BodyD1Ev(ptr noundef nonnull align 8 dereferenceable(132)) unnamed_addr #1

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

attributes #0 = { 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 #1 = { 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 #2 = { "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 8}
!10 = !{!"_ZTS7d2World", !11, i64 0, !6, i64 8, !13, i64 16, !6, i64 144, !14, i64 152, !6, i64 160, !14, i64 168, !6, i64 176}
!11 = !{!"_ZTS6d2Vec2", !12, i64 0, !12, i64 4}
!12 = !{!"float", !7, i64 0}
!13 = !{!"_ZTS16d2BlockAllocator", !6, i64 0, !14, i64 8, !14, i64 12, !7, i64 16}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !8, i64 0}
!17 = !{!18, !6, i64 112}
!18 = !{!"_ZTS6d2Body", !19, i64 0, !20, i64 4, !21, i64 8, !11, i64 24, !11, i64 32, !12, i64 40, !12, i64 44, !12, i64 48, !11, i64 52, !12, i64 60, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !12, i64 80, !12, i64 84, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !12, i64 128}
!19 = !{!"short", !7, i64 0}
!20 = !{!"_ZTS10d2BodyType", !7, i64 0}
!21 = !{!"_ZTS11d2Transform", !11, i64 0, !22, i64 8}
!22 = !{!"_ZTS5d2Rot", !12, i64 0, !12, i64 4}
!23 = !{!18, !6, i64 120}
!24 = !{!10, !6, i64 144}
!25 = !{!10, !14, i64 152}


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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7d2World11DestroyBodyEP6d2Body(ptr noundef nonnull align 8 dereferenceable(184) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr %4, align 8, !tbaa !14
  %6 = getelementptr inbounds i8, ptr %5, i64 24
  %7 = load ptr, ptr %6, align 8
  tail call void %7(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef %1)
  %8 = getelementptr inbounds i8, ptr %1, i64 112
  %9 = load ptr, ptr %8, align 8, !tbaa !16
  %.not = icmp eq ptr %9, null
  %.phi.trans.insert = getelementptr inbounds i8, ptr %1, i64 120
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !22
  br i1 %.not, label %._crit_edge, label %10

10:                                               ; preds = %2
  %11 = getelementptr inbounds i8, ptr %9, i64 120
  store ptr %.pre, ptr %11, align 8, !tbaa !22
  br label %._crit_edge

._crit_edge:                                      ; preds = %2, %10
  %.not13 = icmp eq ptr %.pre, null
  br i1 %.not13, label %14, label %12

12:                                               ; preds = %._crit_edge
  %13 = getelementptr inbounds i8, ptr %.pre, i64 112
  store ptr %9, ptr %13, align 8, !tbaa !16
  br label %14

14:                                               ; preds = %12, %._crit_edge
  %15 = getelementptr inbounds i8, ptr %0, i64 144
  %16 = load ptr, ptr %15, align 8, !tbaa !23
  %17 = icmp eq ptr %16, %1
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  store ptr %.pre, ptr %15, align 8, !tbaa !23
  br label %19

19:                                               ; preds = %18, %14
  %20 = getelementptr inbounds i8, ptr %0, i64 152
  %21 = load i32, ptr %20, align 8, !tbaa !24
  %22 = add nsw i32 %21, -1
  store i32 %22, ptr %20, align 8, !tbaa !24
  tail call void @_ZN6d2BodyD1Ev(ptr noundef nonnull align 8 dereferenceable(132) %1) #3
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @_ZN16d2BlockAllocator4FreeEPvi(ptr noundef nonnull align 8 dereferenceable(128) %23, ptr noundef nonnull %1, i32 noundef 136)
  ret void
}

; Function Attrs: nounwind
declare void @_ZN6d2BodyD1Ev(ptr noundef nonnull align 8 dereferenceable(132)) unnamed_addr #1

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

attributes #0 = { 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 #1 = { 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 #2 = { "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, !11, i64 8}
!6 = !{!"_ZTS7d2World", !7, i64 0, !11, i64 8, !12, i64 16, !11, i64 144, !13, i64 152, !11, i64 160, !13, i64 168, !11, i64 176}
!7 = !{!"_ZTS6d2Vec2", !8, i64 0, !8, i64 4}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!"_ZTS16d2BlockAllocator", !11, i64 0, !13, i64 8, !13, i64 12, !9, i64 16}
!13 = !{!"int", !9, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"vtable pointer", !10, i64 0}
!16 = !{!17, !11, i64 112}
!17 = !{!"_ZTS6d2Body", !18, i64 0, !19, i64 4, !20, i64 8, !7, i64 24, !7, i64 32, !8, i64 40, !8, i64 44, !8, i64 48, !7, i64 52, !8, i64 60, !8, i64 64, !8, i64 68, !8, i64 72, !8, i64 76, !8, i64 80, !8, i64 84, !11, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !8, i64 128}
!18 = !{!"short", !9, i64 0}
!19 = !{!"_ZTS10d2BodyType", !9, i64 0}
!20 = !{!"_ZTS11d2Transform", !7, i64 0, !21, i64 8}
!21 = !{!"_ZTS5d2Rot", !8, i64 0, !8, i64 4}
!22 = !{!17, !11, i64 120}
!23 = !{!6, !11, i64 144}
!24 = !{!6, !13, i64 152}


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