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

; 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 uwtable
define dso_local void @_ZN20BalancedPartitioningC2ERSt6vectorIP8DocumentSaIS2_EE(ptr noundef nonnull align 8 dereferenceable(131088) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %class.BalancedPartitioning, ptr %6, i32 0, i32 0
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %8, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds %class.BalancedPartitioning, ptr %6, i32 0, i32 2
  store i32 18, ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds %class.BalancedPartitioning, ptr %6, i32 0, i32 3
  store i32 40, ptr %10, align 4, !tbaa !12
  %11 = getelementptr inbounds %class.BalancedPartitioning, ptr %6, i32 0, i32 1
  %12 = getelementptr inbounds [16384 x double], ptr %11, i64 0, i64 0
  store double 0.000000e+00, ptr %12, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !15
  br label %13

13:                                               ; preds = %24, %2
  %14 = load i32, ptr %5, align 4, !tbaa !15
  %15 = icmp ult i32 %14, 16384
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %13
  %18 = load i32, ptr %5, align 4, !tbaa !15
  %19 = call noundef double @_ZSt4log2IjEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %18)
  %20 = getelementptr inbounds %class.BalancedPartitioning, ptr %6, i32 0, i32 1
  %21 = load i32, ptr %5, align 4, !tbaa !15
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds [16384 x double], ptr %20, i64 0, i64 %22
  store double %19, ptr %23, align 8, !tbaa !13
  br label %24

24:                                               ; preds = %17
  %25 = load i32, ptr %5, align 4, !tbaa !15
  %26 = add i32 %25, 1
  store i32 %26, ptr %5, align 4, !tbaa !15
  br label %13, !llvm.loop !16

27:                                               ; preds = %16
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4log2IjEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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++ TBAA"}
!9 = !{!10, !11, i64 131080}
!10 = !{!"_ZTS20BalancedPartitioning", !6, i64 0, !7, i64 8, !11, i64 131080, !11, i64 131084}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 131084}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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 nounwind uwtable
define dso_local void @_ZN20BalancedPartitioningC2ERSt6vectorIP8DocumentSaIS2_EE(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(131088) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) unnamed_addr #0 align 2 {
  store ptr %1, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 131080
  store i32 18, ptr %3, align 8, !tbaa !9
  %4 = getelementptr inbounds i8, ptr %0, i64 131084
  store i32 40, ptr %4, align 4, !tbaa !12
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  store double 0.000000e+00, ptr %5, align 8, !tbaa !13
  br label %7

6:                                                ; preds = %7
  ret void

7:                                                ; preds = %2, %7
  %indvars.iv = phi i64 [ 1, %2 ], [ %indvars.iv.next, %7 ]
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  %9 = tail call noundef double @_ZSt4log2IjEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %8)
  %10 = getelementptr inbounds [16384 x double], ptr %5, i64 0, i64 %indvars.iv
  store double %9, ptr %10, align 8, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 16384
  br i1 %exitcond.not, label %6, label %7, !llvm.loop !15
}

; 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

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

!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, !11, i64 131080}
!10 = !{!"_ZTS20BalancedPartitioning", !6, i64 0, !7, i64 8, !11, i64 131080, !11, i64 131084}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 131084}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass