; LLVM IR from sbu-fsl/kernel-ml :: src/decision-tree (decision_tree)

; 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.kml_dt = type { ptr }
%struct.kml_dt_node = type { i32, i32, float, ptr, ptr }
%struct.matrix = type { i32, i32, i32, %union.anon }
%union.anon = type { 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

; Function Attrs: nounwind uwtable
define dso_local i32 @predict_decision_tree(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.kml_dt, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store float 0.000000e+00, ptr %6, align 4, !tbaa !11
  br label %10

10:                                               ; preds = %43, %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.kml_dt_node, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !13
  %14 = icmp ne i32 %13, -1
  br i1 %14, label %15, label %44

15:                                               ; preds = %10
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.matrix, ptr %16, i32 0, i32 3
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.matrix, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !17
  %22 = mul nsw i32 0, %21
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.kml_dt_node, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = add nsw i32 %22, %25
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds float, ptr %18, i64 %27
  %29 = load float, ptr %28, align 4, !tbaa !11
  store float %29, ptr %6, align 4, !tbaa !11
  %30 = load float, ptr %6, align 4, !tbaa !11
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.kml_dt_node, ptr %31, i32 0, i32 2
  %33 = load float, ptr %32, align 8, !tbaa !19
  %34 = fcmp ole float %30, %33
  br i1 %34, label %35, label %39

35:                                               ; preds = %15
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.kml_dt_node, ptr %36, i32 0, i32 3
  %38 = load ptr, ptr %37, align 8, !tbaa !20
  store ptr %38, ptr %5, align 8, !tbaa !5
  br label %43

39:                                               ; preds = %15
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.kml_dt_node, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !21
  store ptr %42, ptr %5, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %39, %35
  br label %10, !llvm.loop !22

44:                                               ; preds = %10
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.kml_dt_node, ptr %45, i32 0, i32 2
  %47 = load float, ptr %46, align 8, !tbaa !19
  %48 = fptosi float %47 to i32
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i32 %48
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"kml_dt", !6, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"kml_dt_node", !15, i64 0, !15, i64 4, !12, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!"int", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !15, i64 4}
!18 = !{!"matrix", !15, i64 0, !15, i64 4, !15, i64 8, !7, i64 16}
!19 = !{!14, !12, i64 8}
!20 = !{!14, !6, i64 16}
!21 = !{!14, !6, i64 24}
!22 = distinct !{!22, !23}
!23 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local i32 @predict_decision_tree(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %.011 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = load i32, ptr %.011, align 8, !tbaa !9
  %.not12 = icmp eq i32 %3, -1
  br i1 %.not12, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %4 = getelementptr inbounds i8, ptr %1, i64 16
  %5 = load ptr, ptr %4, align 8, !tbaa !13
  br label %6

6:                                                ; preds = %.lr.ph, %6
  %7 = phi i32 [ %3, %.lr.ph ], [ %14, %6 ]
  %.013 = phi ptr [ %.011, %.lr.ph ], [ %.0, %6 ]
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds float, ptr %5, i64 %8
  %10 = load float, ptr %9, align 4, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %.013, i64 8
  %12 = load float, ptr %11, align 8, !tbaa !15
  %13 = fcmp ugt float %10, %12
  %.1.in.v = select i1 %13, i64 24, i64 16
  %.1.in = getelementptr inbounds i8, ptr %.013, i64 %.1.in.v
  %.0 = load ptr, ptr %.1.in, align 8, !tbaa !5
  %14 = load i32, ptr %.0, align 8, !tbaa !9
  %.not = icmp eq i32 %14, -1
  br i1 %.not, label %._crit_edge, label %6, !llvm.loop !16

._crit_edge:                                      ; preds = %6, %2
  %.0.lcssa = phi ptr [ %.011, %2 ], [ %.0, %6 ]
  %15 = getelementptr inbounds i8, ptr %.0.lcssa, i64 8
  %16 = load float, ptr %15, align 8, !tbaa !15
  %17 = fptosi float %16 to i32
  ret i32 %17
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) 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" }

!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, !11, i64 0}
!10 = !{!"kml_dt_node", !11, i64 0, !11, i64 4, !12, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !12, i64 0}
!15 = !{!10, !12, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass