; LLVM IR from erincatto/box2d :: samples/doohickey.ll (ZN9Doohickey7DespawnEv)

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

@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1
@__PRETTY_FUNCTION__._ZN9Doohickey7DespawnEv = external hidden unnamed_addr constant [26 x i8], align 1

; 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) #0

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

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

16:                                               ; preds = %1
  br label %19

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

18:                                               ; No predecessors!
  br label %19

19:                                               ; preds = %18, %16
  %20 = getelementptr inbounds %class.Doohickey, ptr %10, i32 0, i32 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %20, i64 8, i1 false), !tbaa.struct !18
  %21 = load i64, ptr %3, align 4
  call void @b2DestroyJoint(i64 %21)
  %22 = getelementptr inbounds %class.Doohickey, ptr %10, i32 0, i32 5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 %22, i64 8, i1 false), !tbaa.struct !18
  %23 = load i64, ptr %4, align 4
  call void @b2DestroyJoint(i64 %23)
  %24 = getelementptr inbounds %class.Doohickey, ptr %10, i32 0, i32 6
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 4 %24, i64 8, i1 false), !tbaa.struct !18
  %25 = load i64, ptr %5, align 4
  call void @b2DestroyJoint(i64 %25)
  %26 = getelementptr inbounds %class.Doohickey, ptr %10, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %26, i64 8, i1 false), !tbaa.struct !18
  %27 = load i64, ptr %6, align 4
  call void @b2DestroyBody(i64 %27)
  %28 = getelementptr inbounds %class.Doohickey, ptr %10, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %28, i64 8, i1 false), !tbaa.struct !18
  %29 = load i64, ptr %7, align 4
  call void @b2DestroyBody(i64 %29)
  %30 = getelementptr inbounds %class.Doohickey, ptr %10, i32 0, i32 2
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %30, i64 8, i1 false), !tbaa.struct !18
  %31 = load i64, ptr %8, align 4
  call void @b2DestroyBody(i64 %31)
  %32 = getelementptr inbounds %class.Doohickey, ptr %10, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %32, i64 8, i1 false), !tbaa.struct !18
  %33 = load i64, ptr %9, align 4
  call void @b2DestroyBody(i64 %33)
  %34 = getelementptr inbounds %class.Doohickey, ptr %10, i32 0, i32 7
  store i8 0, ptr %34, align 4, !tbaa !9
  ret void
}

declare void @b2DestroyJoint(i64) #3

declare void @b2DestroyBody(i64) #3

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { "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 = { 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, !15, i64 56}
!10 = !{!"_ZTS9Doohickey", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !15, i64 56}
!11 = !{!"_ZTS8b2BodyId", !12, i64 0, !13, i64 4, !13, i64 6}
!12 = !{!"int", !7, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!"_ZTS9b2JointId", !12, i64 0, !13, i64 4, !13, i64 6}
!15 = !{!"bool", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{i64 0, i64 4, !19, i64 4, i64 2, !20, i64 6, i64 2, !20}
!19 = !{!12, !12, i64 0}
!20 = !{!13, !13, 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"

@.str.1 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [20 x i8], align 1
@__PRETTY_FUNCTION__._ZN9Doohickey7DespawnEv = external hidden unnamed_addr constant [26 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 @_ZN9Doohickey7DespawnEv(ptr nocapture noundef nonnull align 4 dereferenceable(57) %0) local_unnamed_addr #1 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 56
  %3 = load i8, ptr %2, align 4, !tbaa !5, !range !14, !noundef !15
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %6, label %5

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

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %.sroa.06.0.copyload = load i64, ptr %7, align 4
  tail call void @b2DestroyJoint(i64 %.sroa.06.0.copyload)
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  %.sroa.05.0.copyload = load i64, ptr %8, align 4
  tail call void @b2DestroyJoint(i64 %.sroa.05.0.copyload)
  %9 = getelementptr inbounds i8, ptr %0, i64 48
  %.sroa.04.0.copyload = load i64, ptr %9, align 4
  tail call void @b2DestroyJoint(i64 %.sroa.04.0.copyload)
  %.sroa.03.0.copyload = load i64, ptr %0, align 4
  tail call void @b2DestroyBody(i64 %.sroa.03.0.copyload)
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %.sroa.02.0.copyload = load i64, ptr %10, align 4
  tail call void @b2DestroyBody(i64 %.sroa.02.0.copyload)
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %.sroa.01.0.copyload = load i64, ptr %11, align 4
  tail call void @b2DestroyBody(i64 %.sroa.01.0.copyload)
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %.sroa.0.0.copyload = load i64, ptr %12, align 4
  tail call void @b2DestroyBody(i64 %.sroa.0.0.copyload)
  store i8 0, ptr %2, align 4, !tbaa !5
  ret void
}

declare void @b2DestroyJoint(i64) local_unnamed_addr #2

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, !13, i64 56}
!6 = !{!"_ZTS9Doohickey", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !13, i64 56}
!7 = !{!"_ZTS8b2BodyId", !8, i64 0, !11, i64 4, !11, i64 6}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"short", !9, i64 0}
!12 = !{!"_ZTS9b2JointId", !8, i64 0, !11, i64 4, !11, i64 6}
!13 = !{!"bool", !9, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}


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