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

; 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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5DonutC2Ev(ptr noundef nonnull align 4 dereferenceable(113) %0) unnamed_addr #0 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  %5 = getelementptr inbounds %class.Donut, ptr %4, i32 0, i32 0
  %6 = getelementptr inbounds %class.Donut, ptr %4, i32 0, i32 1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %20, %1
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = icmp slt i32 %8, 7
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %23

11:                                               ; preds = %7
  %12 = getelementptr inbounds %class.Donut, ptr %4, i32 0, i32 0
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [7 x %struct.b2BodyId], ptr %12, i64 0, i64 %14
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 @_ZL13b2_nullBodyId, i64 8, i1 false), !tbaa.struct !11
  %16 = getelementptr inbounds %class.Donut, ptr %4, i32 0, i32 1
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [7 x %struct.b2JointId], ptr %16, i64 0, i64 %18
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %19, ptr align 4 @_ZL14b2_nullJointId, i64 8, i1 false), !tbaa.struct !11
  br label %20

20:                                               ; preds = %11
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %3, align 4, !tbaa !9
  br label %7, !llvm.loop !14

23:                                               ; preds = %10
  %24 = getelementptr inbounds %class.Donut, ptr %4, i32 0, i32 2
  store i8 0, ptr %24, align 4, !tbaa !16
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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) #2

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

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

%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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @_ZN5DonutC2Ev(ptr nocapture noundef nonnull writeonly align 4 dereferenceable(113) %0) unnamed_addr #0 align 2 {
  %2 = load i64, ptr @_ZL13b2_nullBodyId, align 4
  %3 = getelementptr inbounds i8, ptr %0, i64 56
  %4 = load i64, ptr @_ZL14b2_nullJointId, align 4
  store i64 %4, ptr %3, align 4
  %5 = getelementptr inbounds i8, ptr %0, i64 64
  store i64 %4, ptr %5, align 4
  %6 = getelementptr inbounds i8, ptr %0, i64 72
  store i64 %4, ptr %6, align 4
  %7 = insertelement <4 x i64> poison, i64 %2, i64 0
  %8 = shufflevector <4 x i64> %7, <4 x i64> poison, <4 x i32> zeroinitializer
  store <4 x i64> %8, ptr %0, align 4
  %9 = getelementptr inbounds i8, ptr %0, i64 80
  store i64 %4, ptr %9, align 4
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %2, ptr %10, align 4
  %11 = getelementptr inbounds i8, ptr %0, i64 88
  store i64 %4, ptr %11, align 4
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 %2, ptr %12, align 4
  %13 = getelementptr inbounds i8, ptr %0, i64 96
  store i64 %4, ptr %13, align 4
  %14 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 %2, ptr %14, align 4
  %15 = getelementptr inbounds i8, ptr %0, i64 104
  store i64 %4, ptr %15, align 4
  %16 = getelementptr inbounds i8, ptr %0, i64 112
  store i8 0, ptr %16, align 4, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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" }

!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}


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