; LLVM IR from upupming/algorithm :: acwing/日常刷题/kick-start/561. 大按钮.ll (Z3dfsii)

; 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
@trie = external dso_local global [6600 x [2 x i32]], align 16
@is_end = external dso_local global [6600 x i32], align 16

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z3dfsii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [6600 x i32], ptr @is_end, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %18

12:                                               ; preds = %2
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = sub nsw i32 %13, %14
  %16 = zext i32 %15 to i64
  %17 = shl i64 1, %16
  store i64 %17, ptr %3, align 8
  br label %56

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !9
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [6600 x [2 x i32]], ptr @trie, i64 0, i64 %20
  %22 = getelementptr inbounds [2 x i32], ptr %21, i64 0, i64 0
  %23 = load i32, ptr %22, align 8, !tbaa !5
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %36

25:                                               ; preds = %18
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [6600 x [2 x i32]], ptr @trie, i64 0, i64 %27
  %29 = getelementptr inbounds [2 x i32], ptr %28, i64 0, i64 0
  %30 = load i32, ptr %29, align 8, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  %33 = call noundef i64 @_Z3dfsii(i32 noundef %30, i32 noundef %32)
  %34 = load i64, ptr %6, align 8, !tbaa !9
  %35 = add nsw i64 %34, %33
  store i64 %35, ptr %6, align 8, !tbaa !9
  br label %36

36:                                               ; preds = %25, %18
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [6600 x [2 x i32]], ptr @trie, i64 0, i64 %38
  %40 = getelementptr inbounds [2 x i32], ptr %39, i64 0, i64 1
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %43, label %54

43:                                               ; preds = %36
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [6600 x [2 x i32]], ptr @trie, i64 0, i64 %45
  %47 = getelementptr inbounds [2 x i32], ptr %46, i64 0, i64 1
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  %51 = call noundef i64 @_Z3dfsii(i32 noundef %48, i32 noundef %50)
  %52 = load i64, ptr %6, align 8, !tbaa !9
  %53 = add nsw i64 %52, %51
  store i64 %53, ptr %6, align 8, !tbaa !9
  br label %54

54:                                               ; preds = %43, %36
  %55 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %55, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %56

56:                                               ; preds = %54, %12
  %57 = load i64, ptr %3, align 8
  ret i64 %57
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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"}
!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"

@n = external dso_local local_unnamed_addr global i32, align 4
@trie = external dso_local local_unnamed_addr global [6600 x [2 x i32]], align 16
@is_end = external dso_local local_unnamed_addr global [6600 x i32], align 16

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i64 @_Z3dfsii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [6600 x i32], ptr @is_end, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not21 = icmp eq i32 %5, 0
  br i1 %.not21, label %.lr.ph, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %2
  %accumulator.tr.lcssa = phi i64 [ 0, %2 ], [ %20, %tailrecurse ]
  %.tr17.lcssa = phi i32 [ %1, %2 ], [ %19, %tailrecurse ]
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = sub nsw i32 %6, %.tr17.lcssa
  %8 = zext nneg i32 %7 to i64
  %9 = shl nuw i64 1, %8
  br label %.loopexit

.lr.ph:                                           ; preds = %2, %tailrecurse
  %10 = phi i64 [ %21, %tailrecurse ], [ %3, %2 ]
  %.tr1723 = phi i32 [ %19, %tailrecurse ], [ %1, %2 ]
  %accumulator.tr22 = phi i64 [ %20, %tailrecurse ], [ 0, %2 ]
  %11 = getelementptr inbounds [6600 x [2 x i32]], ptr @trie, i64 0, i64 %10
  %12 = load i32, ptr %11, align 8, !tbaa !5
  %.not15 = icmp eq i32 %12, 0
  br i1 %.not15, label %16, label %13

13:                                               ; preds = %.lr.ph
  %14 = add nsw i32 %.tr1723, 1
  %15 = tail call noundef i64 @_Z3dfsii(i32 noundef %12, i32 noundef %14)
  br label %16

16:                                               ; preds = %13, %.lr.ph
  %.0 = phi i64 [ %15, %13 ], [ 0, %.lr.ph ]
  %17 = getelementptr inbounds i8, ptr %11, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %.not16 = icmp eq i32 %18, 0
  br i1 %.not16, label %.loopexit, label %tailrecurse

tailrecurse:                                      ; preds = %16
  %19 = add nsw i32 %.tr1723, 1
  %20 = add nsw i64 %.0, %accumulator.tr22
  %21 = sext i32 %18 to i64
  %22 = getelementptr inbounds [6600 x i32], ptr @is_end, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %.not = icmp eq i32 %23, 0
  br i1 %.not, label %.lr.ph, label %tailrecurse._crit_edge

.loopexit:                                        ; preds = %16, %tailrecurse._crit_edge
  %accumulator.tr20 = phi i64 [ %accumulator.tr.lcssa, %tailrecurse._crit_edge ], [ %accumulator.tr22, %16 ]
  %.012 = phi i64 [ %9, %tailrecurse._crit_edge ], [ %.0, %16 ]
  %accumulator.ret.tr = add nsw i64 %.012, %accumulator.tr20
  ret i64 %accumulator.ret.tr
}

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(read, 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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass