; LLVM IR from facebook/redex :: libredex/BalancedPartitioning.ll (ZNK20BalancedPartitioning8log_costEjj)

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

%class.BalancedPartitioning = type { ptr, [16384 x double], i32, i32 }

; 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: mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4log2IjEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK20BalancedPartitioning8log_costEjj(ptr noundef nonnull align 8 dereferenceable(131088) %0, i32 noundef %1, i32 noundef %2) #2 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = add i32 %10, 1
  %12 = icmp ult i32 %11, 16384
  br i1 %12, label %13, label %20

13:                                               ; preds = %3
  %14 = getelementptr inbounds %class.BalancedPartitioning, ptr %9, i32 0, i32 1
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = add i32 %15, 1
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds [16384 x double], ptr %14, i64 0, i64 %17
  %19 = load double, ptr %18, align 8, !tbaa !11
  br label %24

20:                                               ; preds = %3
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = add i32 %21, 1
  %23 = call noundef double @_ZSt4log2IjEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %22)
  br label %24

24:                                               ; preds = %20, %13
  %25 = phi double [ %19, %13 ], [ %23, %20 ]
  store double %25, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = add i32 %26, 1
  %28 = icmp ult i32 %27, 16384
  br i1 %28, label %29, label %36

29:                                               ; preds = %24
  %30 = getelementptr inbounds %class.BalancedPartitioning, ptr %9, i32 0, i32 1
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = add i32 %31, 1
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [16384 x double], ptr %30, i64 0, i64 %33
  %35 = load double, ptr %34, align 8, !tbaa !11
  br label %40

36:                                               ; preds = %24
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = add i32 %37, 1
  %39 = call noundef double @_ZSt4log2IjEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %38)
  br label %40

40:                                               ; preds = %36, %29
  %41 = phi double [ %35, %29 ], [ %39, %36 ]
  store double %41, ptr %8, align 8, !tbaa !11
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = uitofp i32 %42 to double
  %44 = load double, ptr %7, align 8, !tbaa !11
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = uitofp i32 %45 to double
  %47 = load double, ptr %8, align 8, !tbaa !11
  %48 = fmul double %46, %47
  %49 = call double @llvm.fmuladd.f64(double %43, double %44, double %48)
  %50 = fneg double %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret double %50
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}


; 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 nounwind uwtable
declare dso_local noundef double @_ZSt4log2IjEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_ZNK20BalancedPartitioning8log_costEjj(ptr nocapture noundef nonnull readonly align 8 dereferenceable(131088) %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 align 2 {
  %4 = add i32 %1, 1
  %5 = icmp ult i32 %4, 16384
  br i1 %5, label %6, label %11

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = zext nneg i32 %4 to i64
  %9 = getelementptr inbounds [16384 x double], ptr %7, i64 0, i64 %8
  %10 = load double, ptr %9, align 8, !tbaa !5
  br label %13

11:                                               ; preds = %3
  %12 = tail call noundef double @_ZSt4log2IjEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %4)
  br label %13

13:                                               ; preds = %11, %6
  %14 = phi double [ %10, %6 ], [ %12, %11 ]
  %15 = add i32 %2, 1
  %16 = icmp ult i32 %15, 16384
  br i1 %16, label %17, label %22

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  %19 = zext nneg i32 %15 to i64
  %20 = getelementptr inbounds [16384 x double], ptr %18, i64 0, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !5
  br label %24

22:                                               ; preds = %13
  %23 = tail call noundef double @_ZSt4log2IjEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %15)
  br label %24

24:                                               ; preds = %22, %17
  %25 = phi double [ %21, %17 ], [ %23, %22 ]
  %26 = uitofp i32 %1 to double
  %27 = uitofp i32 %2 to double
  %28 = fmul double %25, %27
  %29 = tail call double @llvm.fmuladd.f64(double %26, double %14, double %28)
  %30 = fneg double %29
  ret double %30
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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