; LLVM IR from sbu-fsl/kernel-ml :: examples (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 }

@iter = external hidden global i32, align 4
@timing_sum = external hidden global float, align 4
@acc_sum = external hidden global float, align 4
@.str.7 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @linear_example_check_correction(i64, i64) #0

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

; 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
declare dso_local float @simulation(ptr noundef) #0

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca float, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 100, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %6 = call ptr @build_linear_regression(float noundef 0x3F9EB851E0000000, i32 noundef 10, float noundef 0x3FEFAE1480000000, i32 noundef 2)
  store ptr %6, ptr %3, align 8, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct.linear_regression, ptr %7, i32 0, i32 4
  store ptr @linear_example_check_correction, ptr %8, align 8, !tbaa !11
  %9 = call i64 @time(ptr noundef null) #4
  %10 = trunc i64 %9 to i32
  call void @srand(i32 noundef %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %23, %0
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp slt i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %26

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %17 = load ptr, ptr %3, align 8, !tbaa !9
  %18 = call float @simulation(ptr noundef %17)
  store float %18, ptr %5, align 4, !tbaa !17
  %19 = load ptr, ptr %3, align 8, !tbaa !9
  call void @reset_linear_regression(ptr noundef %19)
  store i32 0, ptr @iter, align 4, !tbaa !5
  %20 = load float, ptr %5, align 4, !tbaa !17
  %21 = load float, ptr @acc_sum, align 4, !tbaa !17
  %22 = fadd float %21, %20
  store float %22, ptr @acc_sum, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %23

23:                                               ; preds = %16
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %4, align 4, !tbaa !5
  br label %11, !llvm.loop !19

26:                                               ; preds = %15
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  %28 = load float, ptr @acc_sum, align 4, !tbaa !17
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sitofp i32 %29 to float
  %31 = fdiv float %28, %30
  %32 = fpext float %31 to double
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, double noundef %32)
  %34 = load float, ptr @timing_sum, align 4, !tbaa !17
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sitofp i32 %35 to float
  %37 = fdiv float %34, %36
  %38 = fmul float %37, 1.000000e+03
  %39 = fpext float %38 to double
  %40 = call i32 (ptr, ...) @printf(ptr noundef @.str.9, double noundef %39)
  %41 = load ptr, ptr %3, align 8, !tbaa !9
  call void @clean_linear_regression(ptr noundef %41)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %42 = load i32, ptr %1, align 4
  ret i32 %42
}

declare ptr @build_linear_regression(float noundef, i32 noundef, float noundef, i32 noundef) #2

; Function Attrs: nounwind
declare void @srand(i32 noundef) #3

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #3

declare void @reset_linear_regression(ptr noundef) #2

declare void @clean_linear_regression(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 "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 #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 32}
!12 = !{!"linear_regression", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !13, i64 40, !14, i64 72, !16, i64 744}
!13 = !{!"model_data", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!14 = !{!"model_multithreading", !7, i64 0, !7, i64 512, !7, i64 640, !7, i64 644, !7, i64 648, !15, i64 656, !10, i64 664}
!15 = !{!"long", !7, i64 0}
!16 = !{!"model_state", !7, i64 0, !7, i64 4}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"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"

@iter = external hidden local_unnamed_addr global i32, align 4
@timing_sum = external hidden local_unnamed_addr global float, align 4
@acc_sum = external hidden local_unnamed_addr global float, align 4
@.str.7 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @linear_example_check_correction(i64, i64) #0

; Function Attrs: nounwind uwtable
declare dso_local float @simulation(ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call ptr @build_linear_regression(float noundef 0x3F9EB851E0000000, i32 noundef 10, float noundef 0x3FEFAE1480000000, i32 noundef 2) #4
  %2 = getelementptr inbounds i8, ptr %1, i64 32
  store ptr @linear_example_check_correction, ptr %2, align 8, !tbaa !5
  %3 = tail call i64 @time(ptr noundef null) #4
  %4 = trunc i64 %3 to i32
  tail call void @srand(i32 noundef %4) #4
  br label %16

5:                                                ; preds = %16
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  %7 = load float, ptr @acc_sum, align 4, !tbaa !15
  %8 = fdiv float %7, 1.000000e+02
  %9 = fpext float %8 to double
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, double noundef %9)
  %11 = load float, ptr @timing_sum, align 4, !tbaa !15
  %12 = fdiv float %11, 1.000000e+02
  %13 = fmul float %12, 1.000000e+03
  %14 = fpext float %13 to double
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.9, double noundef %14)
  tail call void @clean_linear_regression(ptr noundef %1) #4
  ret i32 0

16:                                               ; preds = %0, %16
  %.010 = phi i32 [ 0, %0 ], [ %20, %16 ]
  %17 = tail call float @simulation(ptr noundef %1)
  tail call void @reset_linear_regression(ptr noundef %1) #4
  store i32 0, ptr @iter, align 4, !tbaa !17
  %18 = load float, ptr @acc_sum, align 4, !tbaa !15
  %19 = fadd float %17, %18
  store float %19, ptr @acc_sum, align 4, !tbaa !15
  %20 = add nuw nsw i32 %.010, 1
  %exitcond.not = icmp eq i32 %20, 100
  br i1 %exitcond.not, label %5, label %16, !llvm.loop !18
}

declare ptr @build_linear_regression(float noundef, i32 noundef, float noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #3

declare void @reset_linear_regression(ptr noundef) local_unnamed_addr #2

declare void @clean_linear_regression(ptr noundef) local_unnamed_addr #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 = { nofree nounwind "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 = { "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 "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 #4 = { 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 32}
!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, !16, i64 0}
!16 = !{!"float", !8, i64 0}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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