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

; 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.KmerSignature = type <{ i32, i32, double, double, i8, [7 x i8] }>

@.str.4 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__._ZNK20BalancedPartitioning17prepare_signatureER13KmerSignature = external hidden unnamed_addr constant [68 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [35 x i8], align 1

; 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: noreturn
declare void @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK20BalancedPartitioning17prepare_signatureER13KmerSignature(ptr noundef nonnull align 8 dereferenceable(131088) %0, ptr noundef nonnull align 8 dereferenceable(25) %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %class.KmerSignature, ptr %9, i32 0, i32 0
  %11 = load i32, ptr %10, align 8, !tbaa !9
  store i32 %11, ptr %5, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %class.KmerSignature, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !15
  store i32 %14, ptr %6, align 4, !tbaa !14
  %15 = load i32, ptr %5, align 4, !tbaa !14
  %16 = icmp ugt i32 %15, 0
  br i1 %16, label %20, label %17

17:                                               ; preds = %2
  %18 = load i32, ptr %6, align 4, !tbaa !14
  %19 = icmp ugt i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17, %2
  br label %25

21:                                               ; preds = %17
  %22 = load i32, ptr %5, align 4, !tbaa !14
  %23 = load i32, ptr %6, align 4, !tbaa !14
  call void (ptr, ptr, i32, ptr, i32, ptr, ...) @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef @.str.10, ptr noundef @.str.4, i32 noundef 345, ptr noundef @__PRETTY_FUNCTION__._ZNK20BalancedPartitioning17prepare_signatureER13KmerSignature, i32 noundef 2, ptr noundef @.str.11, i32 noundef %22, i32 noundef %23) #4
  unreachable

24:                                               ; No predecessors!
  br label %25

25:                                               ; preds = %24, %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %26 = load i32, ptr %5, align 4, !tbaa !14
  %27 = load i32, ptr %6, align 4, !tbaa !14
  %28 = call noundef double @_ZNK20BalancedPartitioning8log_costEjj(ptr noundef nonnull align 8 dereferenceable(131088) %8, i32 noundef %26, i32 noundef %27)
  store double %28, ptr %7, align 8, !tbaa !16
  %29 = load i32, ptr %5, align 4, !tbaa !14
  %30 = icmp ugt i32 %29, 0
  br i1 %30, label %31, label %41

31:                                               ; preds = %25
  %32 = load double, ptr %7, align 8, !tbaa !16
  %33 = load i32, ptr %5, align 4, !tbaa !14
  %34 = sub i32 %33, 1
  %35 = load i32, ptr %6, align 4, !tbaa !14
  %36 = add i32 %35, 1
  %37 = call noundef double @_ZNK20BalancedPartitioning8log_costEjj(ptr noundef nonnull align 8 dereferenceable(131088) %8, i32 noundef %34, i32 noundef %36)
  %38 = fsub double %32, %37
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %class.KmerSignature, ptr %39, i32 0, i32 2
  store double %38, ptr %40, align 8, !tbaa !17
  br label %41

41:                                               ; preds = %31, %25
  %42 = load i32, ptr %6, align 4, !tbaa !14
  %43 = icmp ugt i32 %42, 0
  br i1 %43, label %44, label %54

44:                                               ; preds = %41
  %45 = load double, ptr %7, align 8, !tbaa !16
  %46 = load i32, ptr %5, align 4, !tbaa !14
  %47 = add i32 %46, 1
  %48 = load i32, ptr %6, align 4, !tbaa !14
  %49 = sub i32 %48, 1
  %50 = call noundef double @_ZNK20BalancedPartitioning8log_costEjj(ptr noundef nonnull align 8 dereferenceable(131088) %8, i32 noundef %47, i32 noundef %49)
  %51 = fsub double %45, %50
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %class.KmerSignature, ptr %52, i32 0, i32 3
  store double %51, ptr %53, align 8, !tbaa !18
  br label %54

54:                                               ; preds = %44, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZNK20BalancedPartitioning8log_costEjj(ptr noundef nonnull align 8 dereferenceable(131088), i32 noundef, i32 noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn "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 = { nounwind }
attributes #4 = { noreturn }

!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 0}
!10 = !{!"_ZTS13KmerSignature", !11, i64 0, !11, i64 4, !12, i64 8, !12, i64 16, !13, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !11, i64 4}
!16 = !{!12, !12, i64 0}
!17 = !{!10, !12, i64 8}
!18 = !{!10, !12, i64 16}


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

@.str.4 = external hidden unnamed_addr constant [82 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [15 x i8], align 1
@__PRETTY_FUNCTION__._ZNK20BalancedPartitioning17prepare_signatureER13KmerSignature = external hidden unnamed_addr constant [68 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: noreturn
declare void @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK20BalancedPartitioning17prepare_signatureER13KmerSignature(ptr noundef nonnull align 8 dereferenceable(131088) %0, ptr nocapture noundef nonnull align 8 dereferenceable(25) %1) local_unnamed_addr #1 align 2 {
  %3 = load i32, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !12
  %6 = icmp ne i32 %3, 0
  %7 = icmp ne i32 %5, 0
  %or.cond = select i1 %6, i1 true, i1 %7
  br i1 %or.cond, label %9, label %8

8:                                                ; preds = %2
  tail call void (ptr, ptr, i32, ptr, i32, ptr, ...) @_Z11assert_failPKcS0_jS0_10RedexErrorS0_z(ptr noundef nonnull @.str.10, ptr noundef nonnull @.str.4, i32 noundef 345, ptr noundef nonnull @__PRETTY_FUNCTION__._ZNK20BalancedPartitioning17prepare_signatureER13KmerSignature, i32 noundef 2, ptr noundef nonnull @.str.11, i32 noundef 0, i32 noundef 0) #2
  unreachable

9:                                                ; preds = %2
  %10 = tail call noundef double @_ZNK20BalancedPartitioning8log_costEjj(ptr noundef nonnull align 8 dereferenceable(131088) %0, i32 noundef %3, i32 noundef %5)
  br i1 %6, label %11, label %17

11:                                               ; preds = %9
  %12 = add i32 %3, -1
  %13 = add i32 %5, 1
  %14 = tail call noundef double @_ZNK20BalancedPartitioning8log_costEjj(ptr noundef nonnull align 8 dereferenceable(131088) %0, i32 noundef %12, i32 noundef %13)
  %15 = fsub double %10, %14
  %16 = getelementptr inbounds i8, ptr %1, i64 8
  store double %15, ptr %16, align 8, !tbaa !13
  br label %17

17:                                               ; preds = %11, %9
  br i1 %7, label %18, label %24

18:                                               ; preds = %17
  %19 = add i32 %3, 1
  %20 = add i32 %5, -1
  %21 = tail call noundef double @_ZNK20BalancedPartitioning8log_costEjj(ptr noundef nonnull align 8 dereferenceable(131088) %0, i32 noundef %19, i32 noundef %20)
  %22 = fsub double %10, %21
  %23 = getelementptr inbounds i8, ptr %1, i64 16
  store double %22, ptr %23, align 8, !tbaa !14
  br label %24

24:                                               ; preds = %18, %17
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef double @_ZNK20BalancedPartitioning8log_costEjj(ptr noundef nonnull align 8 dereferenceable(131088), i32 noundef, i32 noundef) local_unnamed_addr #1 align 2

attributes #0 = { noreturn "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 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 = { noreturn }

!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, !7, i64 0}
!6 = !{!"_ZTS13KmerSignature", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !11, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !10, i64 16}


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