; LLVM IR from lzyrapx/Competitive-Programming :: LibreOJ/106（Splay）（104基础上加区间）.ll (Z5SplayiiRi)

; 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 [1500300 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4sideii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6Rotatei(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5SplayiiRi(i32 noundef %0, i32 noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !9
  br label %7

7:                                                ; preds = %58, %3
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [1500300 x i32], ptr @fa, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !5
  %13 = icmp ne i32 %11, %12
  br i1 %13, label %14, label %60

14:                                               ; preds = %7
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [1500300 x i32], ptr @fa, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = call noundef i32 @_Z4sideii(i32 noundef %15, i32 noundef %19)
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1500300 x i32], ptr @fa, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1500300 x i32], ptr @fa, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [1500300 x i32], ptr @fa, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = call noundef i32 @_Z4sideii(i32 noundef %24, i32 noundef %31)
  %33 = icmp eq i32 %20, %32
  br i1 %33, label %34, label %58

34:                                               ; preds = %14
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [1500300 x i32], ptr @fa, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = load ptr, ptr %6, align 8, !tbaa !9
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = icmp ne i32 %38, %40
  br i1 %41, label %42, label %58

42:                                               ; preds = %34
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1500300 x i32], ptr @fa, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1500300 x i32], ptr @fa, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = load ptr, ptr %6, align 8, !tbaa !9
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = icmp ne i32 %49, %51
  br i1 %52, label %53, label %58

53:                                               ; preds = %42
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [1500300 x i32], ptr @fa, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  call void @_Z6Rotatei(i32 noundef %57)
  br label %58

58:                                               ; preds = %53, %42, %34, %14
  %59 = load i32, ptr %4, align 4, !tbaa !5
  call void @_Z6Rotatei(i32 noundef %59)
  br label %7, !llvm.loop !11

60:                                               ; preds = %7
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %66

63:                                               ; preds = %60
  %64 = load i32, ptr %4, align 4, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 %64, ptr %65, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %63, %60
  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" }

!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 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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 [1500300 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4sideii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6Rotatei(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5SplayiiRi(i32 noundef %0, i32 noundef %1, ptr nocapture noundef nonnull align 4 dereferenceable(4) %2) local_unnamed_addr #0 {
  %4 = sext i32 %0 to i64
  %5 = getelementptr inbounds [1500300 x i32], ptr @fa, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not19 = icmp eq i32 %6, %1
  br i1 %.not19, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %23
  %7 = phi i32 [ %24, %23 ], [ %6, %3 ]
  %8 = tail call noundef i32 @_Z4sideii(i32 noundef %0, i32 noundef %7)
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [1500300 x i32], ptr @fa, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = tail call noundef i32 @_Z4sideii(i32 noundef %9, i32 noundef %12)
  %14 = icmp eq i32 %8, %13
  br i1 %14, label %15, label %23

15:                                               ; preds = %.lr.ph
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %.not17 = icmp eq i32 %16, %17
  br i1 %.not17, label %23, label %18

18:                                               ; preds = %15
  %19 = sext i32 %16 to i64
  %20 = getelementptr inbounds [1500300 x i32], ptr @fa, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %.not18 = icmp eq i32 %21, %17
  br i1 %.not18, label %23, label %22

22:                                               ; preds = %18
  tail call void @_Z6Rotatei(i32 noundef %16)
  br label %23

23:                                               ; preds = %22, %18, %15, %.lr.ph
  tail call void @_Z6Rotatei(i32 noundef %0)
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %.not = icmp eq i32 %24, %1
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

._crit_edge:                                      ; preds = %23, %3
  %25 = icmp eq i32 %1, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %._crit_edge
  store i32 %0, ptr %2, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %26, %._crit_edge
  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" }

!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: EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass