; LLVM IR from csviragh/robotsim :: src (colors)

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

6:                                                ; preds = %54, %2
  %7 = load i32, ptr %5, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = load i32, ptr %8, align 4, !tbaa !9
  %10 = icmp slt i32 %7, %9
  br i1 %10, label %11, label %57

11:                                               ; preds = %6
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds %struct.model_specific_color_t, ptr %12, i64 %14
  %16 = getelementptr inbounds %struct.model_specific_color_t, ptr %15, i32 0, i32 1
  %17 = getelementptr inbounds [3 x float], ptr %16, i64 0, i64 0
  %18 = load float, ptr %17, align 8, !tbaa !11
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds %struct.model_specific_color_t, ptr %19, i64 %21
  %23 = getelementptr inbounds %struct.model_specific_color_t, ptr %22, i32 0, i32 2
  %24 = getelementptr inbounds [3 x ptr], ptr %23, i64 0, i64 0
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  store float %18, ptr %25, align 4, !tbaa !11
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds %struct.model_specific_color_t, ptr %26, i64 %28
  %30 = getelementptr inbounds %struct.model_specific_color_t, ptr %29, i32 0, i32 1
  %31 = getelementptr inbounds [3 x float], ptr %30, i64 0, i64 1
  %32 = load float, ptr %31, align 4, !tbaa !11
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %struct.model_specific_color_t, ptr %33, i64 %35
  %37 = getelementptr inbounds %struct.model_specific_color_t, ptr %36, i32 0, i32 2
  %38 = getelementptr inbounds [3 x ptr], ptr %37, i64 0, i64 1
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  store float %32, ptr %39, align 4, !tbaa !11
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds %struct.model_specific_color_t, ptr %40, i64 %42
  %44 = getelementptr inbounds %struct.model_specific_color_t, ptr %43, i32 0, i32 1
  %45 = getelementptr inbounds [3 x float], ptr %44, i64 0, i64 2
  %46 = load float, ptr %45, align 8, !tbaa !11
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds %struct.model_specific_color_t, ptr %47, i64 %49
  %51 = getelementptr inbounds %struct.model_specific_color_t, ptr %50, i32 0, i32 2
  %52 = getelementptr inbounds [3 x ptr], ptr %51, i64 0, i64 2
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  store float %46, ptr %53, align 4, !tbaa !11
  br label %54

54:                                               ; preds = %11
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %5, align 4, !tbaa !9
  br label %6, !llvm.loop !13

57:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #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, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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.model_specific_color_t = type { ptr, [3 x float], [3 x ptr] }

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

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %3 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %5 = icmp eq i32 %3, 1
  br i1 %5, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

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

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %6 = getelementptr inbounds %struct.model_specific_color_t, ptr %0, i64 %indvars.iv
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = load float, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %6, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  store float %8, ptr %10, align 4, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %6, i64 12
  %12 = load float, ptr %11, align 4, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %6, i64 32
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  store float %12, ptr %14, align 4, !tbaa !9
  %15 = getelementptr inbounds i8, ptr %6, i64 16
  %16 = load float, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %6, i64 40
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  store float %16, ptr %18, align 4, !tbaa !9
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %19 = getelementptr inbounds %struct.model_specific_color_t, ptr %0, i64 %indvars.iv.next
  %20 = getelementptr inbounds i8, ptr %19, i64 8
  %21 = load float, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %19, i64 24
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  store float %21, ptr %23, align 4, !tbaa !9
  %24 = getelementptr inbounds i8, ptr %19, i64 12
  %25 = load float, ptr %24, align 4, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %19, i64 32
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  store float %25, ptr %27, align 4, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %19, i64 16
  %29 = load float, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %19, i64 40
  %31 = load ptr, ptr %30, align 8, !tbaa !11
  store float %29, ptr %31, align 4, !tbaa !9
  %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 %.lr.ph, !llvm.loop !13

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

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %32 = getelementptr inbounds %struct.model_specific_color_t, ptr %0, i64 %indvars.iv.unr
  %33 = getelementptr inbounds i8, ptr %32, i64 8
  %34 = load float, ptr %33, align 8, !tbaa !9
  %35 = getelementptr inbounds i8, ptr %32, i64 24
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  store float %34, ptr %36, align 4, !tbaa !9
  %37 = getelementptr inbounds i8, ptr %32, i64 12
  %38 = load float, ptr %37, align 4, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %32, i64 32
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  store float %38, ptr %40, align 4, !tbaa !9
  %41 = getelementptr inbounds i8, ptr %32, i64 16
  %42 = load float, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds i8, ptr %32, i64 40
  %44 = load ptr, ptr %43, align 8, !tbaa !11
  store float %42, ptr %44, align 4, !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %2
  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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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