; LLVM IR from PyCee/NUS_library :: src/physics (NUS_kinematic_property)

; 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.NUS_vector = type { double, double, double }
%struct.NUS_kinematic_property = type { ptr, %struct.NUS_vector, i32 }
%struct.NUS_kinematic_factor = type { %struct.NUS_vector, i32 }

; 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: nounwind uwtable
define dso_local void @nus_kinematic_property_integral(ptr dead_on_unwind noalias writable sret(%struct.NUS_vector) align 8 %0, ptr noundef %1, double noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca %struct.NUS_vector, align 8
  %8 = alloca %struct.NUS_vector, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  store double %2, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr %7) #4
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %9, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %10, i64 24, i1 false), !tbaa.struct !11
  store i32 0, ptr %6, align 4, !tbaa !12
  br label %11

11:                                               ; preds = %25, %3
  %12 = load i32, ptr %6, align 4, !tbaa !12
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 8, !tbaa !14
  %16 = icmp ult i32 %12, %15
  br i1 %16, label %17, label %28

17:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 24, ptr %8) #4
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.NUS_kinematic_property, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = load i32, ptr %6, align 4, !tbaa !12
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %20, i64 %22
  %24 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %23, i32 0, i32 0
  call void @nus_vector_add(ptr dead_on_unwind writable sret(%struct.NUS_vector) align 8 %8, ptr noundef byval(%struct.NUS_vector) align 8 %7, ptr noundef byval(%struct.NUS_vector) align 8 %24)
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %8, i64 24, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 24, ptr %8) #4
  br label %25

25:                                               ; preds = %17
  %26 = load i32, ptr %6, align 4, !tbaa !12
  %27 = add i32 %26, 1
  store i32 %27, ptr %6, align 4, !tbaa !12
  br label %11, !llvm.loop !18

28:                                               ; preds = %11
  %29 = load double, ptr %5, align 8, !tbaa !9
  call void @nus_vector_scale(ptr dead_on_unwind writable sret(%struct.NUS_vector) align 8 %0, ptr noundef byval(%struct.NUS_vector) align 8 %7, double noundef %29)
  call void @llvm.lifetime.end.p0(i64 24, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  ret void
}

declare void @nus_vector_add(ptr dead_on_unwind writable sret(%struct.NUS_vector) align 8, ptr noundef byval(%struct.NUS_vector) align 8, ptr noundef byval(%struct.NUS_vector) align 8) #3

declare void @nus_vector_scale(ptr dead_on_unwind writable sret(%struct.NUS_vector) align 8, ptr noundef byval(%struct.NUS_vector) align 8, double noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 = { "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 = { 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 = !{!"double", !7, i64 0}
!11 = !{i64 0, i64 8, !9, i64 8, i64 8, !9, i64 16, i64 8, !9}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 32}
!15 = !{!"NUS_kinematic_property", !6, i64 0, !16, i64 8, !13, i64 32}
!16 = !{!"NUS_vector", !10, i64 0, !10, i64 8, !10, i64 16}
!17 = !{!15, !6, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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.NUS_vector = type { double, double, double }
%struct.NUS_kinematic_factor = type { %struct.NUS_vector, i32 }

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @nus_kinematic_property_integral(ptr dead_on_unwind noalias writable sret(%struct.NUS_vector) align 8 %0, ptr nocapture noundef readonly %1, double noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.NUS_vector, align 8
  %5 = alloca %struct.NUS_vector, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %4) #4
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 8 dereferenceable(24) %6, i64 24, i1 false), !tbaa.struct !5
  %7 = getelementptr inbounds i8, ptr %1, i64 32
  %8 = load i32, ptr %7, align 8, !tbaa !10
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %3 ]
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #4
  %9 = load ptr, ptr %1, align 8, !tbaa !15
  %10 = getelementptr inbounds %struct.NUS_kinematic_factor, ptr %9, i64 %indvars.iv
  call void @nus_vector_add(ptr dead_on_unwind nonnull writable sret(%struct.NUS_vector) align 8 %5, ptr noundef nonnull byval(%struct.NUS_vector) align 8 %4, ptr noundef byval(%struct.NUS_vector) align 8 %10) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %4, ptr noundef nonnull align 8 dereferenceable(24) %5, i64 24, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = load i32, ptr %7, align 8, !tbaa !10
  %12 = zext i32 %11 to i64
  %13 = icmp ult i64 %indvars.iv.next, %12
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %3
  call void @nus_vector_scale(ptr dead_on_unwind writable sret(%struct.NUS_vector) align 8 %0, ptr noundef nonnull byval(%struct.NUS_vector) align 8 %4, double noundef %2) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %4) #4
  ret void
}

declare void @nus_vector_add(ptr dead_on_unwind writable sret(%struct.NUS_vector) align 8, ptr noundef byval(%struct.NUS_vector) align 8, ptr noundef byval(%struct.NUS_vector) align 8) local_unnamed_addr #3

declare void @nus_vector_scale(ptr dead_on_unwind writable sret(%struct.NUS_vector) align 8, ptr noundef byval(%struct.NUS_vector) align 8, double noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree 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 = { "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 = { 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 = !{i64 0, i64 8, !6, i64 8, i64 8, !6, i64 16, i64 8, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !14, i64 32}
!11 = !{!"NUS_kinematic_property", !12, i64 0, !13, i64 8, !14, i64 32}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"NUS_vector", !7, i64 0, !7, i64 8, !7, i64 16}
!14 = !{!"int", !8, i64 0}
!15 = !{!11, !12, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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