; LLVM IR from lzyrapx/Competitive-Programming :: BZOJ/3224（splay模板）.ll (Z3delv)

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

@fa = external dso_local global [100005 x i32], align 16
@ch = external dso_local global [100005 x [2 x i32]], align 16
@s = external dso_local global [100005 x i32], align 16
@root = external dso_local global i32, align 4
@cnt = external dso_local global [100005 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z2upRKi(ptr noundef nonnull align 4 dereferenceable(4)) #0

; 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5splayRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3delv() #0 {
  %1 = alloca i32, align 4
  %2 = load i32, ptr @root, align 4, !tbaa !5
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds [100005 x i32], ptr @cnt, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 1
  br i1 %6, label %7, label %18

7:                                                ; preds = %0
  %8 = load i32, ptr @root, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [100005 x i32], ptr @cnt, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr %10, align 4, !tbaa !5
  %13 = load i32, ptr @root, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100005 x i32], ptr @s, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = add nsw i32 %16, -1
  store i32 %17, ptr %15, align 4, !tbaa !5
  br label %87

18:                                               ; preds = %0
  %19 = load i32, ptr @root, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [100005 x [2 x i32]], ptr @ch, 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 %38, label %25

25:                                               ; preds = %18
  %26 = load i32, ptr @root, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100005 x [2 x i32]], ptr @ch, i64 0, i64 %27
  %29 = getelementptr inbounds [2 x i32], ptr %28, i64 0, i64 1
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100005 x i32], ptr @fa, i64 0, i64 %31
  store i32 0, ptr %32, align 4, !tbaa !5
  %33 = load i32, ptr @root, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100005 x [2 x i32]], ptr @ch, i64 0, i64 %34
  %36 = getelementptr inbounds [2 x i32], ptr %35, i64 0, i64 1
  %37 = load i32, ptr %36, align 4, !tbaa !5
  store i32 %37, ptr @root, align 4, !tbaa !5
  br label %87

38:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  %39 = load i32, ptr @root, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100005 x [2 x i32]], ptr @ch, i64 0, i64 %40
  %42 = getelementptr inbounds [2 x i32], ptr %41, i64 0, i64 0
  %43 = load i32, ptr %42, align 8, !tbaa !5
  store i32 %43, ptr %1, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %51, %38
  %45 = load i32, ptr %1, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [100005 x [2 x i32]], ptr @ch, i64 0, i64 %46
  %48 = getelementptr inbounds [2 x i32], ptr %47, i64 0, i64 1
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %51, label %57

51:                                               ; preds = %44
  %52 = load i32, ptr %1, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100005 x [2 x i32]], ptr @ch, i64 0, i64 %53
  %55 = getelementptr inbounds [2 x i32], ptr %54, i64 0, i64 1
  %56 = load i32, ptr %55, align 4, !tbaa !5
  store i32 %56, ptr %1, align 4, !tbaa !5
  br label %44, !llvm.loop !9

57:                                               ; preds = %44
  call void @_Z5splayRKiS0_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) @root)
  %58 = load i32, ptr @root, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100005 x [2 x i32]], ptr @ch, i64 0, i64 %59
  %61 = getelementptr inbounds [2 x i32], ptr %60, i64 0, i64 1
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = load i32, ptr %1, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [100005 x [2 x i32]], ptr @ch, i64 0, i64 %64
  %66 = getelementptr inbounds [2 x i32], ptr %65, i64 0, i64 1
  store i32 %62, ptr %66, align 4, !tbaa !5
  %67 = load i32, ptr %1, align 4, !tbaa !5
  store i32 %67, ptr @root, align 4, !tbaa !5
  %68 = load i32, ptr %1, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [100005 x i32], ptr @fa, i64 0, i64 %69
  store i32 0, ptr %70, align 4, !tbaa !5
  %71 = load i32, ptr @root, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [100005 x [2 x i32]], ptr @ch, i64 0, i64 %72
  %74 = getelementptr inbounds [2 x i32], ptr %73, i64 0, i64 1
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %77, label %86

77:                                               ; preds = %57
  %78 = load i32, ptr @root, align 4, !tbaa !5
  %79 = load i32, ptr @root, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [100005 x [2 x i32]], ptr @ch, i64 0, i64 %80
  %82 = getelementptr inbounds [2 x i32], ptr %81, i64 0, i64 1
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [100005 x i32], ptr @fa, i64 0, i64 %84
  store i32 %78, ptr %85, align 4, !tbaa !5
  br label %86

86:                                               ; preds = %77, %57
  call void @_Z2upRKi(ptr noundef nonnull align 4 dereferenceable(4) @root)
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  br label %87

87:                                               ; preds = %86, %25, %7
  ret void
}

attributes #0 = { 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 #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"}
!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"

@fa = external dso_local local_unnamed_addr global [100005 x i32], align 16
@ch = external dso_local local_unnamed_addr global [100005 x [2 x i32]], align 16
@s = external dso_local local_unnamed_addr global [100005 x i32], align 16
@root = external dso_local global i32, align 4
@cnt = external dso_local local_unnamed_addr global [100005 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z2upRKi(ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z5splayRKiS0_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3delv() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = load i32, ptr @root, align 4, !tbaa !5
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds [100005 x i32], ptr @cnt, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 1
  br i1 %6, label %7, label %12

7:                                                ; preds = %0
  %8 = add nsw i32 %5, -1
  store i32 %8, ptr %4, align 4, !tbaa !5
  %9 = getelementptr inbounds [100005 x i32], ptr @s, i64 0, i64 %3
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr %9, align 4, !tbaa !5
  br label %38

12:                                               ; preds = %0
  %13 = getelementptr inbounds [100005 x [2 x i32]], ptr @ch, i64 0, i64 %3
  %14 = load i32, ptr %13, align 8, !tbaa !5
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %15, label %20

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %13, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100005 x i32], ptr @fa, i64 0, i64 %18
  store i32 0, ptr %19, align 4, !tbaa !5
  store i32 %17, ptr @root, align 4, !tbaa !5
  br label %38

20:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #2
  br label %21

21:                                               ; preds = %21, %20
  %storemerge = phi i32 [ %14, %20 ], [ %24, %21 ]
  %22 = sext i32 %storemerge to i64
  %23 = getelementptr inbounds [100005 x [2 x i32]], ptr @ch, i64 0, i64 %22, i64 1
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %.not3 = icmp eq i32 %24, 0
  br i1 %.not3, label %25, label %21, !llvm.loop !9

25:                                               ; preds = %21
  store i32 %storemerge, ptr %1, align 4, !tbaa !5
  call void @_Z5splayRKiS0_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) @root)
  %26 = load i32, ptr @root, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100005 x [2 x i32]], ptr @ch, i64 0, i64 %27, i64 1
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = load i32, ptr %1, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100005 x [2 x i32]], ptr @ch, i64 0, i64 %31, i64 1
  store i32 %29, ptr %32, align 4, !tbaa !5
  store i32 %30, ptr @root, align 4, !tbaa !5
  %33 = getelementptr inbounds [100005 x i32], ptr @fa, i64 0, i64 %31
  store i32 0, ptr %33, align 4, !tbaa !5
  %.not4 = icmp eq i32 %29, 0
  br i1 %.not4, label %37, label %34

34:                                               ; preds = %25
  %35 = sext i32 %29 to i64
  %36 = getelementptr inbounds [100005 x i32], ptr @fa, i64 0, i64 %35
  store i32 %30, ptr %36, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %34, %25
  call void @_Z2upRKi(ptr noundef nonnull align 4 dereferenceable(4) @root)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #2
  br label %38

38:                                               ; preds = %37, %15, %7
  ret void
}

attributes #0 = { 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 #1 = { mustprogress 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"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,SimplifyCFGPass