; LLVM IR from erincatto/box2d :: samples/donut.ll (ZN5Donut7DestroyEv)

; 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.b2BodyId = type { i32, i16, i16 }
%struct.b2JointId = type { i32, i16, i16 }
%class.Donut = type <{ [7 x %struct.b2BodyId], [7 x %struct.b2JointId], i8, [3 x i8] }>

@_ZL13b2_nullBodyId = external hidden constant %struct.b2BodyId, align 4
@_ZL14b2_nullJointId = external hidden constant %struct.b2JointId, align 4
@.str.1 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [20 x i8], align 1
@__PRETTY_FUNCTION__._ZN5Donut7DestroyEv = external hidden unnamed_addr constant [22 x i8], align 1

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN5Donut7DestroyEv(ptr noundef nonnull align 4 dereferenceable(113) %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca %struct.b2BodyId, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr %2, align 8
  %6 = getelementptr inbounds %class.Donut, ptr %5, i32 0, i32 2
  %7 = load i8, ptr %6, align 4, !tbaa !9, !range !12, !noundef !13
  %8 = trunc i8 %7 to i1
  %9 = zext i1 %8 to i32
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  br label %14

12:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 86, ptr noundef @__PRETTY_FUNCTION__._ZN5Donut7DestroyEv) #5
  unreachable

13:                                               ; No predecessors!
  br label %14

14:                                               ; preds = %13, %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 0, ptr %3, align 4, !tbaa !14
  br label %15

15:                                               ; preds = %33, %14
  %16 = load i32, ptr %3, align 4, !tbaa !14
  %17 = icmp slt i32 %16, 7
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %36

19:                                               ; preds = %15
  %20 = getelementptr inbounds %class.Donut, ptr %5, i32 0, i32 0
  %21 = load i32, ptr %3, align 4, !tbaa !14
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [7 x %struct.b2BodyId], ptr %20, i64 0, i64 %22
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 %23, i64 8, i1 false), !tbaa.struct !16
  %24 = load i64, ptr %4, align 4
  call void @b2DestroyBody(i64 %24)
  %25 = getelementptr inbounds %class.Donut, ptr %5, i32 0, i32 0
  %26 = load i32, ptr %3, align 4, !tbaa !14
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [7 x %struct.b2BodyId], ptr %25, i64 0, i64 %27
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %28, ptr align 4 @_ZL13b2_nullBodyId, i64 8, i1 false), !tbaa.struct !16
  %29 = getelementptr inbounds %class.Donut, ptr %5, i32 0, i32 1
  %30 = load i32, ptr %3, align 4, !tbaa !14
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [7 x %struct.b2JointId], ptr %29, i64 0, i64 %31
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %32, ptr align 4 @_ZL14b2_nullJointId, i64 8, i1 false), !tbaa.struct !16
  br label %33

33:                                               ; preds = %19
  %34 = load i32, ptr %3, align 4, !tbaa !14
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %3, align 4, !tbaa !14
  br label %15, !llvm.loop !19

36:                                               ; preds = %18
  %37 = getelementptr inbounds %class.Donut, ptr %5, i32 0, i32 2
  store i8 0, ptr %37, align 4, !tbaa !9
  ret void
}

declare void @b2DestroyBody(i64) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { "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 #5 = { noreturn nounwind }
attributes #6 = { 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, !11, i64 112}
!10 = !{!"_ZTS5Donut", !7, i64 0, !7, i64 56, !11, i64 112}
!11 = !{!"bool", !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{i64 0, i64 4, !14, i64 4, i64 2, !17, i64 6, i64 2, !17}
!17 = !{!18, !18, i64 0}
!18 = !{!"short", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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.b2BodyId = type { i32, i16, i16 }
%struct.b2JointId = type { i32, i16, i16 }

@_ZL13b2_nullBodyId = external hidden local_unnamed_addr constant %struct.b2BodyId, align 4
@_ZL14b2_nullJointId = external hidden local_unnamed_addr constant %struct.b2JointId, align 4
@.str.1 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [20 x i8], align 1
@__PRETTY_FUNCTION__._ZN5Donut7DestroyEv = external hidden unnamed_addr constant [22 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 uwtable
define dso_local void @_ZN5Donut7DestroyEv(ptr nocapture noundef nonnull align 4 dereferenceable(113) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 112
  %3 = load i8, ptr %2, align 4, !tbaa !5, !range !10, !noundef !11
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %.preheader, label %20

.preheader:                                       ; preds = %1
  %5 = load i64, ptr @_ZL13b2_nullBodyId, align 4
  %6 = getelementptr inbounds i8, ptr %0, i64 56
  %7 = load i64, ptr @_ZL14b2_nullJointId, align 4
  %.sroa.0.0.copyload = load i64, ptr %0, align 4
  tail call void @b2DestroyBody(i64 %.sroa.0.0.copyload)
  store i64 %5, ptr %0, align 4
  store i64 %7, ptr %6, align 4
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %.sroa.0.0.copyload.1 = load i64, ptr %8, align 4
  tail call void @b2DestroyBody(i64 %.sroa.0.0.copyload.1)
  store i64 %5, ptr %8, align 4
  %9 = getelementptr inbounds i8, ptr %0, i64 64
  store i64 %7, ptr %9, align 4
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %.sroa.0.0.copyload.2 = load i64, ptr %10, align 4
  tail call void @b2DestroyBody(i64 %.sroa.0.0.copyload.2)
  store i64 %5, ptr %10, align 4
  %11 = getelementptr inbounds i8, ptr %0, i64 72
  store i64 %7, ptr %11, align 4
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %.sroa.0.0.copyload.3 = load i64, ptr %12, align 4
  tail call void @b2DestroyBody(i64 %.sroa.0.0.copyload.3)
  store i64 %5, ptr %12, align 4
  %13 = getelementptr inbounds i8, ptr %0, i64 80
  store i64 %7, ptr %13, align 4
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %.sroa.0.0.copyload.4 = load i64, ptr %14, align 4
  tail call void @b2DestroyBody(i64 %.sroa.0.0.copyload.4)
  store i64 %5, ptr %14, align 4
  %15 = getelementptr inbounds i8, ptr %0, i64 88
  store i64 %7, ptr %15, align 4
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  %.sroa.0.0.copyload.5 = load i64, ptr %16, align 4
  tail call void @b2DestroyBody(i64 %.sroa.0.0.copyload.5)
  store i64 %5, ptr %16, align 4
  %17 = getelementptr inbounds i8, ptr %0, i64 96
  store i64 %7, ptr %17, align 4
  %18 = getelementptr inbounds i8, ptr %0, i64 48
  %.sroa.0.0.copyload.6 = load i64, ptr %18, align 4
  tail call void @b2DestroyBody(i64 %.sroa.0.0.copyload.6)
  store i64 %5, ptr %18, align 4
  %19 = getelementptr inbounds i8, ptr %0, i64 104
  store i64 %7, ptr %19, align 4
  store i8 0, ptr %2, align 4, !tbaa !5
  ret void

20:                                               ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 86, ptr noundef nonnull @__PRETTY_FUNCTION__._ZN5Donut7DestroyEv) #3
  unreachable
}

declare void @b2DestroyBody(i64) local_unnamed_addr #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 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 = { "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 = { 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, !9, i64 112}
!6 = !{!"_ZTS5Donut", !7, i64 0, !7, i64 56, !9, i64 112}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"bool", !7, i64 0}
!10 = !{i8 0, i8 2}
!11 = !{}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass