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

; 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.readahead_net = type { i32, ptr, ptr, ptr, ptr, %struct.model_data, %struct.model_multithreading, %struct.model_state, ptr, ptr, %struct.readahead_net_data_stat, %struct.readahead_norm_data_stat }
%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.readahead_net_data_stat = type { i64, double, double }
%struct.readahead_norm_data_stat = type { i64, ptr, ptr, ptr, ptr }
%struct.matrix = type { i32, i32, i32, %union.anon }
%union.anon = type { ptr }

@readahead_test_list = external hidden constant [33 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local ptr @readahead_net_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

declare void @free_matrix(ptr noundef) #2

declare ptr @allocate_matrix(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @predict_readahead(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %8 = call ptr @allocate_matrix(i32 noundef 1, i32 noundef 33, i32 noundef 1)
  store ptr %8, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr null, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %51, %1
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 33
  br i1 %11, label %12, label %54

12:                                               ; preds = %9
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [33 x i32], ptr @readahead_test_list, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !9
  call void @readahead_normalized_online_data(ptr noundef %13, i32 noundef %17, i1 noundef zeroext false)
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.readahead_net, ptr %18, i32 0, i32 9
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = call ptr @matrix_float_conversion(ptr noundef %20)
  store ptr %21, ptr %5, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = call ptr @readahead_net_inference(ptr noundef %22, ptr noundef %23)
  store ptr %24, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.matrix, ptr %25, i32 0, i32 3
  %27 = load ptr, ptr %26, align 8, !tbaa !20
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.matrix, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !21
  %31 = mul nsw i32 0, %30
  %32 = add nsw i32 %31, 0
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds float, ptr %27, i64 %33
  %35 = load float, ptr %34, align 4, !tbaa !23
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.matrix, ptr %36, i32 0, i32 3
  %38 = load ptr, ptr %37, align 8, !tbaa !20
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.matrix, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !21
  %42 = mul nsw i32 0, %41
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = add nsw i32 %42, %43
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds float, ptr %38, i64 %45
  store float %35, ptr %46, align 4, !tbaa !23
  %47 = load ptr, ptr %2, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.readahead_net, ptr %47, i32 0, i32 3
  %49 = load ptr, ptr %48, align 8, !tbaa !25
  call void @cleanup_autodiff(ptr noundef %49)
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free_matrix(ptr noundef %50)
  br label %51

51:                                               ; preds = %12
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %7, align 4, !tbaa !9
  br label %9, !llvm.loop !26

54:                                               ; preds = %9
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.readahead_net, ptr %55, i32 0, i32 9
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  call void @print_matrix(ptr noundef %57)
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = call ptr @matrix_argsort(ptr noundef %58, ptr noundef @cmp_prediction)
  store ptr %59, ptr %4, align 8, !tbaa !5
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %60
}

declare void @readahead_normalized_online_data(ptr noundef, i32 noundef, i1 noundef zeroext) #2

declare ptr @matrix_float_conversion(ptr noundef) #2

declare void @print_matrix(ptr noundef) #2

declare ptr @matrix_argsort(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @cmp_prediction(ptr noundef, ptr noundef) #0

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 760}
!12 = !{!"readahead_net", !10, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !14, i64 72, !16, i64 744, !6, i64 752, !6, i64 760, !17, i64 768, !19, i64 792}
!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 = !{!"readahead_net_data_stat", !15, i64 0, !18, i64 8, !18, i64 16}
!18 = !{!"double", !7, i64 0}
!19 = !{!"readahead_norm_data_stat", !15, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!20 = !{!7, !7, i64 0}
!21 = !{!22, !10, i64 4}
!22 = !{!"matrix", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 16}
!23 = !{!24, !24, i64 0}
!24 = !{!"float", !7, i64 0}
!25 = !{!12, !6, i64 24}
!26 = distinct !{!26, !27}
!27 = !{!"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"

@readahead_test_list = external hidden local_unnamed_addr constant [33 x i32], align 16

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

declare void @cleanup_autodiff(ptr noundef) local_unnamed_addr #1

declare void @free_matrix(ptr noundef) local_unnamed_addr #1

declare ptr @allocate_matrix(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @predict_readahead(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call ptr @allocate_matrix(i32 noundef 1, i32 noundef 33, i32 noundef 1) #2
  %3 = getelementptr inbounds i8, ptr %0, i64 760
  %4 = getelementptr inbounds i8, ptr %2, i64 16
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  br label %6

6:                                                ; preds = %1, %6
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %6 ]
  %7 = getelementptr inbounds [33 x i32], ptr @readahead_test_list, i64 0, i64 %indvars.iv
  %8 = load i32, ptr %7, align 4, !tbaa !5
  tail call void @readahead_normalized_online_data(ptr noundef %0, i32 noundef %8, i1 noundef zeroext false) #2
  %9 = load ptr, ptr %3, align 8, !tbaa !9
  %10 = tail call ptr @matrix_float_conversion(ptr noundef %9) #2
  %11 = tail call ptr @readahead_net_inference(ptr noundef %10, ptr noundef %0)
  %12 = getelementptr inbounds i8, ptr %11, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !19
  %14 = load float, ptr %13, align 4, !tbaa !20
  %15 = load ptr, ptr %4, align 8, !tbaa !19
  %16 = getelementptr inbounds float, ptr %15, i64 %indvars.iv
  store float %14, ptr %16, align 4, !tbaa !20
  %17 = load ptr, ptr %5, align 8, !tbaa !22
  tail call void @cleanup_autodiff(ptr noundef %17) #2
  tail call void @free_matrix(ptr noundef %10) #2
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 33
  br i1 %exitcond.not, label %18, label %6, !llvm.loop !23

18:                                               ; preds = %6
  %19 = load ptr, ptr %3, align 8, !tbaa !9
  tail call void @print_matrix(ptr noundef %19) #2
  %20 = tail call ptr @matrix_argsort(ptr noundef nonnull %2, ptr noundef nonnull @cmp_prediction) #2
  ret ptr %20
}

declare void @readahead_normalized_online_data(ptr noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #1

declare ptr @matrix_float_conversion(ptr noundef) local_unnamed_addr #1

declare void @print_matrix(ptr noundef) local_unnamed_addr #1

declare ptr @matrix_argsort(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @cmp_prediction(ptr noundef, ptr noundef) #0

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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 760}
!10 = !{!"readahead_net", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !12, i64 40, !13, i64 72, !15, i64 744, !11, i64 752, !11, i64 760, !16, i64 768, !18, i64 792}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"model_data", !11, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!13 = !{!"model_multithreading", !7, i64 0, !7, i64 512, !7, i64 640, !7, i64 644, !7, i64 648, !14, i64 656, !11, i64 664}
!14 = !{!"long", !7, i64 0}
!15 = !{!"model_state", !7, i64 0, !7, i64 4}
!16 = !{!"readahead_net_data_stat", !14, i64 0, !17, i64 8, !17, i64 16}
!17 = !{!"double", !7, i64 0}
!18 = !{!"readahead_norm_data_stat", !14, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!19 = !{!7, !7, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"float", !7, i64 0}
!22 = !{!10, !11, i64 24}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass