; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x24-迭代加深/170. 加成序列.ll (Z3dfsi)

; 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
@d = external dso_local global i32, align 4
@a = external dso_local global [20 x i32], align 16
@seen = external dso_local global [110 x i8], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z3dfsi(i32 noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr @d, align 4, !tbaa !5
  %10 = icmp eq i32 %8, %9
  br i1 %10, label %11, label %18

11:                                               ; preds = %1
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [20 x i32], ptr @a, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = icmp eq i32 %15, %16
  store i1 %17, ptr %2, align 1
  br label %86

18:                                               ; preds = %1
  call void @llvm.memset.p0.i64(ptr align 16 @seen, i8 0, i64 110, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %19 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %19, ptr %4, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %80, %18
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = icmp sge i32 %21, 1
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 2, ptr %5, align 4
  br label %83

24:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %25 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %25, ptr %6, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %74, %24
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = icmp sge i32 %27, 1
  br i1 %28, label %30, label %29

29:                                               ; preds = %26
  store i32 5, ptr %5, align 4
  br label %77

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [20 x i32], ptr @a, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [20 x i32], ptr @a, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = add nsw i32 %34, %38
  store i32 %39, ptr %7, align 4, !tbaa !5
  %40 = load i32, ptr %7, align 4, !tbaa !5
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [20 x i32], ptr @a, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = icmp sge i32 %40, %44
  br i1 %45, label %46, label %70

46:                                               ; preds = %30
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = icmp sle i32 %47, %48
  br i1 %49, label %50, label %70

50:                                               ; preds = %46
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [110 x i8], ptr @seen, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !9, !range !11, !noundef !12
  %55 = trunc i8 %54 to i1
  br i1 %55, label %70, label %56

56:                                               ; preds = %50
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [20 x i32], ptr @a, i64 0, i64 %60
  store i32 %57, ptr %61, align 4, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [110 x i8], ptr @seen, i64 0, i64 %63
  store i8 1, ptr %64, align 1, !tbaa !9
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  %67 = call noundef zeroext i1 @_Z3dfsi(i32 noundef %66)
  br i1 %67, label %68, label %69

68:                                               ; preds = %56
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %71

69:                                               ; preds = %56
  br label %70

70:                                               ; preds = %69, %50, %46, %30
  store i32 0, ptr %5, align 4
  br label %71

71:                                               ; preds = %70, %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %72 = load i32, ptr %5, align 4
  switch i32 %72, label %77 [
    i32 0, label %73
  ]

73:                                               ; preds = %71
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %6, align 4, !tbaa !5
  %76 = add nsw i32 %75, -1
  store i32 %76, ptr %6, align 4, !tbaa !5
  br label %26, !llvm.loop !13

77:                                               ; preds = %71, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %78 = load i32, ptr %5, align 4
  switch i32 %78, label %83 [
    i32 5, label %79
  ]

79:                                               ; preds = %77
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %4, align 4, !tbaa !5
  %82 = add nsw i32 %81, -1
  store i32 %82, ptr %4, align 4, !tbaa !5
  br label %20, !llvm.loop !15

83:                                               ; preds = %77, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %84 = load i32, ptr %5, align 4
  switch i32 %84, label %88 [
    i32 2, label %85
    i32 1, label %86
  ]

85:                                               ; preds = %83
  store i1 false, ptr %2, align 1
  br label %86

86:                                               ; preds = %85, %83, %11
  %87 = load i1, ptr %2, align 1
  ret i1 %87

88:                                               ; preds = %83
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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

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 nounwind willreturn memory(argmem: write) }
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++ 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"}
!15 = distinct !{!15, !14}


; 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
@d = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [20 x i32], align 16
@seen = external dso_local local_unnamed_addr global [110 x i8], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z3dfsi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @d, align 4, !tbaa !5
  %3 = icmp eq i32 %2, %0
  br i1 %3, label %4, label %10

4:                                                ; preds = %1
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [20 x i32], ptr @a, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = icmp eq i32 %7, %8
  br label %.loopexit

10:                                               ; preds = %1
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(110) @seen, i8 0, i64 110, i1 false)
  %11 = icmp sgt i32 %0, 0
  br i1 %11, label %.preheader.lr.ph, label %.loopexit

.preheader.lr.ph:                                 ; preds = %10
  %12 = zext nneg i32 %0 to i64
  %13 = getelementptr inbounds [20 x i32], ptr @a, i64 0, i64 %12
  %14 = add nuw nsw i32 %0, 1
  %15 = zext nneg i32 %14 to i64
  %16 = getelementptr inbounds [20 x i32], ptr @a, i64 0, i64 %15
  %.pre41.pre = load i32, ptr @n, align 4
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %35
  %.pre41 = phi i32 [ %.pre41.pre, %.preheader.lr.ph ], [ %.pre4142, %35 ]
  %indvars.iv = phi i64 [ %12, %.preheader.lr.ph ], [ %indvars.iv.next, %35 ]
  %17 = getelementptr inbounds [20 x i32], ptr @a, i64 0, i64 %indvars.iv
  br label %18

18:                                               ; preds = %.preheader, %.critedge
  %.pre4143 = phi i32 [ %.pre41, %.preheader ], [ %.pre4142, %.critedge ]
  %19 = phi i32 [ %.pre41, %.preheader ], [ %32, %.critedge ]
  %indvars.iv37 = phi i64 [ %indvars.iv, %.preheader ], [ %indvars.iv.next38, %.critedge ]
  %20 = load i32, ptr %17, align 4, !tbaa !5
  %21 = getelementptr inbounds [20 x i32], ptr @a, i64 0, i64 %indvars.iv37
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = add nsw i32 %22, %20
  %24 = load i32, ptr %13, align 4, !tbaa !5
  %.not = icmp slt i32 %23, %24
  %.not30 = icmp sgt i32 %23, %19
  %or.cond = select i1 %.not, i1 true, i1 %.not30
  br i1 %or.cond, label %.critedge, label %25

25:                                               ; preds = %18
  %26 = sext i32 %23 to i64
  %27 = getelementptr inbounds [110 x i8], ptr @seen, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !9, !range !11, !noundef !12
  %29 = trunc nuw i8 %28 to i1
  br i1 %29, label %.critedge, label %30

30:                                               ; preds = %25
  store i32 %23, ptr %16, align 4, !tbaa !5
  store i8 1, ptr %27, align 1, !tbaa !9
  %31 = tail call noundef zeroext i1 @_Z3dfsi(i32 noundef %14)
  %.pre = load i32, ptr @n, align 4
  br i1 %31, label %.loopexit, label %.critedge

.critedge:                                        ; preds = %30, %25, %18
  %.pre4142 = phi i32 [ %.pre, %30 ], [ %.pre4143, %25 ], [ %.pre4143, %18 ]
  %32 = phi i32 [ %.pre, %30 ], [ %19, %25 ], [ %19, %18 ]
  %indvars.iv.next38 = add nsw i64 %indvars.iv37, -1
  %33 = trunc nuw i64 %indvars.iv37 to i32
  %34 = icmp slt i32 %33, 2
  br i1 %34, label %35, label %18, !llvm.loop !13

35:                                               ; preds = %.critedge
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %36 = icmp sgt i64 %indvars.iv, 1
  br i1 %36, label %.preheader, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %35, %30, %10, %4
  %.5 = phi i1 [ %9, %4 ], [ false, %10 ], [ true, %30 ], [ false, %35 ]
  ret i1 %.5
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

!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"}
!15 = distinct !{!15, !14}


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