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

; 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

; 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 noundef i32 @_Z5queryiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !5
  %15 = load i32, ptr %9, align 4, !tbaa !5
  %16 = load i32, ptr %10, align 4, !tbaa !5
  %17 = icmp eq i32 %15, %16
  br i1 %17, label %18, label %20

18:                                               ; preds = %5
  %19 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %19, ptr %6, align 4
  br label %73

20:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = load i32, ptr %10, align 4, !tbaa !5
  %23 = add nsw i32 %21, %22
  %24 = ashr i32 %23, 1
  store i32 %24, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [2000200 x i32], ptr @lson, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [2000200 x i32], ptr @sum, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [2000200 x i32], ptr @lson, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [2000200 x i32], ptr @sum, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = sub nsw i32 %31, %38
  store i32 %39, ptr %13, align 4, !tbaa !5
  %40 = load i32, ptr %13, align 4, !tbaa !5
  %41 = load i32, ptr %11, align 4, !tbaa !5
  %42 = icmp sge i32 %40, %41
  br i1 %42, label %43, label %56

43:                                               ; preds = %20
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [2000200 x i32], ptr @lson, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [2000200 x i32], ptr @lson, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = load i32, ptr %12, align 4, !tbaa !5
  %54 = load i32, ptr %11, align 4, !tbaa !5
  %55 = call noundef i32 @_Z5queryiiiii(i32 noundef %47, i32 noundef %51, i32 noundef %52, i32 noundef %53, i32 noundef %54)
  store i32 %55, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %72

56:                                               ; preds = %20
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [2000200 x i32], ptr @rson, i64 0, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = load i32, ptr %8, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [2000200 x i32], ptr @rson, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = load i32, ptr %12, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  %67 = load i32, ptr %10, align 4, !tbaa !5
  %68 = load i32, ptr %11, align 4, !tbaa !5
  %69 = load i32, ptr %13, align 4, !tbaa !5
  %70 = sub nsw i32 %68, %69
  %71 = call noundef i32 @_Z5queryiiiii(i32 noundef %60, i32 noundef %64, i32 noundef %66, i32 noundef %67, i32 noundef %70)
  store i32 %71, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %72

72:                                               ; preds = %56, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %73

73:                                               ; preds = %72, %18
  %74 = load i32, ptr %6, align 4
  ret i32 %74
}

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


; 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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z5queryiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %23, %5
  %.tr.ph = phi i32 [ %25, %23 ], [ %0, %5 ]
  %.tr27.ph = phi i32 [ %27, %23 ], [ %1, %5 ]
  %.tr28.ph = phi i32 [ %28, %23 ], [ %2, %5 ]
  %.tr29.ph = phi i32 [ %.tr29, %23 ], [ %3, %5 ]
  %.tr30.ph = phi i32 [ %29, %23 ], [ %4, %5 ]
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.outer, %7
  %.tr = phi i32 [ %18, %7 ], [ %.tr.ph, %tailrecurse.outer ]
  %.tr27 = phi i32 [ %12, %7 ], [ %.tr27.ph, %tailrecurse.outer ]
  %.tr29 = phi i32 [ %9, %7 ], [ %.tr29.ph, %tailrecurse.outer ]
  %6 = icmp eq i32 %.tr28.ph, %.tr29
  br i1 %6, label %30, label %7

7:                                                ; preds = %tailrecurse
  %8 = add nsw i32 %.tr29, %.tr28.ph
  %9 = ashr i32 %8, 1
  %10 = sext i32 %.tr27 to i64
  %11 = getelementptr inbounds [2000200 x i32], ptr @lson, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [2000200 x i32], ptr @sum, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = sext i32 %.tr to i64
  %17 = getelementptr inbounds [2000200 x i32], ptr @lson, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [2000200 x i32], ptr @sum, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sub nsw i32 %15, %21
  %.not = icmp slt i32 %22, %.tr30.ph
  br i1 %.not, label %23, label %tailrecurse

23:                                               ; preds = %7
  %24 = getelementptr inbounds [2000200 x i32], ptr @rson, i64 0, i64 %16
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = getelementptr inbounds [2000200 x i32], ptr @rson, i64 0, i64 %10
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = add nsw i32 %9, 1
  %29 = sub nsw i32 %.tr30.ph, %22
  br label %tailrecurse.outer

30:                                               ; preds = %tailrecurse
  ret i32 %.tr28.ph
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, 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,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass