; LLVM IR from wuzhouhui/leetcode :: 70_climbing_stair (climbStairs)

; 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: nounwind uwtable
define dso_local i32 @climbStairs(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %15

9:                                                ; preds = %1
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %15, label %12

12:                                               ; preds = %9
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 2
  br i1 %14, label %15, label %17

15:                                               ; preds = %12, %9, %1
  %16 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %16, ptr %2, align 4
  br label %62

17:                                               ; preds = %12
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = zext i32 %19 to i64
  %21 = call ptr @llvm.stacksave.p0()
  store ptr %21, ptr %4, align 8
  %22 = alloca i32, i64 %20, align 16
  store i64 %20, ptr %5, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %53, %17
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = icmp sle i32 %24, %25
  br i1 %26, label %27, label %56

27:                                               ; preds = %23
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = icmp eq i32 %28, 1
  br i1 %29, label %33, label %30

30:                                               ; preds = %27
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = icmp eq i32 %31, 2
  br i1 %32, label %33, label %38

33:                                               ; preds = %30, %27
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds i32, ptr %22, i64 %36
  store i32 %34, ptr %37, align 4, !tbaa !5
  br label %53

38:                                               ; preds = %30
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %22, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = sub nsw i32 %44, 2
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr %22, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = add nsw i32 %43, %48
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr %22, i64 %51
  store i32 %49, ptr %52, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %38, %33
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %6, align 4, !tbaa !5
  br label %23, !llvm.loop !9

56:                                               ; preds = %23
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i32, ptr %22, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  store i32 %60, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %61 = load ptr, ptr %4, align 8
  call void @llvm.stackrestore.p0(ptr %61)
  br label %62

62:                                               ; preds = %56, %15
  %63 = load i32, ptr %2, align 4
  ret i32 %63
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

; Function Attrs: nofree norecurse nosync nounwind uwtable
define dso_local i32 @climbStairs(i32 noundef %0) local_unnamed_addr #0 {
  %or.cond3 = icmp ult i32 %0, 3
  br i1 %or.cond3, label %36, label %2

2:                                                ; preds = %1
  %3 = add i32 %0, 1
  %4 = zext i32 %3 to i64
  %5 = tail call ptr @llvm.stacksave.p0()
  %6 = alloca i32, i64 %4, align 16
  %.not24 = icmp slt i32 %0, 1
  br i1 %.not24, label %._crit_edge, label %.lr.ph.peel.next27

.lr.ph.peel.next27:                               ; preds = %2
  %7 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 1, ptr %7, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 2, ptr %8, align 8, !tbaa !5
  %9 = add nsw i64 %4, -3
  %10 = add nsw i64 %4, -4
  %xtraiter = and i64 %9, 3
  %11 = icmp ult i64 %10, 3
  br i1 %11, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.peel.next27.new

.lr.ph.peel.next27.new:                           ; preds = %.lr.ph.peel.next27
  %unroll_iter = and i64 %9, -4
  br label %12

12:                                               ; preds = %12, %.lr.ph.peel.next27.new
  %store_forwarded = phi i32 [ 2, %.lr.ph.peel.next27.new ], [ %30, %12 ]
  %indvars.iv = phi i64 [ 3, %.lr.ph.peel.next27.new ], [ %indvars.iv.next.3, %12 ]
  %niter = phi i64 [ 0, %.lr.ph.peel.next27.new ], [ %niter.next.3, %12 ]
  %13 = getelementptr i32, ptr %6, i64 %indvars.iv
  %14 = getelementptr i8, ptr %13, i64 -8
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i32 %15, %store_forwarded
  store i32 %16, ptr %13, align 4, !tbaa !5
  %17 = getelementptr i32, ptr %6, i64 %indvars.iv
  %18 = getelementptr i8, ptr %17, i64 4
  %19 = getelementptr i8, ptr %17, i64 -4
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = add nsw i32 %20, %16
  store i32 %21, ptr %18, align 4, !tbaa !5
  %22 = getelementptr i32, ptr %6, i64 %indvars.iv
  %23 = getelementptr i8, ptr %22, i64 8
  %24 = load i32, ptr %22, align 4, !tbaa !5
  %25 = add nsw i32 %24, %21
  store i32 %25, ptr %23, align 4, !tbaa !5
  %26 = getelementptr i32, ptr %6, i64 %indvars.iv
  %27 = getelementptr i8, ptr %26, i64 12
  %28 = getelementptr i8, ptr %26, i64 4
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add nsw i32 %29, %25
  store i32 %30, ptr %27, align 4, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %12, !llvm.loop !9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %12, %.lr.ph.peel.next27
  %store_forwarded.unr = phi i32 [ 2, %.lr.ph.peel.next27 ], [ %30, %12 ]
  %indvars.iv.unr = phi i64 [ 3, %.lr.ph.peel.next27 ], [ %indvars.iv.next.3, %12 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge.loopexit, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %store_forwarded.epil = phi i32 [ %34, %.epil.preheader ], [ %store_forwarded.unr, %._crit_edge.loopexit.unr-lcssa ]
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %31 = getelementptr i32, ptr %6, i64 %indvars.iv.epil
  %32 = getelementptr i8, ptr %31, i64 -8
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = add nsw i32 %33, %store_forwarded.epil
  store i32 %34, ptr %31, align 4, !tbaa !5
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.loopexit, label %.epil.preheader, !llvm.loop !12

._crit_edge.loopexit:                             ; preds = %.epil.preheader, %._crit_edge.loopexit.unr-lcssa
  %.phi.trans.insert = zext nneg i32 %0 to i64
  %.phi.trans.insert33 = getelementptr inbounds i32, ptr %6, i64 %.phi.trans.insert
  %.pre = load i32, ptr %.phi.trans.insert33, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %2, %._crit_edge.loopexit
  %35 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ undef, %2 ]
  tail call void @llvm.stackrestore.p0(ptr %5)
  br label %36

36:                                               ; preds = %1, %._crit_edge
  %.022 = phi i32 [ %35, %._crit_edge ], [ %0, %1 ]
  ret i32 %.022
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #1

attributes #0 = { nofree norecurse nosync 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 = { mustprogress nocallback nofree nosync nounwind willreturn }

!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/C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 2}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.unroll.disable"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopFullUnrollPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass