; LLVM IR from lzyrapx/Competitive-Programming :: ACdream/1076（dp+置换+康拓展开）.ll (Z6CantorPi)

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

@p = external dso_local global [8 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 nounwind uwtable
define dso_local noundef i32 @_Z6CantorPi(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %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 ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %53, %1
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp sle i32 %9, 5
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %56

12:                                               ; preds = %8
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i32, ptr %13, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = sub nsw i32 %17, 1
  store i32 %18, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %40, %12
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %43

24:                                               ; preds = %19
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr %25, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr %30, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = icmp slt i32 %29, %34
  br i1 %35, label %36, label %39

36:                                               ; preds = %24
  %37 = load i32, ptr %4, align 4, !tbaa !9
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr %4, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %36, %24
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %7, align 4, !tbaa !9
  br label %19, !llvm.loop !11

43:                                               ; preds = %23
  %44 = load i32, ptr %4, align 4, !tbaa !9
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = sub nsw i32 5, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [8 x i32], ptr @p, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = mul nsw i32 %44, %49
  %51 = load i32, ptr %3, align 4, !tbaa !9
  %52 = add nsw i32 %51, %50
  store i32 %52, ptr %3, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %43
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !13

56:                                               ; preds = %11
  %57 = load i32, ptr %3, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 1, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %58
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@p = external dso_local local_unnamed_addr global [8 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 -2147483647, -2147483648) i32 @_Z6CantorPi(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
._crit_edge.4:
  %1 = getelementptr inbounds i8, ptr %0, i64 4
  %2 = load i32, ptr %1, align 4, !tbaa !5
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @p, i64 16), align 16, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = load i32, ptr getelementptr inbounds (i8, ptr @p, i64 12), align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @p, i64 8), align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = load i32, ptr getelementptr inbounds (i8, ptr @p, i64 4), align 4, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 20
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = add nsw i32 %14, -1
  %16 = icmp slt i32 %2, %14
  %17 = sext i1 %16 to i32
  %spec.select.4 = add nsw i32 %15, %17
  %18 = icmp slt i32 %5, %14
  %19 = sext i1 %18 to i32
  %spec.select.4.1 = add nsw i32 %spec.select.4, %19
  %20 = icmp slt i32 %8, %14
  %21 = sext i1 %20 to i32
  %spec.select.4.2 = add nsw i32 %spec.select.4.1, %21
  %22 = icmp slt i32 %11, %14
  %23 = sext i1 %22 to i32
  %spec.select.4.3 = add nsw i32 %spec.select.4.2, %23
  %24 = add nsw i32 %11, -1
  %25 = icmp slt i32 %2, %11
  %26 = sext i1 %25 to i32
  %spec.select.3 = add nsw i32 %24, %26
  %27 = icmp slt i32 %5, %11
  %28 = sext i1 %27 to i32
  %spec.select.3.1 = add nsw i32 %spec.select.3, %28
  %29 = icmp slt i32 %8, %11
  %30 = sext i1 %29 to i32
  %spec.select.3.2 = add nsw i32 %spec.select.3.1, %30
  %31 = mul nsw i32 %12, %spec.select.3.2
  %32 = add nsw i32 %8, -1
  %33 = icmp slt i32 %2, %8
  %34 = sext i1 %33 to i32
  %spec.select.2 = add nsw i32 %32, %34
  %35 = icmp slt i32 %5, %8
  %36 = sext i1 %35 to i32
  %spec.select.2.1 = add nsw i32 %spec.select.2, %36
  %37 = mul nsw i32 %9, %spec.select.2.1
  %38 = add nsw i32 %5, -1
  %39 = icmp slt i32 %2, %5
  %40 = sext i1 %39 to i32
  %spec.select.1 = add nsw i32 %38, %40
  %41 = mul nsw i32 %6, %spec.select.1
  %42 = add nsw i32 %2, -1
  %43 = mul nsw i32 %3, %42
  %44 = add nsw i32 %41, %43
  %45 = add nsw i32 %37, %44
  %46 = add nsw i32 %31, %45
  %47 = load i32, ptr @p, align 16, !tbaa !5
  %48 = mul nsw i32 %47, %spec.select.4.3
  %49 = add nsw i32 %48, %46
  %50 = add nsw i32 %49, 1
  ret i32 %50
}

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