; LLVM IR from Ayon-SSP/The-SDE-Prep :: 3]_CP/DP/Subset Sum Problem/Subset Sum Problem (recursive).ll (Z9subsetSumPiii)

; 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: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z9subsetSumPiii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %3
  store i1 true, ptr %4, align 1
  br label %54

11:                                               ; preds = %3
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %18

14:                                               ; preds = %11
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  store i1 false, ptr %4, align 1
  br label %54

18:                                               ; preds = %14, %11
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = sub nsw i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %19, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = load i32, ptr %7, align 4, !tbaa !9
  %26 = icmp sgt i32 %24, %25
  br i1 %26, label %27, label %33

27:                                               ; preds = %18
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = sub nsw i32 %29, 1
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = call noundef zeroext i1 @_Z9subsetSumPiii(ptr noundef %28, i32 noundef %30, i32 noundef %31)
  store i1 %32, ptr %4, align 1
  br label %54

33:                                               ; preds = %18
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = sub nsw i32 %35, 1
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %38, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = sub nsw i32 %37, %43
  %45 = call noundef zeroext i1 @_Z9subsetSumPiii(ptr noundef %34, i32 noundef %36, i32 noundef %44)
  br i1 %45, label %52, label %46

46:                                               ; preds = %33
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = sub nsw i32 %48, 1
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = call noundef zeroext i1 @_Z9subsetSumPiii(ptr noundef %47, i32 noundef %49, i32 noundef %50)
  br label %52

52:                                               ; preds = %46, %33
  %53 = phi i1 [ true, %33 ], [ %51, %46 ]
  store i1 %53, ptr %4, align 1
  br label %54

54:                                               ; preds = %52, %27, %17, %10
  %55 = load i1, ptr %4, align 1
  ret i1 %55
}

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

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


; 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 nofree nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local noundef zeroext i1 @_Z9subsetSumPiii(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %2, 0
  br i1 %4, label %._crit_edge, label %.lr.ph.split

.lr.ph.split:                                     ; preds = %3
  %5 = icmp eq i32 %1, 0
  br i1 %5, label %._crit_edge, label %.lr.ph30.preheader

.lr.ph30.preheader:                               ; preds = %.lr.ph.split
  %6 = sext i32 %1 to i64
  br label %.lr.ph30

.lr.ph30:                                         ; preds = %.lr.ph30.preheader, %tailrecurse.backedge
  %indvars.iv = phi i64 [ %6, %.lr.ph30.preheader ], [ %indvars.iv.next, %tailrecurse.backedge ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %7 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, %2
  br i1 %9, label %.lr.ph30.tailrecurse.backedge_crit_edge, label %11

.lr.ph30.tailrecurse.backedge_crit_edge:          ; preds = %.lr.ph30
  %.pre = trunc nsw i64 %indvars.iv.next to i32
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %.lr.ph30.tailrecurse.backedge_crit_edge, %11
  %.pre-phi = phi i32 [ %.pre, %.lr.ph30.tailrecurse.backedge_crit_edge ], [ %13, %11 ]
  %10 = icmp eq i32 %.pre-phi, 0
  br i1 %10, label %._crit_edge, label %.lr.ph30

11:                                               ; preds = %.lr.ph30
  %12 = sub nsw i32 %2, %8
  %13 = trunc nsw i64 %indvars.iv.next to i32
  %14 = tail call noundef zeroext i1 @_Z9subsetSumPiii(ptr noundef nonnull %0, i32 noundef %13, i32 noundef %12)
  br i1 %14, label %._crit_edge, label %tailrecurse.backedge

._crit_edge:                                      ; preds = %tailrecurse.backedge, %11, %.lr.ph.split, %3
  %.0 = phi i1 [ true, %3 ], [ false, %.lr.ph.split ], [ true, %11 ], [ false, %tailrecurse.backedge ]
  ret i1 %.0
}

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(argmem: read) 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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