; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/1997（模拟）（汉诺塔）.ll (Z5hannoiiii)

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

@a = external dso_local global [4 x [70 x i32]], align 16

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

16:                                               ; preds = %4
  store i32 1, ptr %5, align 4
  br label %80

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [4 x [70 x i32]], ptr @a, i64 0, i64 %19
  %21 = getelementptr inbounds [70 x i32], ptr %20, i64 0, i64 0
  %22 = load i32, ptr %21, align 8, !tbaa !5
  store i32 %22, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [4 x [70 x i32]], ptr @a, i64 0, i64 %24
  %26 = getelementptr inbounds [70 x i32], ptr %25, i64 0, i64 0
  %27 = load i32, ptr %26, align 8, !tbaa !5
  store i32 %27, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [4 x [70 x i32]], ptr @a, i64 0, i64 %29
  %31 = getelementptr inbounds [70 x i32], ptr %30, i64 0, i64 0
  %32 = load i32, ptr %31, align 8, !tbaa !5
  store i32 %32, ptr %12, align 4, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [4 x [70 x i32]], ptr @a, i64 0, i64 %34
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [70 x i32], ptr %35, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = icmp eq i32 %39, %40
  br i1 %41, label %42, label %55

42:                                               ; preds = %17
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [4 x [70 x i32]], ptr @a, i64 0, i64 %44
  %46 = getelementptr inbounds [70 x i32], ptr %45, i64 0, i64 0
  %47 = load i32, ptr %46, align 8, !tbaa !5
  %48 = add nsw i32 %47, -1
  store i32 %48, ptr %46, align 8, !tbaa !5
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = sub nsw i32 %49, 1
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = call noundef i32 @_Z5hannoiiii(i32 noundef %50, i32 noundef %51, i32 noundef %52, i32 noundef %53)
  store i32 %54, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %79

55:                                               ; preds = %17
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [4 x [70 x i32]], ptr @a, i64 0, i64 %57
  %59 = load i32, ptr %12, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [70 x i32], ptr %58, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = icmp eq i32 %62, %63
  br i1 %64, label %65, label %78

65:                                               ; preds = %55
  %66 = load i32, ptr %9, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [4 x [70 x i32]], ptr @a, i64 0, i64 %67
  %69 = getelementptr inbounds [70 x i32], ptr %68, i64 0, i64 0
  %70 = load i32, ptr %69, align 8, !tbaa !5
  %71 = add nsw i32 %70, -1
  store i32 %71, ptr %69, align 8, !tbaa !5
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = sub nsw i32 %72, 1
  %74 = load i32, ptr %8, align 4, !tbaa !5
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = load i32, ptr %9, align 4, !tbaa !5
  %77 = call noundef i32 @_Z5hannoiiii(i32 noundef %73, i32 noundef %74, i32 noundef %75, i32 noundef %76)
  store i32 %77, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %79

78:                                               ; preds = %55
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %79

79:                                               ; preds = %78, %65, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %80

80:                                               ; preds = %79, %16
  %81 = load i32, ptr %5, align 4
  ret i32 %81
}

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

; 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 = { 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"}


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

@a = external dso_local local_unnamed_addr global [4 x [70 x i32]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 0, 2) i32 @_Z5hannoiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp slt i32 %0, 1
  br i1 %5, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %4, %tailrecurse.outer
  %.tr24.ph37 = phi i32 [ %.tr2433, %tailrecurse.outer ], [ %3, %4 ]
  %.tr23.ph36 = phi i32 [ %.tr22.ph35, %tailrecurse.outer ], [ %2, %4 ]
  %.tr22.ph35 = phi i32 [ %.tr2332, %tailrecurse.outer ], [ %1, %4 ]
  %.tr.ph34 = phi i32 [ %25, %tailrecurse.outer ], [ %0, %4 ]
  %6 = sext i32 %.tr22.ph35 to i64
  %7 = getelementptr inbounds [4 x [70 x i32]], ptr @a, i64 0, i64 %6
  %.promoted = load i32, ptr %7, align 8, !tbaa !5
  %8 = sext i32 %.promoted to i64
  br label %9

9:                                                ; preds = %.lr.ph, %tailrecurse
  %indvars.iv = phi i64 [ %8, %.lr.ph ], [ %indvars.iv.next, %tailrecurse ]
  %.tr2433 = phi i32 [ %.tr24.ph37, %.lr.ph ], [ %.tr2332, %tailrecurse ]
  %.tr2332 = phi i32 [ %.tr23.ph36, %.lr.ph ], [ %.tr2433, %tailrecurse ]
  %.tr31 = phi i32 [ %.tr.ph34, %.lr.ph ], [ %17, %tailrecurse ]
  %10 = sext i32 %.tr2433 to i64
  %11 = getelementptr inbounds [4 x [70 x i32]], ptr @a, i64 0, i64 %10
  %12 = load i32, ptr %11, align 8, !tbaa !5
  %13 = getelementptr inbounds [4 x [70 x i32]], ptr @a, i64 0, i64 %6, i64 %indvars.iv
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = icmp eq i32 %14, %.tr31
  br i1 %15, label %tailrecurse, label %19

tailrecurse:                                      ; preds = %9
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %16 = trunc nsw i64 %indvars.iv.next to i32
  store i32 %16, ptr %7, align 8, !tbaa !5
  %17 = add nsw i32 %.tr31, -1
  %18 = icmp slt i32 %.tr31, 2
  br i1 %18, label %.loopexit, label %9

19:                                               ; preds = %9
  %20 = sext i32 %12 to i64
  %21 = getelementptr inbounds [4 x [70 x i32]], ptr @a, i64 0, i64 %10, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = icmp eq i32 %22, %.tr31
  br i1 %23, label %tailrecurse.outer, label %.loopexit

tailrecurse.outer:                                ; preds = %19
  %24 = add nsw i32 %12, -1
  store i32 %24, ptr %11, align 8, !tbaa !5
  %25 = add nsw i32 %.tr31, -1
  %26 = icmp slt i32 %.tr31, 2
  br i1 %26, label %.loopexit, label %.lr.ph

.loopexit:                                        ; preds = %19, %tailrecurse.outer, %tailrecurse, %4
  %.1 = phi i32 [ 1, %4 ], [ 1, %tailrecurse ], [ 1, %tailrecurse.outer ], [ 0, %19 ]
  ret i32 %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: 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" }

!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: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass