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

%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.sgd_optimizer = type { float, %union.val, %union.val, %union.val, ptr, ptr, ptr }
%union.val = type { double }
%struct.layers = type { ptr, ptr }
%struct.layer = type { ptr, i32, ptr, 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

declare void @kml_atomic_bool_init(ptr noundef, i1 noundef zeroext) #1

declare void @kml_atomic_int_init(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @reset_linear_regression(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.linear_regression, ptr %4, i32 0, i32 1
  %6 = load ptr, ptr %5, align 8, !tbaa !9
  %7 = getelementptr inbounds %struct.sgd_optimizer, ptr %6, i32 0, i32 5
  %8 = load ptr, ptr %7, align 8, !tbaa !16
  call void @reset_updates(ptr noundef %8)
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.linear_regression, ptr %9, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.sgd_optimizer, ptr %11, i32 0, i32 2
  store float 0.000000e+00, ptr %12, align 8, !tbaa !19
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.linear_regression, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds %struct.sgd_optimizer, ptr %15, i32 0, i32 1
  store float 0.000000e+00, ptr %16, align 8, !tbaa !19
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.linear_regression, ptr %17, i32 0, i32 7
  %19 = getelementptr inbounds %struct.model_state, ptr %18, i32 0, i32 0
  call void @kml_atomic_bool_init(ptr noundef %19, i1 noundef zeroext true)
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.linear_regression, ptr %20, i32 0, i32 7
  %22 = getelementptr inbounds %struct.model_state, ptr %21, i32 0, i32 1
  call void @kml_atomic_int_init(ptr noundef %22, i32 noundef 0)
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.linear_regression, ptr %23, i32 0, i32 3
  %25 = load ptr, ptr %24, align 8, !tbaa !20
  %26 = getelementptr inbounds %struct.layers, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !21
  store ptr %27, ptr %3, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %41, %1
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %45

31:                                               ; preds = %28
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.layer, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !23
  switch i32 %34, label %39 [
    i32 0, label %35
  ]

35:                                               ; preds = %31
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.layer, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !25
  call void @reset_linear_layer(ptr noundef %38)
  br label %40

39:                                               ; preds = %31
  br label %40

40:                                               ; preds = %39, %35
  br label %41

41:                                               ; preds = %40
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.layer, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !26
  store ptr %44, ptr %3, align 8, !tbaa !5
  br label %28, !llvm.loop !27

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

declare void @reset_updates(ptr noundef) #1

declare void @reset_linear_layer(ptr noundef) #1

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

declare void @kml_atomic_bool_init(ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

declare void @kml_atomic_int_init(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @reset_linear_regression(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 40
  %5 = load ptr, ptr %4, align 8, !tbaa !15
  tail call void @reset_updates(ptr noundef %5) #2
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  store float 0.000000e+00, ptr %7, align 8, !tbaa !18
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  store float 0.000000e+00, ptr %9, align 8, !tbaa !18
  %10 = getelementptr inbounds i8, ptr %0, i64 744
  tail call void @kml_atomic_bool_init(ptr noundef nonnull %10, i1 noundef zeroext true) #2
  %11 = getelementptr inbounds i8, ptr %0, i64 748
  tail call void @kml_atomic_int_init(ptr noundef nonnull %11, i32 noundef 0) #2
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = load ptr, ptr %12, align 8, !tbaa !19
  %.010 = load ptr, ptr %13, align 8, !tbaa !20
  %.not11 = icmp eq ptr %.010, null
  br i1 %.not11, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %18
  %.012 = phi ptr [ %.0, %18 ], [ %.010, %1 ]
  %14 = getelementptr inbounds i8, ptr %.012, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !21
  %cond = icmp eq i32 %15, 0
  br i1 %cond, label %16, label %18

16:                                               ; preds = %.lr.ph
  %17 = load ptr, ptr %.012, align 8, !tbaa !23
  tail call void @reset_linear_layer(ptr noundef %17) #2
  br label %18

18:                                               ; preds = %16, %.lr.ph
  %19 = getelementptr inbounds i8, ptr %.012, i64 16
  %.0 = load ptr, ptr %19, align 8, !tbaa !20
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !24

._crit_edge:                                      ; preds = %18, %1
  ret void
}

declare void @reset_updates(ptr noundef) local_unnamed_addr #0

declare void @reset_linear_layer(ptr noundef) local_unnamed_addr #0

attributes #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 = { 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, !10, i64 8}
!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, !10, i64 40}
!16 = !{!"sgd_optimizer", !17, i64 0, !8, i64 8, !8, i64 16, !8, i64 24, !10, i64 32, !10, i64 40, !10, i64 48}
!17 = !{!"float", !8, i64 0}
!18 = !{!8, !8, i64 0}
!19 = !{!6, !10, i64 24}
!20 = !{!10, !10, i64 0}
!21 = !{!22, !7, i64 8}
!22 = !{!"layer", !10, i64 0, !7, i64 8, !10, i64 16, !10, i64 24}
!23 = !{!22, !10, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}


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