; LLVM IR from PetarV-/Algorithms :: Recursion, Backtracking etc./K-Combinations.ll (Z13kCombinationsii)

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

@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@skup = external dso_local global [100 x i32], align 16
@inSet = external dso_local global [100 x i8], align 16
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z13kCombinationsii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = sub nsw i32 %6, %7
  %9 = load i32, ptr @k, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = sub nsw i32 %9, %10
  %12 = icmp slt i32 %8, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  br label %56

14:                                               ; preds = %2
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load i32, ptr @k, align 4, !tbaa !5
  %17 = icmp eq i32 %15, %16
  br i1 %17, label %18, label %42

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %37, %18
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %19
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [100 x i8], ptr @inSet, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !9, !range !11, !noundef !12
  %29 = trunc i8 %28 to i1
  br i1 %29, label %30, label %36

30:                                               ; preds = %24
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [100 x i32], ptr @skup, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %34)
  br label %36

36:                                               ; preds = %30, %24
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %5, align 4, !tbaa !5
  br label %19, !llvm.loop !13

40:                                               ; preds = %23
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  br label %56

42:                                               ; preds = %14
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [100 x i8], ptr @inSet, i64 0, i64 %44
  store i8 1, ptr %45, align 1, !tbaa !9
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  call void @_Z13kCombinationsii(i32 noundef %47, i32 noundef %49)
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [100 x i8], ptr @inSet, i64 0, i64 %51
  store i8 0, ptr %52, align 1, !tbaa !9
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  %55 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z13kCombinationsii(i32 noundef %54, i32 noundef %55)
  br label %56

56:                                               ; preds = %42, %40, %13
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@n = external dso_local local_unnamed_addr global i32, align 4
@k = external dso_local local_unnamed_addr global i32, align 4
@skup = external dso_local local_unnamed_addr global [100 x i32], align 16
@inSet = external dso_local local_unnamed_addr global [100 x i8], align 16
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z13kCombinationsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = sub nsw i32 %3, %0
  %5 = load i32, ptr @k, align 4, !tbaa !5
  %6 = sub nsw i32 %5, %1
  %7 = icmp slt i32 %4, %6
  br i1 %7, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %8 = add nsw i32 %1, 1
  %9 = icmp eq i32 %5, %1
  br i1 %9, label %.preheader, label %tailrecurse.lr.ph

tailrecurse.lr.ph:                                ; preds = %.lr.ph
  %10 = sext i32 %0 to i64
  br label %tailrecurse

11:                                               ; preds = %tailrecurse
  %12 = icmp eq i32 %30, %1
  br i1 %12, label %.preheader, label %tailrecurse

.preheader:                                       ; preds = %11, %.lr.ph
  %.lcssa = phi i32 [ %3, %.lr.ph ], [ %28, %11 ]
  %13 = icmp sgt i32 %.lcssa, 0
  br i1 %13, label %.lr.ph17, label %._crit_edge

._crit_edge:                                      ; preds = %23, %.preheader
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.loopexit

.lr.ph17:                                         ; preds = %.preheader, %23
  %15 = phi i32 [ %24, %23 ], [ %.lcssa, %.preheader ]
  %indvars.iv19 = phi i64 [ %indvars.iv.next20, %23 ], [ 0, %.preheader ]
  %16 = getelementptr inbounds [100 x i8], ptr @inSet, i64 0, i64 %indvars.iv19
  %17 = load i8, ptr %16, align 1, !tbaa !9, !range !11, !noundef !12
  %18 = trunc nuw i8 %17 to i1
  br i1 %18, label %19, label %23

19:                                               ; preds = %.lr.ph17
  %20 = getelementptr inbounds [100 x i32], ptr @skup, i64 0, i64 %indvars.iv19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %21)
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %.lr.ph17, %19
  %24 = phi i32 [ %15, %.lr.ph17 ], [ %.pre, %19 ]
  %indvars.iv.next20 = add nuw nsw i64 %indvars.iv19, 1
  %25 = sext i32 %24 to i64
  %26 = icmp slt i64 %indvars.iv.next20, %25
  br i1 %26, label %.lr.ph17, label %._crit_edge, !llvm.loop !13

tailrecurse:                                      ; preds = %tailrecurse.lr.ph, %11
  %indvars.iv25 = phi i64 [ %10, %tailrecurse.lr.ph ], [ %indvars.iv.next, %11 ]
  %27 = getelementptr inbounds [100 x i8], ptr @inSet, i64 0, i64 %indvars.iv25
  store i8 1, ptr %27, align 1, !tbaa !9
  %indvars.iv.next = add nsw i64 %indvars.iv25, 1
  %indvars = trunc i64 %indvars.iv.next to i32
  tail call void @_Z13kCombinationsii(i32 noundef %indvars, i32 noundef %8)
  store i8 0, ptr %27, align 1, !tbaa !9
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = sub nsw i32 %28, %indvars
  %30 = load i32, ptr @k, align 4, !tbaa !5
  %31 = sub nsw i32 %30, %1
  %32 = icmp slt i32 %29, %31
  br i1 %32, label %.loopexit, label %11

.loopexit:                                        ; preds = %tailrecurse, %2, %._crit_edge
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { mustprogress nofree 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 = { nofree nounwind "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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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