; LLVM IR from huawei-noah/bolt :: compute/tensor/src/kl.ll (Z11compute_KLDjPKfS0_)

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

; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #1

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

9:                                                ; preds = %53, %3
  %10 = load i32, ptr %8, align 4, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = icmp ult i32 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %56

14:                                               ; preds = %9
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = load i32, ptr %8, align 4, !tbaa !5
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds float, ptr %15, i64 %17
  %19 = load float, ptr %18, align 4, !tbaa !11
  %20 = fcmp une float 0.000000e+00, %19
  br i1 %20, label %21, label %52

21:                                               ; preds = %14
  %22 = load ptr, ptr %6, align 8, !tbaa !9
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds float, ptr %22, i64 %24
  %26 = load float, ptr %25, align 4, !tbaa !11
  %27 = fcmp oeq float 0.000000e+00, %26
  br i1 %27, label %28, label %31

28:                                               ; preds = %21
  %29 = load float, ptr %7, align 4, !tbaa !11
  %30 = fadd float %29, 1.000000e+00
  store float %30, ptr %7, align 4, !tbaa !11
  br label %51

31:                                               ; preds = %21
  %32 = load ptr, ptr %5, align 8, !tbaa !9
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = zext i32 %33 to i64
  %35 = getelementptr inbounds float, ptr %32, i64 %34
  %36 = load float, ptr %35, align 4, !tbaa !11
  %37 = load ptr, ptr %5, align 8, !tbaa !9
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds float, ptr %37, i64 %39
  %41 = load float, ptr %40, align 4, !tbaa !11
  %42 = load ptr, ptr %6, align 8, !tbaa !9
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds float, ptr %42, i64 %44
  %46 = load float, ptr %45, align 4, !tbaa !11
  %47 = fdiv float %41, %46
  %48 = call noundef float @_ZSt3logf(float noundef %47)
  %49 = load float, ptr %7, align 4, !tbaa !11
  %50 = call float @llvm.fmuladd.f32(float %36, float %48, float %49)
  store float %50, ptr %7, align 4, !tbaa !11
  br label %51

51:                                               ; preds = %31, %28
  br label %52

52:                                               ; preds = %51, %14
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = add i32 %54, 1
  store i32 %55, ptr %8, align 4, !tbaa !5
  br label %9, !llvm.loop !13

56:                                               ; preds = %13
  %57 = load float, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret float %57
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt3logf(float noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress 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 = { inlinehint mustprogress 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef float @_Z11compute_KLDjPKfS0_(i32 noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #1 {
  %.not = icmp eq i32 %0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext i32 %0 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %17, %3
  %.015.lcssa = phi float [ 0.000000e+00, %3 ], [ %.1, %17 ]
  ret float %.015.lcssa

.lr.ph:                                           ; preds = %.lr.ph.preheader, %17
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %17 ]
  %.01518 = phi float [ 0.000000e+00, %.lr.ph.preheader ], [ %.1, %17 ]
  %4 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  %5 = load float, ptr %4, align 4, !tbaa !5
  %6 = fcmp une float %5, 0.000000e+00
  br i1 %6, label %7, label %17

7:                                                ; preds = %.lr.ph
  %8 = getelementptr inbounds float, ptr %2, i64 %indvars.iv
  %9 = load float, ptr %8, align 4, !tbaa !5
  %10 = fcmp oeq float %9, 0.000000e+00
  br i1 %10, label %11, label %13

11:                                               ; preds = %7
  %12 = fadd float %.01518, 1.000000e+00
  br label %17

13:                                               ; preds = %7
  %14 = fdiv float %5, %9
  %15 = tail call noundef float @_ZSt3logf(float noundef %14)
  %16 = tail call float @llvm.fmuladd.f32(float %5, float %15, float %.01518)
  br label %17

17:                                               ; preds = %.lr.ph, %13, %11
  %.1 = phi float [ %12, %11 ], [ %16, %13 ], [ %.01518, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt3logf(float noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress 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 = { inlinehint mustprogress 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" }

!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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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