; LLVM IR from csviragh/robotsim :: src/utilities (param_utils)

; 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.flocking_model_params_t = type { [256 x i8], i32, [64 x %struct.fl_param_double_t], i32, [64 x ptr], i32 }
%struct.fl_param_double_t = type { [64 x i8], [10 x i8], double, i32, double, double, double, double, [64 x i8], i8, i8, double, ptr, i32, %struct.anon }
%struct.anon = type { [32 x double], [32 x [7 x i8]] }

; 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 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 @RefreshFlockingParams(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %4

4:                                                ; preds = %25, %1
  %5 = load i32, ptr %3, align 4, !tbaa !9
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.flocking_model_params_t, ptr %6, i32 0, i32 1
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = icmp slt i32 %5, %8
  br i1 %9, label %10, label %28

10:                                               ; preds = %4
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.flocking_model_params_t, ptr %11, i32 0, i32 2
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [64 x %struct.fl_param_double_t], ptr %12, i64 0, i64 %14
  %16 = getelementptr inbounds %struct.fl_param_double_t, ptr %15, i32 0, i32 2
  %17 = load double, ptr %16, align 8, !tbaa !13
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.flocking_model_params_t, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [64 x %struct.fl_param_double_t], ptr %19, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.fl_param_double_t, ptr %22, i32 0, i32 12
  %24 = load ptr, ptr %23, align 8, !tbaa !18
  store double %17, ptr %24, align 8, !tbaa !19
  br label %25

25:                                               ; preds = %10
  %26 = load i32, ptr %3, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %3, align 4, !tbaa !9
  br label %4, !llvm.loop !20

28:                                               ; preds = %4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 256}
!12 = !{!"", !7, i64 0, !10, i64 256, !7, i64 264, !10, i64 45320, !7, i64 45328, !10, i64 45840}
!13 = !{!14, !15, i64 80}
!14 = !{!"", !7, i64 0, !7, i64 64, !15, i64 80, !10, i64 88, !15, i64 96, !15, i64 104, !15, i64 112, !15, i64 120, !7, i64 128, !16, i64 192, !16, i64 193, !15, i64 200, !6, i64 208, !10, i64 216, !17, i64 224}
!15 = !{!"double", !7, i64 0}
!16 = !{!"_Bool", !7, i64 0}
!17 = !{!"", !7, i64 0, !7, i64 256}
!18 = !{!14, !6, i64 208}
!19 = !{!15, !15, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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.fl_param_double_t = type { [64 x i8], [10 x i8], double, i32, double, double, double, double, [64 x i8], i8, i8, double, ptr, i32, %struct.anon }
%struct.anon = type { [32 x double], [32 x [7 x i8]] }

; Function Attrs: nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @RefreshFlockingParams(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 256
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 264
  %wide.trip.count = zext nneg i32 %3 to i64
  %xtraiter = and i64 %wide.trip.count, 3
  %6 = icmp ult i32 %3, 4
  br i1 %6, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

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

7:                                                ; preds = %7, %.lr.ph.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.new ], [ %indvars.iv.next.3, %7 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %7 ]
  %8 = getelementptr inbounds [64 x %struct.fl_param_double_t], ptr %5, i64 0, i64 %indvars.iv
  %9 = getelementptr inbounds i8, ptr %8, i64 80
  %10 = load double, ptr %9, align 8, !tbaa !10
  %11 = getelementptr inbounds i8, ptr %8, i64 208
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  store double %10, ptr %12, align 8, !tbaa !17
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %13 = getelementptr inbounds [64 x %struct.fl_param_double_t], ptr %5, i64 0, i64 %indvars.iv.next
  %14 = getelementptr inbounds i8, ptr %13, i64 80
  %15 = load double, ptr %14, align 8, !tbaa !10
  %16 = getelementptr inbounds i8, ptr %13, i64 208
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  store double %15, ptr %17, align 8, !tbaa !17
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %18 = getelementptr inbounds [64 x %struct.fl_param_double_t], ptr %5, i64 0, i64 %indvars.iv.next.1
  %19 = getelementptr inbounds i8, ptr %18, i64 80
  %20 = load double, ptr %19, align 8, !tbaa !10
  %21 = getelementptr inbounds i8, ptr %18, i64 208
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  store double %20, ptr %22, align 8, !tbaa !17
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %23 = getelementptr inbounds [64 x %struct.fl_param_double_t], ptr %5, i64 0, i64 %indvars.iv.next.2
  %24 = getelementptr inbounds i8, ptr %23, i64 80
  %25 = load double, ptr %24, align 8, !tbaa !10
  %26 = getelementptr inbounds i8, ptr %23, i64 208
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  store double %25, ptr %27, align 8, !tbaa !17
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %7, !llvm.loop !18

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

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %28 = getelementptr inbounds [64 x %struct.fl_param_double_t], ptr %5, i64 0, i64 %indvars.iv.epil
  %29 = getelementptr inbounds i8, ptr %28, i64 80
  %30 = load double, ptr %29, align 8, !tbaa !10
  %31 = getelementptr inbounds i8, ptr %28, i64 208
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  store double %30, ptr %32, align 8, !tbaa !17
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !20

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %1
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) 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 256}
!6 = !{!"", !7, i64 0, !9, i64 256, !7, i64 264, !9, i64 45320, !7, i64 45328, !9, i64 45840}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!11, !12, i64 80}
!11 = !{!"", !7, i64 0, !7, i64 64, !12, i64 80, !9, i64 88, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !7, i64 128, !13, i64 192, !13, i64 193, !12, i64 200, !14, i64 208, !9, i64 216, !15, i64 224}
!12 = !{!"double", !7, i64 0}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!"", !7, i64 0, !7, i64 256}
!16 = !{!11, !14, i64 208}
!17 = !{!12, !12, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}


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