; LLVM IR from Dev-XYS/Algorithms :: Splay-with-Parent(Array).ll (Z5splayii)

; 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 [100000 x i32], align 16
@root = external dso_local global i32, align 4

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5whichi(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5splayii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %39, %2
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [100000 x i32], ptr @fa, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp ne i32 %9, %10
  br i1 %11, label %12, label %41

12:                                               ; preds = %5
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100000 x i32], ptr @fa, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100000 x i32], ptr @fa, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = icmp ne i32 %19, %20
  br i1 %21, label %22, label %39

22:                                               ; preds = %12
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = call noundef i32 @_Z5whichi(i32 noundef %23)
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [100000 x i32], ptr @fa, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = call noundef i32 @_Z5whichi(i32 noundef %28)
  %30 = icmp eq i32 %24, %29
  br i1 %30, label %31, label %36

31:                                               ; preds = %22
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [100000 x i32], ptr @fa, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  call void @_Z6rotatei(i32 noundef %35)
  br label %38

36:                                               ; preds = %22
  %37 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z6rotatei(i32 noundef %37)
  br label %38

38:                                               ; preds = %36, %31
  br label %39

39:                                               ; preds = %38, %12
  %40 = load i32, ptr %3, align 4, !tbaa !5
  call void @_Z6rotatei(i32 noundef %40)
  br label %5, !llvm.loop !9

41:                                               ; preds = %5
  %42 = load i32, ptr %4, align 4, !tbaa !5
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %46

44:                                               ; preds = %41
  %45 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %45, ptr @root, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %44, %41
  ret void
}

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 = { inlinehint 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"}


; 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 [100000 x i32], align 16
@root = external dso_local local_unnamed_addr global i32, align 4

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5whichi(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5splayii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [100000 x i32], ptr @fa, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not13 = icmp eq i32 %5, %1
  br i1 %.not13, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %17
  %6 = phi i32 [ %18, %17 ], [ %5, %2 ]
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [100000 x i32], ptr @fa, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not12 = icmp eq i32 %9, %1
  br i1 %.not12, label %17, label %10

10:                                               ; preds = %.lr.ph
  %11 = tail call noundef i32 @_Z5whichi(i32 noundef %0)
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = tail call noundef i32 @_Z5whichi(i32 noundef %12)
  %14 = icmp eq i32 %11, %13
  br i1 %14, label %15, label %.sink.split

15:                                               ; preds = %10
  %16 = load i32, ptr %4, align 4, !tbaa !5
  br label %.sink.split

.sink.split:                                      ; preds = %10, %15
  %.sink = phi i32 [ %16, %15 ], [ %0, %10 ]
  tail call void @_Z6rotatei(i32 noundef %.sink)
  br label %17

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

._crit_edge:                                      ; preds = %17, %2
  %19 = icmp eq i32 %1, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %._crit_edge
  store i32 %0, ptr @root, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %20, %._crit_edge
  ret void
}

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 = { inlinehint 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,SROAPass,SimplifyCFGPass,TailCallElimPass