; LLVM IR from doyubkim/fluid-engine-dev :: src/jet/physics_animation.ll (ZN3jet16PhysicsAnimation8onUpdateERKNS_5FrameE)

; 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.jet::Frame" = type { i32, double }
%"class.jet::PhysicsAnimation" = type { %"class.jet::Animation", %"struct.jet::Frame", i8, i32, double }
%"class.jet::Animation" = type { ptr }

; 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: mustprogress uwtable
define dso_local void @_ZN3jet16PhysicsAnimation8onUpdateERKNS_5FrameE(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr noundef nonnull align 8 dereferenceable(16) %1) unnamed_addr #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %"struct.jet::Frame", ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds %"class.jet::PhysicsAnimation", ptr %7, i32 0, i32 1
  %12 = getelementptr inbounds %"struct.jet::Frame", ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = icmp sgt i32 %10, %13
  br i1 %14, label %15, label %44

15:                                               ; preds = %2
  %16 = getelementptr inbounds %"class.jet::PhysicsAnimation", ptr %7, i32 0, i32 1
  %17 = getelementptr inbounds %"struct.jet::Frame", ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  call void @_ZN3jet16PhysicsAnimation10initializeEv(ptr noundef nonnull align 8 dereferenceable(40) %7)
  br label %21

21:                                               ; preds = %20, %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.jet::Frame", ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !9
  %25 = getelementptr inbounds %"class.jet::PhysicsAnimation", ptr %7, i32 0, i32 1
  %26 = getelementptr inbounds %"struct.jet::Frame", ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = sub nsw i32 %24, %27
  store i32 %28, ptr %5, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !17
  br label %29

29:                                               ; preds = %38, %21
  %30 = load i32, ptr %6, align 4, !tbaa !17
  %31 = load i32, ptr %5, align 4, !tbaa !17
  %32 = icmp slt i32 %30, %31
  br i1 %32, label %34, label %33

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

34:                                               ; preds = %29
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.jet::Frame", ptr %35, i32 0, i32 1
  %37 = load double, ptr %36, align 8, !tbaa !18
  call void @_ZN3jet16PhysicsAnimation15advanceTimeStepEd(ptr noundef nonnull align 8 dereferenceable(40) %7, double noundef %37)
  br label %38

38:                                               ; preds = %34
  %39 = load i32, ptr %6, align 4, !tbaa !17
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %6, align 4, !tbaa !17
  br label %29, !llvm.loop !19

41:                                               ; preds = %33
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %"class.jet::PhysicsAnimation", ptr %7, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %43, ptr align 8 %42, i64 16, i1 false), !tbaa.struct !21
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %44

44:                                               ; preds = %41, %2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3jet16PhysicsAnimation10initializeEv(ptr noundef nonnull align 8 dereferenceable(40)) #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3jet16PhysicsAnimation15advanceTimeStepEd(ptr noundef nonnull align 8 dereferenceable(40), double noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 0}
!10 = !{!"_ZTSN3jet5FrameE", !11, i64 0, !12, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!14, !11, i64 8}
!14 = !{!"_ZTSN3jet16PhysicsAnimationE", !15, i64 0, !10, i64 8, !16, i64 24, !11, i64 28, !12, i64 32}
!15 = !{!"_ZTSN3jet9AnimationE"}
!16 = !{!"bool", !7, i64 0}
!17 = !{!11, !11, i64 0}
!18 = !{!10, !12, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{i64 0, i64 4, !17, i64 8, i64 8, !22}
!22 = !{!12, !12, 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"

; Function Attrs: mustprogress 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: mustprogress uwtable
define dso_local void @_ZN3jet16PhysicsAnimation8onUpdateERKNS_5FrameE(ptr noundef nonnull align 8 dereferenceable(40) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %1) unnamed_addr #1 align 2 {
  %3 = load i32, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !11
  %6 = icmp sgt i32 %3, %5
  br i1 %6, label %7, label %19

7:                                                ; preds = %2
  %8 = icmp slt i32 %5, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %7
  tail call void @_ZN3jet16PhysicsAnimation10initializeEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %.pre = load i32, ptr %1, align 8, !tbaa !5
  %.pre9 = load i32, ptr %4, align 8, !tbaa !11
  br label %10

10:                                               ; preds = %9, %7
  %11 = phi i32 [ %.pre9, %9 ], [ %5, %7 ]
  %12 = phi i32 [ %.pre, %9 ], [ %3, %7 ]
  %13 = sub nsw i32 %12, %11
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %10
  %15 = getelementptr inbounds i8, ptr %1, i64 8
  br label %16

._crit_edge:                                      ; preds = %16, %10
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(16) %1, i64 16, i1 false), !tbaa.struct !15
  br label %19

16:                                               ; preds = %.lr.ph, %16
  %.08 = phi i32 [ 0, %.lr.ph ], [ %18, %16 ]
  %17 = load double, ptr %15, align 8, !tbaa !18
  tail call void @_ZN3jet16PhysicsAnimation15advanceTimeStepEd(ptr noundef nonnull align 8 dereferenceable(40) %0, double noundef %17)
  %18 = add nuw nsw i32 %.08, 1
  %exitcond.not = icmp eq i32 %18, %13
  br i1 %exitcond.not, label %._crit_edge, label %16, !llvm.loop !19

19:                                               ; preds = %._crit_edge, %2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3jet16PhysicsAnimation10initializeEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3jet16PhysicsAnimation15advanceTimeStepEd(ptr noundef nonnull align 8 dereferenceable(40), double noundef) local_unnamed_addr #1 align 2

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

!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, !7, i64 0}
!6 = !{!"_ZTSN3jet5FrameE", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!12, !7, i64 8}
!12 = !{!"_ZTSN3jet16PhysicsAnimationE", !13, i64 0, !6, i64 8, !14, i64 24, !7, i64 28, !10, i64 32}
!13 = !{!"_ZTSN3jet9AnimationE"}
!14 = !{!"bool", !8, i64 0}
!15 = !{i64 0, i64 4, !16, i64 8, i64 8, !17}
!16 = !{!7, !7, i64 0}
!17 = !{!10, !10, i64 0}
!18 = !{!6, !10, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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