; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/LONG/DEC14/SANSKAR/sans.ll (Z11isSubsetSumPxxx)

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

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

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

14:                                               ; preds = %11
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = sub nsw i64 %16, 1
  %18 = getelementptr inbounds i64, ptr %15, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !9
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %21, label %25

21:                                               ; preds = %14, %11
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  store i1 false, ptr %4, align 1
  br label %62

25:                                               ; preds = %21, %14
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = sub nsw i64 %27, 1
  %29 = getelementptr inbounds i64, ptr %26, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = icmp sgt i64 %30, %31
  br i1 %32, label %33, label %39

33:                                               ; preds = %25
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i64, ptr %6, align 8, !tbaa !9
  %36 = sub nsw i64 %35, 1
  %37 = load i64, ptr %7, align 8, !tbaa !9
  %38 = call noundef zeroext i1 @_Z11isSubsetSumPxxx(ptr noundef %34, i64 noundef %36, i64 noundef %37)
  store i1 %38, ptr %4, align 1
  br label %62

39:                                               ; preds = %25
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = sub nsw i64 %41, 1
  %43 = load i64, ptr %7, align 8, !tbaa !9
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load i64, ptr %6, align 8, !tbaa !9
  %46 = sub nsw i64 %45, 1
  %47 = getelementptr inbounds i64, ptr %44, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !9
  %49 = sub nsw i64 %43, %48
  %50 = call noundef zeroext i1 @_Z11isSubsetSumPxxx(ptr noundef %40, i64 noundef %42, i64 noundef %49)
  br i1 %50, label %51, label %56

51:                                               ; preds = %39
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i64, ptr %6, align 8, !tbaa !9
  %54 = sub nsw i64 %53, 1
  %55 = getelementptr inbounds i64, ptr %52, i64 %54
  store i64 0, ptr %55, align 8, !tbaa !9
  store i1 true, ptr %4, align 1
  br label %62

56:                                               ; preds = %39
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load i64, ptr %6, align 8, !tbaa !9
  %59 = sub nsw i64 %58, 1
  %60 = load i64, ptr %7, align 8, !tbaa !9
  %61 = call noundef zeroext i1 @_Z11isSubsetSumPxxx(ptr noundef %57, i64 noundef %59, i64 noundef %60)
  store i1 %61, ptr %4, align 1
  br label %62

62:                                               ; preds = %56, %51, %33, %24, %10
  %63 = load i1, ptr %4, align 1
  ret i1 %63
}

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 = !{!"long long", !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 memory(argmem: readwrite) uwtable
define dso_local noundef zeroext i1 @_Z11isSubsetSumPxxx(ptr nocapture noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i64 %2, 0
  %invariant.gep = getelementptr i8, ptr %0, i64 -8
  br i1 %4, label %.loopexit, label %.lr.ph.split

.lr.ph.split:                                     ; preds = %3
  %5 = icmp eq i64 %1, 0
  br i1 %5, label %.loopexit, label %.lr.ph37

.lr.ph37:                                         ; preds = %.lr.ph.split, %tailrecurse.backedge
  %.tr262936 = phi i64 [ %9, %tailrecurse.backedge ], [ %1, %.lr.ph.split ]
  %gep = getelementptr i64, ptr %invariant.gep, i64 %.tr262936
  %6 = load i64, ptr %gep, align 8, !tbaa !5
  %7 = icmp eq i64 %6, 0
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %.lr.ph37
  %9 = add nsw i64 %.tr262936, -1
  %10 = icmp sgt i64 %6, %2
  br i1 %10, label %tailrecurse.backedge, label %12

tailrecurse.backedge:                             ; preds = %8, %12
  %11 = icmp eq i64 %9, 0
  br i1 %11, label %.loopexit, label %.lr.ph37

12:                                               ; preds = %8
  %13 = sub nsw i64 %2, %6
  %14 = tail call noundef zeroext i1 @_Z11isSubsetSumPxxx(ptr noundef nonnull %0, i64 noundef %9, i64 noundef %13)
  br i1 %14, label %.split, label %tailrecurse.backedge

.split:                                           ; preds = %12
  %15 = getelementptr inbounds i64, ptr %0, i64 %9
  store i64 0, ptr %15, align 8, !tbaa !5
  br label %.loopexit

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

attributes #0 = { mustprogress nofree nosync nounwind memory(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" }

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


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