; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/2665(主席树).ll (Z6updateiRiiii)

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

@lson = external dso_local global [2000200 x i32], align 16
@rson = external dso_local global [2000200 x i32], align 16
@sum = external dso_local global [2000200 x i32], align 16
@tot = external dso_local global i32, align 4

; 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 @_Z6updateiRiiii(i32 noundef %0, ptr noundef nonnull align 4 dereferenceable(4) %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !5
  %12 = load i32, ptr @tot, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr @tot, align 4, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %13, ptr %14, align 4, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [2000200 x i32], ptr @lson, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = load ptr, ptr %7, align 8, !tbaa !9
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [2000200 x i32], ptr @lson, i64 0, i64 %21
  store i32 %18, ptr %22, align 4, !tbaa !5
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [2000200 x i32], ptr @rson, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = load ptr, ptr %7, align 8, !tbaa !9
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [2000200 x i32], ptr @rson, i64 0, i64 %29
  store i32 %26, ptr %30, align 4, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [2000200 x i32], ptr @sum, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  %36 = load ptr, ptr %7, align 8, !tbaa !9
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [2000200 x i32], ptr @sum, i64 0, i64 %38
  store i32 %35, ptr %39, align 4, !tbaa !5
  %40 = load i32, ptr %8, align 4, !tbaa !5
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = icmp eq i32 %40, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %5
  br label %78

44:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = load i32, ptr %9, align 4, !tbaa !5
  %47 = add nsw i32 %45, %46
  %48 = ashr i32 %47, 1
  store i32 %48, ptr %11, align 4, !tbaa !5
  %49 = load i32, ptr %10, align 4, !tbaa !5
  %50 = load i32, ptr %11, align 4, !tbaa !5
  %51 = icmp sle i32 %49, %50
  br i1 %51, label %52, label %64

52:                                               ; preds = %44
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [2000200 x i32], ptr @lson, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = load ptr, ptr %7, align 8, !tbaa !9
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [2000200 x i32], ptr @lson, i64 0, i64 %59
  %61 = load i32, ptr %8, align 4, !tbaa !5
  %62 = load i32, ptr %11, align 4, !tbaa !5
  %63 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z6updateiRiiii(i32 noundef %56, ptr noundef nonnull align 4 dereferenceable(4) %60, i32 noundef %61, i32 noundef %62, i32 noundef %63)
  br label %77

64:                                               ; preds = %44
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [2000200 x i32], ptr @rson, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = load ptr, ptr %7, align 8, !tbaa !9
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [2000200 x i32], ptr @rson, i64 0, i64 %71
  %73 = load i32, ptr %11, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  %75 = load i32, ptr %9, align 4, !tbaa !5
  %76 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z6updateiRiiii(i32 noundef %68, ptr noundef nonnull align 4 dereferenceable(4) %72, i32 noundef %74, i32 noundef %75, i32 noundef %76)
  br label %77

77:                                               ; preds = %64, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %78

78:                                               ; preds = %77, %43
  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}


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

@lson = external dso_local local_unnamed_addr global [2000200 x i32], align 16
@rson = external dso_local local_unnamed_addr global [2000200 x i32], align 16
@sum = external dso_local local_unnamed_addr global [2000200 x i32], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z6updateiRiiii(i32 noundef %0, ptr nocapture noundef nonnull align 4 dereferenceable(4) %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %32, %5
  %.tr.ph = phi i32 [ %14, %32 ], [ %0, %5 ]
  %.tr26.ph = phi ptr [ %33, %32 ], [ %1, %5 ]
  %.tr27.ph = phi i32 [ %34, %32 ], [ %2, %5 ]
  %.tr28.ph = phi i32 [ %.tr28, %32 ], [ %3, %5 ]
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.outer, %30
  %.tr = phi i32 [ %10, %30 ], [ %.tr.ph, %tailrecurse.outer ]
  %.tr26 = phi ptr [ %31, %30 ], [ %.tr26.ph, %tailrecurse.outer ]
  %.tr28 = phi i32 [ %27, %30 ], [ %.tr28.ph, %tailrecurse.outer ]
  %6 = load i32, ptr @tot, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @tot, align 4, !tbaa !5
  store i32 %7, ptr %.tr26, align 4, !tbaa !5
  %8 = sext i32 %.tr to i64
  %9 = getelementptr inbounds [2000200 x i32], ptr @lson, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = sext i32 %7 to i64
  %12 = getelementptr inbounds [2000200 x i32], ptr @lson, i64 0, i64 %11
  store i32 %10, ptr %12, align 4, !tbaa !5
  %13 = getelementptr inbounds [2000200 x i32], ptr @rson, i64 0, i64 %8
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = load i32, ptr %.tr26, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [2000200 x i32], ptr @rson, i64 0, i64 %16
  store i32 %14, ptr %17, align 4, !tbaa !5
  %18 = getelementptr inbounds [2000200 x i32], ptr @sum, i64 0, i64 %8
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  %21 = load i32, ptr %.tr26, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2000200 x i32], ptr @sum, i64 0, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !5
  %24 = icmp eq i32 %.tr27.ph, %.tr28
  br i1 %24, label %35, label %25

25:                                               ; preds = %tailrecurse
  %26 = add nsw i32 %.tr28, %.tr27.ph
  %27 = ashr i32 %26, 1
  %.not = icmp slt i32 %27, %4
  %28 = load i32, ptr %.tr26, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  br i1 %.not, label %32, label %30

30:                                               ; preds = %25
  %31 = getelementptr inbounds [2000200 x i32], ptr @lson, i64 0, i64 %29
  br label %tailrecurse

32:                                               ; preds = %25
  %33 = getelementptr inbounds [2000200 x i32], ptr @rson, i64 0, i64 %29
  %34 = add nsw i32 %27, 1
  br label %tailrecurse.outer

35:                                               ; preds = %tailrecurse
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass