; LLVM IR from sbu-fsl/kernel-ml :: examples (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.layers = type { ptr, ptr }

@.str.9 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [71 x i8], align 1
@iter = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local void @data_processing(ptr noundef) #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 void @simulation(ptr noundef) #0

; 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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 1, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = call ptr @build_readahead_net(float noundef 0x3F847AE140000000, i32 noundef 1, float noundef 0x3FECCCCCC0000000, i32 noundef 5)
  store ptr %5, ptr %3, align 8, !tbaa !9
  %6 = load ptr, ptr %3, align 8, !tbaa !9
  %7 = getelementptr inbounds %struct.readahead_net, ptr %6, i32 0, i32 7
  %8 = getelementptr inbounds %struct.model_state, ptr %7, i32 0, i32 0
  store atomic i8 0, ptr %8 seq_cst, align 1, !tbaa !11
  %9 = load ptr, ptr %3, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.readahead_net, ptr %9, i32 0, i32 3
  %11 = load ptr, ptr %10, align 8, !tbaa !20
  %12 = getelementptr inbounds %struct.layers, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !21
  call void @set_weights_biases_from_file(ptr noundef %13, ptr noundef @.str.9, ptr noundef @.str.10)
  %14 = load ptr, ptr %3, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.readahead_net, ptr %14, i32 0, i32 3
  %16 = load ptr, ptr %15, align 8, !tbaa !20
  %17 = getelementptr inbounds %struct.layers, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !23
  call void @set_weights_biases_from_file(ptr noundef %18, ptr noundef @.str.11, ptr noundef @.str.12)
  %19 = load ptr, ptr %3, align 8, !tbaa !9
  call void @data_processing(ptr noundef %19)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %28, %0
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = icmp slt i32 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %31

25:                                               ; preds = %20
  %26 = load ptr, ptr %3, align 8, !tbaa !9
  call void @simulation(ptr noundef %26)
  %27 = load ptr, ptr %3, align 8, !tbaa !9
  call void @reset_readahead_net(ptr noundef %27)
  store i32 0, ptr @iter, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %25
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %4, align 4, !tbaa !5
  br label %20, !llvm.loop !24

31:                                               ; preds = %24
  %32 = load ptr, ptr %3, align 8, !tbaa !9
  call void @clean_readahead_net(ptr noundef %32)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  %33 = load i32, ptr %1, align 4
  ret i32 %33
}

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

declare void @set_weights_biases_from_file(ptr noundef, ptr noundef, ptr noundef) #2

declare void @reset_readahead_net(ptr noundef) #2

declare void @clean_readahead_net(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 = !{!"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, !7, i64 744}
!12 = !{!"readahead_net", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !13, i64 40, !14, i64 72, !16, i64 744, !10, i64 752, !10, i64 760, !17, i64 768, !19, i64 792}
!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 = !{!"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, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!20 = !{!12, !10, i64 24}
!21 = !{!22, !10, i64 0}
!22 = !{!"layers", !10, i64 0, !10, i64 8}
!23 = !{!22, !10, i64 8}
!24 = distinct !{!24, !25}
!25 = !{!"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"

@.str.9 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [71 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [68 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [71 x i8], align 1
@iter = external hidden local_unnamed_addr global i32, align 4

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
.critedge:
  %0 = tail call ptr @build_readahead_net(float noundef 0x3F847AE140000000, i32 noundef 1, float noundef 0x3FECCCCCC0000000, i32 noundef 5) #2
  %1 = getelementptr inbounds i8, ptr %0, i64 744
  store atomic i8 0, ptr %1 seq_cst, align 1, !tbaa !5
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = load ptr, ptr %2, align 8, !tbaa !18
  %4 = load ptr, ptr %3, align 8, !tbaa !19
  tail call void @set_weights_biases_from_file(ptr noundef %4, ptr noundef nonnull @.str.9, ptr noundef nonnull @.str.10) #2
  %5 = load ptr, ptr %2, align 8, !tbaa !18
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !21
  tail call void @set_weights_biases_from_file(ptr noundef %7, ptr noundef nonnull @.str.11, ptr noundef nonnull @.str.12) #2
  tail call void @data_processing(ptr noundef %0)
  tail call void @simulation(ptr noundef %0)
  tail call void @reset_readahead_net(ptr noundef %0) #2
  store i32 0, ptr @iter, align 4, !tbaa !22
  tail call void @clean_readahead_net(ptr noundef %0) #2
  ret i32 0
}

declare ptr @build_readahead_net(float noundef, i32 noundef, float noundef, i32 noundef) local_unnamed_addr #1

declare void @set_weights_biases_from_file(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @reset_readahead_net(ptr noundef) local_unnamed_addr #1

declare void @clean_readahead_net(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, !8, i64 744}
!6 = !{!"readahead_net", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !11, i64 40, !12, i64 72, !14, i64 744, !10, i64 752, !10, i64 760, !15, i64 768, !17, i64 792}
!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 = !{!"readahead_net_data_stat", !13, i64 0, !16, i64 8, !16, i64 16}
!16 = !{!"double", !8, i64 0}
!17 = !{!"readahead_norm_data_stat", !13, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!18 = !{!6, !10, i64 24}
!19 = !{!20, !10, i64 0}
!20 = !{!"layers", !10, i64 0, !10, i64 8}
!21 = !{!20, !10, i64 8}
!22 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass