; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 03. Recursion/count_possible_paths_in_a_maze.ll (Z13countPathMazeiii)

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

12:                                               ; preds = %3
  %13 = load i32, ptr %7, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = sub nsw i32 %14, 1
  %16 = icmp eq i32 %13, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %12
  store i32 1, ptr %4, align 4
  br label %39

18:                                               ; preds = %12, %3
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = icmp sge i32 %19, %20
  br i1 %21, label %26, label %22

22:                                               ; preds = %18
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = icmp sge i32 %23, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %22, %18
  store i32 0, ptr %4, align 4
  br label %39

27:                                               ; preds = %22
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = call noundef i32 @_Z13countPathMazeiii(i32 noundef %28, i32 noundef %30, i32 noundef %31)
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  %37 = call noundef i32 @_Z13countPathMazeiii(i32 noundef %33, i32 noundef %34, i32 noundef %36)
  %38 = add nsw i32 %32, %37
  store i32 %38, ptr %4, align 4
  br label %39

39:                                               ; preds = %27, %26, %17
  %40 = load i32, ptr %4, align 4
  ret i32 %40
}

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


; 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(none) uwtable
define dso_local noundef i32 @_Z13countPathMazeiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = add i32 %0, -1
  %5 = icmp eq i32 %4, %1
  %6 = icmp eq i32 %4, %2
  %or.cond23 = and i1 %5, %6
  br i1 %or.cond23, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %.not = icmp slt i32 %1, %0
  %7 = add nsw i32 %1, 1
  br i1 %.not, label %.lr.ph.split, label %._crit_edge

.lr.ph.split:                                     ; preds = %.lr.ph
  br i1 %5, label %.lr.ph.split.split.preheader, label %.lr.ph.split.split.us

.lr.ph.split.split.preheader:                     ; preds = %.lr.ph.split
  %smax = tail call i32 @llvm.smax.i32(i32 %2, i32 %0)
  br label %.lr.ph.split.split

.lr.ph.split.split.us:                            ; preds = %.lr.ph.split
  %.not19.us35 = icmp slt i32 %2, %0
  br i1 %.not19.us35, label %tailrecurse.us, label %._crit_edge

tailrecurse.us:                                   ; preds = %.lr.ph.split.split.us, %tailrecurse.us
  %accumulator.tr24.us3037 = phi i32 [ %10, %tailrecurse.us ], [ 0, %.lr.ph.split.split.us ]
  %.tr2225.us36 = phi i32 [ %9, %tailrecurse.us ], [ %2, %.lr.ph.split.split.us ]
  %8 = tail call noundef i32 @_Z13countPathMazeiii(i32 noundef %0, i32 noundef %7, i32 noundef %.tr2225.us36)
  %9 = add nsw i32 %.tr2225.us36, 1
  %10 = add nsw i32 %8, %accumulator.tr24.us3037
  %exitcond.not = icmp eq i32 %9, %0
  br i1 %exitcond.not, label %._crit_edge, label %tailrecurse.us

.lr.ph.split.split:                               ; preds = %.lr.ph.split.split.preheader, %tailrecurse
  %.tr2225 = phi i32 [ %12, %tailrecurse ], [ %2, %.lr.ph.split.split.preheader ]
  %accumulator.tr24 = phi i32 [ %13, %tailrecurse ], [ 0, %.lr.ph.split.split.preheader ]
  %exitcond42.not = icmp eq i32 %.tr2225, %smax
  br i1 %exitcond42.not, label %._crit_edge, label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph.split.split
  %11 = tail call noundef i32 @_Z13countPathMazeiii(i32 noundef %0, i32 noundef %7, i32 noundef %.tr2225)
  %12 = add i32 %.tr2225, 1
  %13 = add nsw i32 %11, %accumulator.tr24
  %14 = icmp eq i32 %12, %1
  br i1 %14, label %._crit_edge, label %.lr.ph.split.split

._crit_edge:                                      ; preds = %tailrecurse.us, %tailrecurse, %.lr.ph.split.split, %.lr.ph, %.lr.ph.split.split.us, %3
  %accumulator.tr.lcssa = phi i32 [ 0, %3 ], [ 0, %.lr.ph ], [ 0, %.lr.ph.split.split.us ], [ %accumulator.tr24, %.lr.ph.split.split ], [ %13, %tailrecurse ], [ %10, %tailrecurse.us ]
  %.0 = phi i32 [ 1, %3 ], [ 0, %.lr.ph ], [ 0, %.lr.ph.split.split.us ], [ 0, %.lr.ph.split.split ], [ 1, %tailrecurse ], [ 0, %tailrecurse.us ]
  %accumulator.ret.tr = add nsw i32 %.0, %accumulator.tr.lcssa
  ret i32 %accumulator.ret.tr
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

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

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


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