; LLVM IR from freddiev4/dailyprogrammerchallenges :: Easy Challenges/Challenge 0263 Easy - Calculating Shannon Entropy of a String (shannon)

; 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: nounwind uwtable
define dso_local float @shannon(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca [128 x float], align 16
  %4 = alloca float, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 512, ptr %3) #5
  call void @llvm.memset.p0.i64(ptr align 16 %3, i8 0, i64 512, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store float 0.000000e+00, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !11
  br label %7

7:                                                ; preds = %24, %1
  %8 = load i32, ptr %5, align 4, !tbaa !11
  %9 = sext i32 %8 to i64
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call i64 @strlen(ptr noundef %10) #6
  %12 = icmp ult i64 %9, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %27

14:                                               ; preds = %7
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = load i32, ptr %5, align 4, !tbaa !11
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i8, ptr %15, i64 %17
  %19 = load i8, ptr %18, align 1, !tbaa !13
  %20 = sext i8 %19 to i64
  %21 = getelementptr inbounds [128 x float], ptr %3, i64 0, i64 %20
  %22 = load float, ptr %21, align 4, !tbaa !9
  %23 = fadd float %22, 1.000000e+00
  store float %23, ptr %21, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %14
  %25 = load i32, ptr %5, align 4, !tbaa !11
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %5, align 4, !tbaa !11
  br label %7, !llvm.loop !14

27:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %28

28:                                               ; preds = %62, %27
  %29 = load i32, ptr %6, align 4, !tbaa !11
  %30 = icmp slt i32 %29, 128
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %65

32:                                               ; preds = %28
  %33 = load i32, ptr %6, align 4, !tbaa !11
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [128 x float], ptr %3, i64 0, i64 %34
  %36 = load float, ptr %35, align 4, !tbaa !9
  %37 = fcmp une float %36, 0.000000e+00
  br i1 %37, label %38, label %57

38:                                               ; preds = %32
  %39 = load i32, ptr %6, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [128 x float], ptr %3, i64 0, i64 %40
  %42 = load float, ptr %41, align 4, !tbaa !9
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = call i64 @strlen(ptr noundef %43) #6
  %45 = uitofp i64 %44 to float
  %46 = fdiv float %42, %45
  %47 = load i32, ptr %6, align 4, !tbaa !11
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [128 x float], ptr %3, i64 0, i64 %48
  %50 = load float, ptr %49, align 4, !tbaa !9
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = call i64 @strlen(ptr noundef %51) #6
  %53 = uitofp i64 %52 to float
  %54 = fdiv float %50, %53
  %55 = call float @log2f(float noundef %54) #5
  %56 = fmul float %46, %55
  br label %58

57:                                               ; preds = %32
  br label %58

58:                                               ; preds = %57, %38
  %59 = phi float [ %56, %38 ], [ 0.000000e+00, %57 ]
  %60 = load float, ptr %4, align 4, !tbaa !9
  %61 = fadd float %60, %59
  store float %61, ptr %4, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %58
  %63 = load i32, ptr %6, align 4, !tbaa !11
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %6, align 4, !tbaa !11
  br label %28, !llvm.loop !16

65:                                               ; preds = %31
  %66 = load float, ptr %4, align 4, !tbaa !9
  %67 = fmul float -1.000000e+00, %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 512, ptr %3) #5
  ret float %67
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

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

; Function Attrs: nounwind
declare float @log2f(float noundef) #4

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nounwind willreturn memory(read) "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 "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

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


; 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 nounwind memory(write, argmem: readwrite) uwtable
define dso_local float @shannon(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca [128 x float], align 16
  call void @llvm.lifetime.start.p0(i64 512, ptr nonnull %2) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(512) %2, i8 0, i64 512, i1 false)
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #6
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %.preheader.preheader, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %xtraiter = and i64 %3, 3
  %4 = icmp ult i64 %3, 4
  br i1 %4, label %.preheader.preheader.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %3, -4
  br label %.lr.ph

.preheader.preheader.loopexit.unr-lcssa:          ; preds = %.lr.ph, %.lr.ph.preheader
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.3, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader.preheader.loopexit.unr-lcssa, %.lr.ph.epil
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %.preheader.preheader.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %.preheader.preheader.loopexit.unr-lcssa ]
  %5 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.epil
  %6 = load i8, ptr %5, align 1, !tbaa !5
  %7 = sext i8 %6 to i64
  %8 = getelementptr inbounds [128 x float], ptr %2, i64 0, i64 %7
  %9 = load float, ptr %8, align 4, !tbaa !8
  %10 = fadd float %9, 1.000000e+00
  store float %10, ptr %8, align 4, !tbaa !8
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %.preheader.preheader, label %.lr.ph.epil, !llvm.loop !10

.preheader.preheader:                             ; preds = %.preheader.preheader.loopexit.unr-lcssa, %.lr.ph.epil, %1
  br label %.preheader

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %11 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %12 = load i8, ptr %11, align 1, !tbaa !5
  %13 = sext i8 %12 to i64
  %14 = getelementptr inbounds [128 x float], ptr %2, i64 0, i64 %13
  %15 = load float, ptr %14, align 4, !tbaa !8
  %16 = fadd float %15, 1.000000e+00
  store float %16, ptr %14, align 4, !tbaa !8
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %17 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %19 = sext i8 %18 to i64
  %20 = getelementptr inbounds [128 x float], ptr %2, i64 0, i64 %19
  %21 = load float, ptr %20, align 4, !tbaa !8
  %22 = fadd float %21, 1.000000e+00
  store float %22, ptr %20, align 4, !tbaa !8
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %23 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.1
  %24 = load i8, ptr %23, align 1, !tbaa !5
  %25 = sext i8 %24 to i64
  %26 = getelementptr inbounds [128 x float], ptr %2, i64 0, i64 %25
  %27 = load float, ptr %26, align 4, !tbaa !8
  %28 = fadd float %27, 1.000000e+00
  store float %28, ptr %26, align 4, !tbaa !8
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %29 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.2
  %30 = load i8, ptr %29, align 1, !tbaa !5
  %31 = sext i8 %30 to i64
  %32 = getelementptr inbounds [128 x float], ptr %2, i64 0, i64 %31
  %33 = load float, ptr %32, align 4, !tbaa !8
  %34 = fadd float %33, 1.000000e+00
  store float %34, ptr %32, align 4, !tbaa !8
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %.preheader.preheader.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !12

35:                                               ; preds = %46
  %36 = fneg float %48
  call void @llvm.lifetime.end.p0(i64 512, ptr nonnull %2) #5
  ret float %36

.preheader:                                       ; preds = %.preheader.preheader, %46
  %indvars.iv21 = phi i64 [ %indvars.iv.next22, %46 ], [ 0, %.preheader.preheader ]
  %.01418 = phi float [ %48, %46 ], [ 0.000000e+00, %.preheader.preheader ]
  %37 = getelementptr inbounds [128 x float], ptr %2, i64 0, i64 %indvars.iv21
  %38 = load float, ptr %37, align 4, !tbaa !8
  %39 = fcmp une float %38, 0.000000e+00
  br i1 %39, label %40, label %46

40:                                               ; preds = %.preheader
  %41 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #6
  %42 = uitofp i64 %41 to float
  %43 = fdiv float %38, %42
  %44 = tail call float @log2f(float noundef %43) #5
  %45 = fmul float %44, %43
  br label %46

46:                                               ; preds = %.preheader, %40
  %47 = phi float [ %45, %40 ], [ 0.000000e+00, %.preheader ]
  %48 = fadd float %.01418, %47
  %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 1
  %exitcond24.not = icmp eq i64 %indvars.iv.next22, 128
  br i1 %exitcond24.not, label %35, label %.preheader, !llvm.loop !14
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @log2f(float noundef) local_unnamed_addr #4

attributes #0 = { nofree nounwind memory(write, argmem: readwrite) 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { mustprogress nofree nounwind willreturn memory(write) "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"float", !6, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.unroll.disable"}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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