; LLVM IR from robinrodricks/InspiritImage :: Inspirit.Assurf/clib/rpp (rpp_vecmat)

; 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.mat33_t = type { [9 x double] }

; 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 @mat33_array_sum(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mat33_clear(ptr noundef %10)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.mat33_t, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds [9 x double], ptr %12, i64 0, i64 0
  store ptr %13, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %88, %3
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %18, label %91

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds %struct.mat33_t, ptr %19, i64 %21
  %23 = getelementptr inbounds %struct.mat33_t, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds [9 x double], ptr %23, i64 0, i64 0
  store ptr %24, ptr %9, align 8, !tbaa !5
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = getelementptr inbounds double, ptr %25, i64 0
  %27 = load double, ptr %26, align 8, !tbaa !11
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds double, ptr %28, i64 0
  %30 = load double, ptr %29, align 8, !tbaa !11
  %31 = fadd double %30, %27
  store double %31, ptr %29, align 8, !tbaa !11
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = getelementptr inbounds double, ptr %32, i64 3
  %34 = load double, ptr %33, align 8, !tbaa !11
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds double, ptr %35, i64 3
  %37 = load double, ptr %36, align 8, !tbaa !11
  %38 = fadd double %37, %34
  store double %38, ptr %36, align 8, !tbaa !11
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds double, ptr %39, i64 6
  %41 = load double, ptr %40, align 8, !tbaa !11
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds double, ptr %42, i64 6
  %44 = load double, ptr %43, align 8, !tbaa !11
  %45 = fadd double %44, %41
  store double %45, ptr %43, align 8, !tbaa !11
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = getelementptr inbounds double, ptr %46, i64 1
  %48 = load double, ptr %47, align 8, !tbaa !11
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds double, ptr %49, i64 1
  %51 = load double, ptr %50, align 8, !tbaa !11
  %52 = fadd double %51, %48
  store double %52, ptr %50, align 8, !tbaa !11
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds double, ptr %53, i64 4
  %55 = load double, ptr %54, align 8, !tbaa !11
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = getelementptr inbounds double, ptr %56, i64 4
  %58 = load double, ptr %57, align 8, !tbaa !11
  %59 = fadd double %58, %55
  store double %59, ptr %57, align 8, !tbaa !11
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = getelementptr inbounds double, ptr %60, i64 7
  %62 = load double, ptr %61, align 8, !tbaa !11
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = getelementptr inbounds double, ptr %63, i64 7
  %65 = load double, ptr %64, align 8, !tbaa !11
  %66 = fadd double %65, %62
  store double %66, ptr %64, align 8, !tbaa !11
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = getelementptr inbounds double, ptr %67, i64 2
  %69 = load double, ptr %68, align 8, !tbaa !11
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds double, ptr %70, i64 2
  %72 = load double, ptr %71, align 8, !tbaa !11
  %73 = fadd double %72, %69
  store double %73, ptr %71, align 8, !tbaa !11
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = getelementptr inbounds double, ptr %74, i64 5
  %76 = load double, ptr %75, align 8, !tbaa !11
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = getelementptr inbounds double, ptr %77, i64 5
  %79 = load double, ptr %78, align 8, !tbaa !11
  %80 = fadd double %79, %76
  store double %80, ptr %78, align 8, !tbaa !11
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  %82 = getelementptr inbounds double, ptr %81, i64 8
  %83 = load double, ptr %82, align 8, !tbaa !11
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = getelementptr inbounds double, ptr %84, i64 8
  %86 = load double, ptr %85, align 8, !tbaa !11
  %87 = fadd double %86, %83
  store double %87, ptr %85, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %88

88:                                               ; preds = %18
  %89 = load i32, ptr %7, align 4, !tbaa !9
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %7, align 4, !tbaa !9
  br label %14, !llvm.loop !13

91:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare void @mat33_clear(ptr noundef) #2

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 = { inlinehint 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !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.mat33_t = type { [9 x double] }

; Function Attrs: nounwind uwtable
define dso_local void @mat33_array_sum(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  tail call void @mat33_clear(ptr noundef %0)
  %4 = icmp sgt i32 %2, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = getelementptr inbounds i8, ptr %0, i64 56
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = getelementptr inbounds i8, ptr %0, i64 40
  %12 = getelementptr inbounds i8, ptr %0, i64 64
  %.promoted = load double, ptr %0, align 8, !tbaa !5
  %.promoted25 = load double, ptr %5, align 8, !tbaa !5
  %.promoted26 = load double, ptr %6, align 8, !tbaa !5
  %.promoted27 = load double, ptr %7, align 8, !tbaa !5
  %.promoted28 = load double, ptr %8, align 8, !tbaa !5
  %.promoted29 = load double, ptr %9, align 8, !tbaa !5
  %.promoted30 = load double, ptr %10, align 8, !tbaa !5
  %.promoted31 = load double, ptr %11, align 8, !tbaa !5
  %.promoted32 = load double, ptr %12, align 8, !tbaa !5
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %13

13:                                               ; preds = %.lr.ph, %13
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %13 ]
  %14 = phi double [ %.promoted32, %.lr.ph ], [ %49, %13 ]
  %15 = phi double [ %.promoted31, %.lr.ph ], [ %46, %13 ]
  %16 = phi double [ %.promoted30, %.lr.ph ], [ %43, %13 ]
  %17 = phi double [ %.promoted29, %.lr.ph ], [ %40, %13 ]
  %18 = phi double [ %.promoted28, %.lr.ph ], [ %37, %13 ]
  %19 = phi double [ %.promoted27, %.lr.ph ], [ %34, %13 ]
  %20 = phi double [ %.promoted26, %.lr.ph ], [ %31, %13 ]
  %21 = phi double [ %.promoted25, %.lr.ph ], [ %28, %13 ]
  %22 = phi double [ %.promoted, %.lr.ph ], [ %25, %13 ]
  %23 = getelementptr inbounds %struct.mat33_t, ptr %1, i64 %indvars.iv
  %24 = load double, ptr %23, align 8, !tbaa !5
  %25 = fadd double %24, %22
  store double %25, ptr %0, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %23, i64 24
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = fadd double %27, %21
  store double %28, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %23, i64 48
  %30 = load double, ptr %29, align 8, !tbaa !5
  %31 = fadd double %30, %20
  store double %31, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %23, i64 8
  %33 = load double, ptr %32, align 8, !tbaa !5
  %34 = fadd double %33, %19
  store double %34, ptr %7, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %23, i64 32
  %36 = load double, ptr %35, align 8, !tbaa !5
  %37 = fadd double %36, %18
  store double %37, ptr %8, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %23, i64 56
  %39 = load double, ptr %38, align 8, !tbaa !5
  %40 = fadd double %39, %17
  store double %40, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %23, i64 16
  %42 = load double, ptr %41, align 8, !tbaa !5
  %43 = fadd double %42, %16
  store double %43, ptr %10, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %23, i64 40
  %45 = load double, ptr %44, align 8, !tbaa !5
  %46 = fadd double %45, %15
  store double %46, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %23, i64 64
  %48 = load double, ptr %47, align 8, !tbaa !5
  %49 = fadd double %48, %14
  store double %49, ptr %12, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %13, !llvm.loop !9

._crit_edge:                                      ; preds = %13, %3
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare void @mat33_clear(ptr noundef) local_unnamed_addr #1

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" }
attributes #1 = { inlinehint 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, !6, i64 0}
!6 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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