; LLVM IR from tangjz/acm-icpc :: 51nod/1648.ll (Z5splayi)

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

%struct.Node = type { i32, [2 x i32], i32 }

@t = external dso_local global [100009 x %struct.Node], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z6isrooti(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6rotatei(i32 noundef) #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
define dso_local void @_Z5splayi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %63, %1
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = call noundef zeroext i1 @_Z6isrooti(i32 noundef %6)
  %8 = xor i1 %7, true
  br i1 %8, label %9, label %65

9:                                                ; preds = %5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [100009 x %struct.Node], ptr @t, i64 0, i64 %11
  %13 = getelementptr inbounds %struct.Node, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 16, !tbaa !9
  %15 = call noundef zeroext i1 @_Z6isrooti(i32 noundef %14)
  br i1 %15, label %63, label %16

16:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100009 x %struct.Node], ptr @t, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.Node, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 16, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100009 x %struct.Node], ptr @t, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.Node, ptr %23, i32 0, i32 1
  %25 = getelementptr inbounds [2 x i32], ptr %24, i64 0, i64 1
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = icmp eq i32 %26, %27
  %29 = zext i1 %28 to i32
  store i32 %29, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100009 x %struct.Node], ptr @t, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.Node, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 16, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100009 x %struct.Node], ptr @t, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.Node, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 16, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100009 x %struct.Node], ptr @t, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.Node, ptr %40, i32 0, i32 1
  %42 = getelementptr inbounds [2 x i32], ptr %41, i64 0, i64 1
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100009 x %struct.Node], ptr @t, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.Node, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 16, !tbaa !9
  %49 = icmp eq i32 %43, %48
  %50 = zext i1 %49 to i32
  store i32 %50, ptr %4, align 4, !tbaa !5
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = icmp eq i32 %51, %52
  br i1 %53, label %54, label %60

54:                                               ; preds = %16
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100009 x %struct.Node], ptr @t, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.Node, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 16, !tbaa !9
  call void @_Z6rotatei(i32 noundef %59)
  br label %62

60:                                               ; preds = %16
  %61 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z6rotatei(i32 noundef %61)
  br label %62

62:                                               ; preds = %60, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %63

63:                                               ; preds = %62, %9
  %64 = load i32, ptr %2, align 4, !tbaa !5
  call void @_Z6rotatei(i32 noundef %64)
  br label %5, !llvm.loop !11

65:                                               ; preds = %5
  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 = !{!10, !6, i64 0}
!10 = !{!"_ZTS4Node", !6, i64 0, !7, i64 4, !6, i64 12}
!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"

%struct.Node = type { i32, [2 x i32], i32 }

@t = external dso_local local_unnamed_addr global [100009 x %struct.Node], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z6isrooti(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 @_Z5splayi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call noundef zeroext i1 @_Z6isrooti(i32 noundef %0)
  br i1 %2, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [100009 x %struct.Node], ptr @t, i64 0, i64 %3
  br label %5

5:                                                ; preds = %.lr.ph, %20
  %6 = load i32, ptr %4, align 16, !tbaa !5
  %7 = tail call noundef zeroext i1 @_Z6isrooti(i32 noundef %6)
  br i1 %7, label %20, label %.sink.split

.sink.split:                                      ; preds = %5
  %8 = load i32, ptr %4, align 16, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [100009 x %struct.Node], ptr @t, i64 0, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %12 = load i32, ptr %11, align 8, !tbaa !10
  %13 = icmp eq i32 %12, %0
  %14 = load i32, ptr %10, align 16, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100009 x %struct.Node], ptr @t, i64 0, i64 %15, i32 1, i64 1
  %17 = load i32, ptr %16, align 8, !tbaa !10
  %18 = icmp ne i32 %17, %8
  %19 = xor i1 %13, %18
  %. = select i1 %19, i32 %8, i32 %0
  tail call void @_Z6rotatei(i32 noundef %.)
  br label %20

20:                                               ; preds = %.sink.split, %5
  tail call void @_Z6rotatei(i32 noundef %0)
  %21 = tail call noundef zeroext i1 @_Z6isrooti(i32 noundef %0)
  br i1 %21, label %._crit_edge, label %5, !llvm.loop !11

._crit_edge:                                      ; preds = %20, %1
  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, !7, i64 0}
!6 = !{!"_ZTS4Node", !7, i64 0, !8, i64 4, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass