; LLVM IR from tangjz/acm-icpc :: hdu/6087.ll (Z7RebuildiPi)

; 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.Treap = type { i32, i32, i32, i32, i64 }

@pool = external dso_local global [2500001 x %struct.Treap], 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 uwtable
define dso_local void @_Z7RebuildiPi(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %10, label %9

9:                                                ; preds = %2
  br label %46

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.Treap, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !11
  store i32 %15, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.Treap, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !14
  store i32 %20, ptr %6, align 4, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !9
  call void @_Z7RebuildiPi(i32 noundef %21, ptr noundef %22)
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.Treap, ptr %25, i32 0, i32 3
  %27 = load i32, ptr %26, align 4, !tbaa !15
  %28 = load ptr, ptr %4, align 8, !tbaa !9
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.Treap, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 8, !tbaa !16
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i32, ptr %28, i64 %34
  store i32 %27, ptr %35, align 4, !tbaa !5
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !9
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.Treap, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !16
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds i32, ptr %37, i64 %43
  %45 = getelementptr inbounds i32, ptr %44, i64 1
  call void @_Z7RebuildiPi(i32 noundef %36, ptr noundef %45)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %46

46:                                               ; preds = %10, %9
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS5Treap", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !13, i64 16}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !6, i64 4}
!15 = !{!12, !6, i64 12}
!16 = !{!12, !6, i64 8}


; 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.Treap = type { i32, i32, i32, i32, i64 }

@pool = external dso_local local_unnamed_addr global [2500001 x %struct.Treap], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(read, argmem: write, inaccessiblemem: none) uwtable
define dso_local void @_Z7RebuildiPi(i32 noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %.not11 = icmp eq i32 %0, 0
  br i1 %.not11, label %tailrecurse._crit_edge, label %tailrecurse

tailrecurse:                                      ; preds = %2, %tailrecurse
  %.tr1013 = phi ptr [ %18, %tailrecurse ], [ %1, %2 ]
  %.tr12 = phi i32 [ %7, %tailrecurse ], [ %0, %2 ]
  %3 = sext i32 %.tr12 to i64
  %4 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %3
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %4, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  tail call void @_Z7RebuildiPi(i32 noundef %5, ptr noundef %.tr1013)
  %8 = getelementptr inbounds i8, ptr %4, i64 12
  %9 = load i32, ptr %8, align 4, !tbaa !12
  %10 = sext i32 %5 to i64
  %11 = getelementptr inbounds [2500001 x %struct.Treap], ptr @pool, i64 0, i64 %10, i32 2
  %12 = load i32, ptr %11, align 8, !tbaa !13
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i32, ptr %.tr1013, i64 %13
  store i32 %9, ptr %14, align 4, !tbaa !14
  %15 = load i32, ptr %11, align 8, !tbaa !13
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i32, ptr %.tr1013, i64 %16
  %18 = getelementptr inbounds i8, ptr %17, i64 4
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %tailrecurse._crit_edge, label %tailrecurse

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %2
  ret void
}

attributes #0 = { mustprogress nofree nosync nounwind memory(read, argmem: write, 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, !7, i64 0}
!6 = !{!"_ZTS5Treap", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 12}
!13 = !{!6, !7, i64 8}
!14 = !{!7, !7, i64 0}


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