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

; 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.cross_entropy_loss_functions_struct = type { ptr, ptr, ptr, ptr }
%struct.nfs_class_net = type { i32, ptr, ptr, ptr, ptr, %struct.model_data, %struct.model_multithreading, %struct.model_state, ptr, ptr, %struct.nfs_net_data_stat, %struct.nfs_norm_data_stat, float, i32 }
%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.nfs_net_data_stat = type { i64 }
%struct.nfs_norm_data_stat = type { i64, ptr, ptr, ptr, ptr }
%struct.layers = type { ptr, ptr }
%struct.layer = type { ptr, i32, ptr, ptr }
%struct.loss = type { ptr, i32 }

@cross_entropy_loss_functions = external global %struct.cross_entropy_loss_functions_struct, align 8

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

declare void @kml_free(ptr noundef) #1

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

declare void @free_matrix(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @clean_nfs_class_net(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.nfs_class_net, ptr %4, i32 0, i32 5
  %6 = getelementptr inbounds %struct.model_data, ptr %5, i32 0, i32 2
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  call void @free_matrix(ptr noundef %7)
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.nfs_class_net, ptr %8, i32 0, i32 5
  %10 = getelementptr inbounds %struct.model_data, ptr %9, i32 0, i32 3
  %11 = load ptr, ptr %10, align 8, !tbaa !19
  call void @free_matrix(ptr noundef %11)
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.nfs_class_net, ptr %12, i32 0, i32 8
  %14 = load ptr, ptr %13, align 8, !tbaa !20
  call void @free_matrix(ptr noundef %14)
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.nfs_class_net, ptr %15, i32 0, i32 9
  %17 = load ptr, ptr %16, align 8, !tbaa !21
  call void @free_matrix(ptr noundef %17)
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.nfs_class_net, ptr %18, i32 0, i32 11
  %20 = getelementptr inbounds %struct.nfs_norm_data_stat, ptr %19, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !22
  call void @free_matrix(ptr noundef %21)
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.nfs_class_net, ptr %22, i32 0, i32 11
  %24 = getelementptr inbounds %struct.nfs_norm_data_stat, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !23
  call void @free_matrix(ptr noundef %25)
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.nfs_class_net, ptr %26, i32 0, i32 11
  %28 = getelementptr inbounds %struct.nfs_norm_data_stat, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !24
  call void @free_matrix(ptr noundef %29)
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.nfs_class_net, ptr %30, i32 0, i32 11
  %32 = getelementptr inbounds %struct.nfs_norm_data_stat, ptr %31, i32 0, i32 4
  %33 = load ptr, ptr %32, align 8, !tbaa !25
  call void @free_matrix(ptr noundef %33)
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.nfs_class_net, ptr %34, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !26
  %37 = getelementptr inbounds %struct.layers, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !27
  store ptr %38, ptr %3, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %56, %1
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %60

42:                                               ; preds = %39
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.layer, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !29
  switch i32 %45, label %54 [
    i32 0, label %46
    i32 1, label %50
  ]

46:                                               ; preds = %42
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.layer, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !31
  call void @clean_linear_layer(ptr noundef %49)
  br label %55

50:                                               ; preds = %42
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.layer, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %52, align 8, !tbaa !31
  call void @clean_sigmoid_layer(ptr noundef %53)
  br label %54

54:                                               ; preds = %50, %42
  br label %55

55:                                               ; preds = %54, %46
  br label %56

56:                                               ; preds = %55
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.layer, ptr %57, i32 0, i32 2
  %59 = load ptr, ptr %58, align 8, !tbaa !32
  store ptr %59, ptr %3, align 8, !tbaa !5
  br label %39, !llvm.loop !33

60:                                               ; preds = %39
  %61 = load ptr, ptr %2, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.nfs_class_net, ptr %61, i32 0, i32 6
  call void @clean_multithreading_execution(ptr noundef %62)
  %63 = load ptr, ptr %2, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.nfs_class_net, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !35
  call void @cleanup_sgd_optimizer(ptr noundef %65)
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.nfs_class_net, ptr %66, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !26
  call void @delete_layers(ptr noundef %68)
  %69 = load ptr, ptr getelementptr inbounds (%struct.cross_entropy_loss_functions_struct, ptr @cross_entropy_loss_functions, i32 0, i32 3), align 8, !tbaa !36
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.nfs_class_net, ptr %70, i32 0, i32 2
  %72 = load ptr, ptr %71, align 8, !tbaa !38
  %73 = getelementptr inbounds %struct.loss, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !39
  call void %69(ptr noundef %74)
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.nfs_class_net, ptr %75, i32 0, i32 2
  %77 = load ptr, ptr %76, align 8, !tbaa !38
  call void @kml_free(ptr noundef %77)
  %78 = load ptr, ptr %2, align 8, !tbaa !5
  call void @kml_free(ptr noundef %78)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare void @clean_linear_layer(ptr noundef) #1

declare void @clean_sigmoid_layer(ptr noundef) #1

declare void @clean_multithreading_execution(ptr noundef) #1

declare void @cleanup_sgd_optimizer(ptr noundef) #1

declare void @delete_layers(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 56}
!10 = !{!"nfs_class_net", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !13, i64 72, !15, i64 744, !6, i64 752, !6, i64 760, !16, i64 768, !17, i64 776, !18, i64 816, !11, i64 820}
!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 = !{!"nfs_net_data_stat", !14, i64 0}
!17 = !{!"nfs_norm_data_stat", !14, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!18 = !{!"float", !7, i64 0}
!19 = !{!10, !6, i64 64}
!20 = !{!10, !6, i64 752}
!21 = !{!10, !6, i64 760}
!22 = !{!10, !6, i64 800}
!23 = !{!10, !6, i64 784}
!24 = !{!10, !6, i64 792}
!25 = !{!10, !6, i64 808}
!26 = !{!10, !6, i64 24}
!27 = !{!28, !6, i64 0}
!28 = !{!"layers", !6, i64 0, !6, i64 8}
!29 = !{!30, !11, i64 8}
!30 = !{!"layer", !6, i64 0, !11, i64 8, !6, i64 16, !6, i64 24}
!31 = !{!30, !6, i64 0}
!32 = !{!30, !6, i64 16}
!33 = distinct !{!33, !34}
!34 = !{!"llvm.loop.mustprogress"}
!35 = !{!10, !6, i64 8}
!36 = !{!37, !6, i64 24}
!37 = !{!"cross_entropy_loss_functions_struct", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!38 = !{!10, !6, i64 16}
!39 = !{!40, !6, i64 0}
!40 = !{!"loss", !6, i64 0, !11, i64 8}


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

%struct.cross_entropy_loss_functions_struct = type { ptr, ptr, ptr, ptr }

@cross_entropy_loss_functions = external local_unnamed_addr global %struct.cross_entropy_loss_functions_struct, align 8

declare void @kml_free(ptr noundef) local_unnamed_addr #0

declare void @free_matrix(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @clean_nfs_class_net(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 56
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @free_matrix(ptr noundef %3) #2
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = load ptr, ptr %4, align 8, !tbaa !18
  tail call void @free_matrix(ptr noundef %5) #2
  %6 = getelementptr inbounds i8, ptr %0, i64 752
  %7 = load ptr, ptr %6, align 8, !tbaa !19
  tail call void @free_matrix(ptr noundef %7) #2
  %8 = getelementptr inbounds i8, ptr %0, i64 760
  %9 = load ptr, ptr %8, align 8, !tbaa !20
  tail call void @free_matrix(ptr noundef %9) #2
  %10 = getelementptr inbounds i8, ptr %0, i64 800
  %11 = load ptr, ptr %10, align 8, !tbaa !21
  tail call void @free_matrix(ptr noundef %11) #2
  %12 = getelementptr inbounds i8, ptr %0, i64 784
  %13 = load ptr, ptr %12, align 8, !tbaa !22
  tail call void @free_matrix(ptr noundef %13) #2
  %14 = getelementptr inbounds i8, ptr %0, i64 792
  %15 = load ptr, ptr %14, align 8, !tbaa !23
  tail call void @free_matrix(ptr noundef %15) #2
  %16 = getelementptr inbounds i8, ptr %0, i64 808
  %17 = load ptr, ptr %16, align 8, !tbaa !24
  tail call void @free_matrix(ptr noundef %17) #2
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  %19 = load ptr, ptr %18, align 8, !tbaa !25
  %.020 = load ptr, ptr %19, align 8, !tbaa !26
  %.not21 = icmp eq ptr %.020, null
  br i1 %.not21, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %26
  %.022 = phi ptr [ %.0, %26 ], [ %.020, %1 ]
  %20 = getelementptr inbounds i8, ptr %.022, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !27
  switch i32 %21, label %26 [
    i32 0, label %22
    i32 1, label %24
  ]

22:                                               ; preds = %.lr.ph
  %23 = load ptr, ptr %.022, align 8, !tbaa !29
  tail call void @clean_linear_layer(ptr noundef %23) #2
  br label %26

24:                                               ; preds = %.lr.ph
  %25 = load ptr, ptr %.022, align 8, !tbaa !29
  tail call void @clean_sigmoid_layer(ptr noundef %25) #2
  br label %26

26:                                               ; preds = %22, %24, %.lr.ph
  %27 = getelementptr inbounds i8, ptr %.022, i64 16
  %.0 = load ptr, ptr %27, align 8, !tbaa !26
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !30

._crit_edge:                                      ; preds = %26, %1
  %28 = getelementptr inbounds i8, ptr %0, i64 72
  tail call void @clean_multithreading_execution(ptr noundef nonnull %28) #2
  %29 = getelementptr inbounds i8, ptr %0, i64 8
  %30 = load ptr, ptr %29, align 8, !tbaa !32
  tail call void @cleanup_sgd_optimizer(ptr noundef %30) #2
  %31 = load ptr, ptr %18, align 8, !tbaa !25
  tail call void @delete_layers(ptr noundef %31) #2
  %32 = load ptr, ptr getelementptr inbounds (i8, ptr @cross_entropy_loss_functions, i64 24), align 8, !tbaa !33
  %33 = getelementptr inbounds i8, ptr %0, i64 16
  %34 = load ptr, ptr %33, align 8, !tbaa !35
  %35 = load ptr, ptr %34, align 8, !tbaa !36
  tail call void %32(ptr noundef %35) #2
  %36 = load ptr, ptr %33, align 8, !tbaa !35
  tail call void @kml_free(ptr noundef %36) #2
  tail call void @kml_free(ptr noundef %0) #2
  ret void
}

declare void @clean_linear_layer(ptr noundef) local_unnamed_addr #0

declare void @clean_sigmoid_layer(ptr noundef) local_unnamed_addr #0

declare void @clean_multithreading_execution(ptr noundef) local_unnamed_addr #0

declare void @cleanup_sgd_optimizer(ptr noundef) local_unnamed_addr #0

declare void @delete_layers(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 56}
!6 = !{!"nfs_class_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, !16, i64 776, !17, i64 816, !7, i64 820}
!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 = !{!"nfs_net_data_stat", !13, i64 0}
!16 = !{!"nfs_norm_data_stat", !13, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!17 = !{!"float", !8, i64 0}
!18 = !{!6, !10, i64 64}
!19 = !{!6, !10, i64 752}
!20 = !{!6, !10, i64 760}
!21 = !{!6, !10, i64 800}
!22 = !{!6, !10, i64 784}
!23 = !{!6, !10, i64 792}
!24 = !{!6, !10, i64 808}
!25 = !{!6, !10, i64 24}
!26 = !{!10, !10, i64 0}
!27 = !{!28, !7, i64 8}
!28 = !{!"layer", !10, i64 0, !7, i64 8, !10, i64 16, !10, i64 24}
!29 = !{!28, !10, i64 0}
!30 = distinct !{!30, !31}
!31 = !{!"llvm.loop.mustprogress"}
!32 = !{!6, !10, i64 8}
!33 = !{!34, !10, i64 24}
!34 = !{!"cross_entropy_loss_functions_struct", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!35 = !{!6, !10, i64 16}
!36 = !{!37, !10, i64 0}
!37 = !{!"loss", !10, i64 0, !7, i64 8}


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