; LLVM IR from ESPboy-edu/ESPboy_tinyphysicsengine :: programs (hello)

; 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.TPE_Vec3 = type { i32, i32, i32 }
%struct.TPE_Body = type { ptr, i8, ptr, i8, i16, i16, i16, i8, i8 }
%struct.TPE_Joint = type { %struct.TPE_Vec3, [3 x i16], i8 }

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_bodyActivate(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @TPE_bodyAccelerate(ptr noundef %0, i64 %1, i32 %2) #2 {
  %4 = alloca %struct.TPE_Vec3, align 4
  %5 = alloca { i64, i32 }, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 0
  store i64 %1, ptr %8, align 4
  %9 = getelementptr inbounds { i64, i32 }, ptr %5, i32 0, i32 1
  store i32 %2, ptr %9, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 %5, i64 12, i1 false)
  store ptr %0, ptr %6, align 8, !tbaa !5
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  call void @TPE_bodyActivate(ptr noundef %10)
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  store i16 0, ptr %7, align 2, !tbaa !9
  br label %11

11:                                               ; preds = %63, %3
  %12 = load i16, ptr %7, align 2, !tbaa !9
  %13 = zext i16 %12 to i32
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.TPE_Body, ptr %14, i32 0, i32 1
  %16 = load i8, ptr %15, align 8, !tbaa !11
  %17 = zext i8 %16 to i32
  %18 = icmp slt i32 %13, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  br label %66

20:                                               ; preds = %11
  %21 = getelementptr inbounds %struct.TPE_Vec3, ptr %4, i32 0, i32 0
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.TPE_Body, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = load i16, ptr %7, align 2, !tbaa !9
  %27 = zext i16 %26 to i64
  %28 = getelementptr inbounds %struct.TPE_Joint, ptr %25, i64 %27
  %29 = getelementptr inbounds %struct.TPE_Joint, ptr %28, i32 0, i32 1
  %30 = getelementptr inbounds [3 x i16], ptr %29, i64 0, i64 0
  %31 = load i16, ptr %30, align 4, !tbaa !9
  %32 = sext i16 %31 to i32
  %33 = add nsw i32 %32, %22
  %34 = trunc i32 %33 to i16
  store i16 %34, ptr %30, align 4, !tbaa !9
  %35 = getelementptr inbounds %struct.TPE_Vec3, ptr %4, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !17
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TPE_Body, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !16
  %40 = load i16, ptr %7, align 2, !tbaa !9
  %41 = zext i16 %40 to i64
  %42 = getelementptr inbounds %struct.TPE_Joint, ptr %39, i64 %41
  %43 = getelementptr inbounds %struct.TPE_Joint, ptr %42, i32 0, i32 1
  %44 = getelementptr inbounds [3 x i16], ptr %43, i64 0, i64 1
  %45 = load i16, ptr %44, align 2, !tbaa !9
  %46 = sext i16 %45 to i32
  %47 = add nsw i32 %46, %36
  %48 = trunc i32 %47 to i16
  store i16 %48, ptr %44, align 2, !tbaa !9
  %49 = getelementptr inbounds %struct.TPE_Vec3, ptr %4, i32 0, i32 2
  %50 = load i32, ptr %49, align 4, !tbaa !18
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.TPE_Body, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !16
  %54 = load i16, ptr %7, align 2, !tbaa !9
  %55 = zext i16 %54 to i64
  %56 = getelementptr inbounds %struct.TPE_Joint, ptr %53, i64 %55
  %57 = getelementptr inbounds %struct.TPE_Joint, ptr %56, i32 0, i32 1
  %58 = getelementptr inbounds [3 x i16], ptr %57, i64 0, i64 2
  %59 = load i16, ptr %58, align 4, !tbaa !9
  %60 = sext i16 %59 to i32
  %61 = add nsw i32 %60, %50
  %62 = trunc i32 %61 to i16
  store i16 %62, ptr %58, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %20
  %64 = load i16, ptr %7, align 2, !tbaa !9
  %65 = add i16 %64, 1
  store i16 %65, ptr %7, align 2, !tbaa !9
  br label %11, !llvm.loop !19

66:                                               ; preds = %19
  ret void
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !7, i64 8}
!12 = !{!"", !6, i64 0, !7, i64 8, !6, i64 16, !7, i64 24, !10, i64 26, !10, i64 28, !10, i64 30, !7, i64 32, !7, i64 33}
!13 = !{!14, !15, i64 0}
!14 = !{!"", !15, i64 0, !15, i64 4, !15, i64 8}
!15 = !{!"int", !7, i64 0}
!16 = !{!12, !6, i64 0}
!17 = !{!14, !15, i64 4}
!18 = !{!14, !15, i64 8}
!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.TPE_Joint = type { %struct.TPE_Vec3, [3 x i16], i8 }
%struct.TPE_Vec3 = type { i32, i32, i32 }

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_bodyActivate(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TPE_bodyAccelerate(ptr noundef %0, i64 %1, i32 %2) local_unnamed_addr #0 {
  %.sroa.210.0.extract.shift = lshr i64 %1, 32
  %4 = trunc i64 %1 to i16
  %5 = insertelement <2 x i16> poison, i16 %4, i64 0
  %6 = trunc i64 %.sroa.210.0.extract.shift to i16
  %7 = insertelement <2 x i16> %5, i16 %6, i64 1
  tail call void @TPE_bodyActivate(ptr noundef %0)
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i8, ptr %8, align 8, !tbaa !5
  %.not = icmp eq i8 %9, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %10 = load ptr, ptr %0, align 8, !tbaa !11
  %11 = trunc i32 %2 to i16
  %wide.trip.count = zext i8 %9 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %12 = icmp eq i8 %9, 1
  br i1 %12, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %wide.trip.count, 254
  br label %19

._crit_edge.loopexit.unr-lcssa:                   ; preds = %19, %.lr.ph
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.1, %19 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.loopexit.epilog-lcssa

._crit_edge.loopexit.epilog-lcssa:                ; preds = %._crit_edge.loopexit.unr-lcssa
  %13 = getelementptr inbounds %struct.TPE_Joint, ptr %10, i64 %indvars.iv.unr, i32 1
  %14 = load <2 x i16>, ptr %13, align 4, !tbaa !12
  %15 = add <2 x i16> %14, %7
  store <2 x i16> %15, ptr %13, align 4, !tbaa !12
  %16 = getelementptr inbounds %struct.TPE_Joint, ptr %10, i64 %indvars.iv.unr, i32 1, i64 2
  %17 = load i16, ptr %16, align 4, !tbaa !12
  %18 = add i16 %17, %11
  store i16 %18, ptr %16, align 4, !tbaa !12
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit.epilog-lcssa, %._crit_edge.loopexit.unr-lcssa, %3
  ret void

19:                                               ; preds = %19, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.1, %19 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %19 ]
  %20 = getelementptr inbounds %struct.TPE_Joint, ptr %10, i64 %indvars.iv, i32 1
  %21 = load <2 x i16>, ptr %20, align 4, !tbaa !12
  %22 = add <2 x i16> %21, %7
  store <2 x i16> %22, ptr %20, align 4, !tbaa !12
  %23 = getelementptr inbounds %struct.TPE_Joint, ptr %10, i64 %indvars.iv, i32 1, i64 2
  %24 = load i16, ptr %23, align 4, !tbaa !12
  %25 = add i16 %24, %11
  store i16 %25, ptr %23, align 4, !tbaa !12
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %26 = getelementptr inbounds %struct.TPE_Joint, ptr %10, i64 %indvars.iv.next, i32 1
  %27 = load <2 x i16>, ptr %26, align 4, !tbaa !12
  %28 = add <2 x i16> %27, %7
  store <2 x i16> %28, ptr %26, align 4, !tbaa !12
  %29 = getelementptr inbounds %struct.TPE_Joint, ptr %10, i64 %indvars.iv.next, i32 1, i64 2
  %30 = load i16, ptr %29, align 4, !tbaa !12
  %31 = add i16 %30, %11
  store i16 %31, ptr %29, align 4, !tbaa !12
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %19, !llvm.loop !13
}

attributes #0 = { 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" }

!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, !8, i64 8}
!6 = !{!"", !7, i64 0, !8, i64 8, !7, i64 16, !8, i64 24, !10, i64 26, !10, i64 28, !10, i64 30, !8, i64 32, !8, i64 33}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass