; LLVM IR from sbu-fsl/kernel-ml :: src/models (linear_regression)

; 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"

%union.val = type { double }
%struct.linear_regression = type { i32, ptr, ptr, ptr, ptr, %struct.model_data, %struct.model_multithreading, %struct.model_state }
%struct.model_data = type { ptr, ptr, ptr, ptr }
%struct.model_multithreading = type { [32 x %struct.mt_buffer], [32 x i32], i32, i32, i32, i64, ptr }
%struct.mt_buffer = type { ptr, ptr }
%struct.model_state = type { i8, i32 }
%struct.matrix = type { i32, i32, i32, %union.anon }
%union.anon = type { ptr }

; Function Attrs: nounwind uwtable
declare dso_local ptr @linear_regression_inference(ptr noundef, ptr noundef) #0

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

declare void @cleanup_autodiff(ptr noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @linear_regression_test(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %union.val, align 8
  %9 = alloca %union.val, align 8
  %10 = alloca ptr, align 8
  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) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.linear_regression, ptr %11, i32 0, i32 5
  %13 = getelementptr inbounds %struct.model_data, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = call ptr @linear_regression_inference(ptr noundef %14, ptr noundef %15)
  store ptr %16, ptr %10, align 8, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %79, %2
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.matrix, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !17
  %22 = icmp slt i32 %18, %21
  br i1 %22, label %23, label %82

23:                                               ; preds = %17
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %75, %23
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.matrix, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !19
  %29 = icmp slt i32 %25, %28
  br i1 %29, label %30, label %78

30:                                               ; preds = %24
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.matrix, ptr %31, i32 0, i32 3
  %33 = load ptr, ptr %32, align 8, !tbaa !20
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.matrix, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !19
  %38 = mul nsw i32 %34, %37
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = add nsw i32 %38, %39
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds float, ptr %33, i64 %41
  %43 = load float, ptr %42, align 4, !tbaa !21
  store float %43, ptr %8, align 8, !tbaa !20
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.linear_regression, ptr %44, i32 0, i32 5
  %46 = getelementptr inbounds %struct.model_data, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !23
  %48 = getelementptr inbounds %struct.matrix, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !20
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.linear_regression, ptr %51, i32 0, i32 5
  %53 = getelementptr inbounds %struct.model_data, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !23
  %55 = getelementptr inbounds %struct.matrix, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !19
  %57 = mul nsw i32 %50, %56
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = add nsw i32 %57, %58
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds float, ptr %49, i64 %60
  %62 = load float, ptr %61, align 4, !tbaa !21
  store float %62, ptr %9, align 8, !tbaa !20
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.linear_regression, ptr %63, i32 0, i32 4
  %65 = load ptr, ptr %64, align 8, !tbaa !24
  %66 = getelementptr inbounds %union.val, ptr %9, i32 0, i32 0
  %67 = load i64, ptr %66, align 8
  %68 = getelementptr inbounds %union.val, ptr %8, i32 0, i32 0
  %69 = load i64, ptr %68, align 8
  %70 = call zeroext i1 %65(i64 %67, i64 %69)
  br i1 %70, label %71, label %74

71:                                               ; preds = %30
  %72 = load i32, ptr %5, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %5, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %71, %30
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %7, align 4, !tbaa !9
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %7, align 4, !tbaa !9
  br label %24, !llvm.loop !25

78:                                               ; preds = %24
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %6, align 4, !tbaa !9
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %6, align 4, !tbaa !9
  br label %17, !llvm.loop !27

82:                                               ; preds = %17
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  %84 = call ptr @copy_matrix(ptr noundef %83)
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %84, ptr %85, align 8, !tbaa !5
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.linear_regression, ptr %86, i32 0, i32 3
  %88 = load ptr, ptr %87, align 8, !tbaa !28
  call void @cleanup_autodiff(ptr noundef %88)
  %89 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %89
}

declare ptr @copy_matrix(ptr noundef) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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, !6, i64 40}
!12 = !{!"linear_regression", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !14, i64 72, !16, i64 744}
!13 = !{!"model_data", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!14 = !{!"model_multithreading", !7, i64 0, !7, i64 512, !7, i64 640, !7, i64 644, !7, i64 648, !15, i64 656, !6, i64 664}
!15 = !{!"long", !7, i64 0}
!16 = !{!"model_state", !7, i64 0, !7, i64 4}
!17 = !{!18, !10, i64 0}
!18 = !{!"matrix", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 16}
!19 = !{!18, !10, i64 4}
!20 = !{!7, !7, i64 0}
!21 = !{!22, !22, i64 0}
!22 = !{!"float", !7, i64 0}
!23 = !{!12, !6, i64 48}
!24 = !{!12, !6, i64 32}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}
!27 = distinct !{!27, !26}
!28 = !{!12, !6, i64 24}


; 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: nounwind uwtable
declare dso_local ptr @linear_regression_inference(ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @cleanup_autodiff(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @linear_regression_test(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call ptr @linear_regression_inference(ptr noundef %4, ptr noundef %0)
  %6 = load i32, ptr %5, align 8, !tbaa !15
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.preheader.lr.ph, label %._crit_edge30

.preheader.lr.ph:                                 ; preds = %2
  %8 = getelementptr inbounds i8, ptr %5, i64 4
  %9 = getelementptr inbounds i8, ptr %5, i64 16
  %10 = getelementptr inbounds i8, ptr %0, i64 48
  %11 = getelementptr inbounds i8, ptr %0, i64 32
  %12 = load i32, ptr %8, align 4, !tbaa !17
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.preheader, label %._crit_edge30

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %14 = phi i32 [ %40, %._crit_edge ], [ %6, %.preheader.lr.ph ]
  %15 = phi i32 [ %41, %._crit_edge ], [ %12, %.preheader.lr.ph ]
  %.029 = phi i32 [ %.1.lcssa, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %.02328 = phi i32 [ %42, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %17 = phi i32 [ %38, %.lr.ph ], [ %15, %.preheader ]
  %.127 = phi i32 [ %spec.select, %.lr.ph ], [ %.029, %.preheader ]
  %.02426 = phi i32 [ %37, %.lr.ph ], [ 0, %.preheader ]
  %18 = load ptr, ptr %9, align 8, !tbaa !18
  %19 = mul nsw i32 %17, %.02328
  %20 = add nsw i32 %19, %.02426
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds float, ptr %18, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !19
  %24 = load ptr, ptr %10, align 8, !tbaa !21
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !18
  %27 = getelementptr inbounds i8, ptr %24, i64 4
  %28 = load i32, ptr %27, align 4, !tbaa !17
  %29 = mul nsw i32 %28, %.02328
  %30 = add nsw i32 %29, %.02426
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds float, ptr %26, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !19
  %34 = load ptr, ptr %11, align 8, !tbaa !22
  %.sroa.0.0.insert.ext = zext i32 %33 to i64
  %.sroa.05.0.insert.ext = zext i32 %23 to i64
  %35 = tail call zeroext i1 %34(i64 %.sroa.0.0.insert.ext, i64 %.sroa.05.0.insert.ext) #2
  %36 = zext i1 %35 to i32
  %spec.select = add nsw i32 %.127, %36
  %37 = add nuw nsw i32 %.02426, 1
  %38 = load i32, ptr %8, align 4, !tbaa !17
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !23

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %5, align 8, !tbaa !15
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %40 = phi i32 [ %14, %.preheader ], [ %.pre, %._crit_edge.loopexit ]
  %41 = phi i32 [ %15, %.preheader ], [ %38, %._crit_edge.loopexit ]
  %.1.lcssa = phi i32 [ %.029, %.preheader ], [ %spec.select, %._crit_edge.loopexit ]
  %42 = add nuw nsw i32 %.02328, 1
  %43 = icmp slt i32 %42, %40
  br i1 %43, label %.preheader, label %._crit_edge30, !llvm.loop !25

._crit_edge30:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %2
  %.0.lcssa = phi i32 [ 0, %2 ], [ 0, %.preheader.lr.ph ], [ %.1.lcssa, %._crit_edge ]
  %44 = tail call ptr @copy_matrix(ptr noundef nonnull %5) #2
  store ptr %44, ptr %1, align 8, !tbaa !27
  %45 = getelementptr inbounds i8, ptr %0, i64 24
  %46 = load ptr, ptr %45, align 8, !tbaa !28
  tail call void @cleanup_autodiff(ptr noundef %46) #2
  ret i32 %.0.lcssa
}

declare ptr @copy_matrix(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 = { "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, !10, i64 40}
!6 = !{!"linear_regression", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !11, i64 40, !12, i64 72, !14, i64 744}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"model_data", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!12 = !{!"model_multithreading", !8, i64 0, !8, i64 512, !8, i64 640, !8, i64 644, !8, i64 648, !13, i64 656, !10, i64 664}
!13 = !{!"long", !8, i64 0}
!14 = !{!"model_state", !8, i64 0, !8, i64 4}
!15 = !{!16, !7, i64 0}
!16 = !{!"matrix", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 16}
!17 = !{!16, !7, i64 4}
!18 = !{!8, !8, i64 0}
!19 = !{!20, !20, i64 0}
!20 = !{!"float", !8, i64 0}
!21 = !{!6, !10, i64 48}
!22 = !{!6, !10, i64 32}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24, !26}
!26 = !{!"llvm.loop.unswitch.partial.disable"}
!27 = !{!10, !10, i64 0}
!28 = !{!6, !10, i64 24}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass