; LLVM IR from lzyrapx/Competitive-Programming :: HDUOJ/2795 （线段树）区间查询最大值.ll (Z5queryiiii)

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

@MAX = external dso_local global [800040 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
declare dso_local void @_Z6pushupi(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5queryiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %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
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = load i32, ptr %8, align 4, !tbaa !5
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %15, label %23

15:                                               ; preds = %4
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr %9, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [800040 x i32], ptr @MAX, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = sub nsw i32 %20, %16
  store i32 %21, ptr %19, align 4, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %22, ptr %5, align 4
  br label %54

23:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = add nsw i32 %24, %25
  %27 = ashr i32 %26, 1
  store i32 %27, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = shl i32 %28, 1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [800040 x i32], ptr @MAX, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = icmp sge i32 %32, %33
  br i1 %34, label %35, label %42

35:                                               ; preds = %23
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = shl i32 %39, 1
  %41 = call noundef i32 @_Z5queryiiii(i32 noundef %36, i32 noundef %37, i32 noundef %38, i32 noundef %40)
  store i32 %41, ptr %11, align 4, !tbaa !5
  br label %51

42:                                               ; preds = %23
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = load i32, ptr %9, align 4, !tbaa !5
  %48 = shl i32 %47, 1
  %49 = or i32 %48, 1
  %50 = call noundef i32 @_Z5queryiiii(i32 noundef %43, i32 noundef %45, i32 noundef %46, i32 noundef %49)
  store i32 %50, ptr %11, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %42, %35
  %52 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z6pushupi(i32 noundef %52)
  %53 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %53, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %54

54:                                               ; preds = %51, %15
  %55 = load i32, ptr %5, align 4
  ret i32 %55
}

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"

@MAX = external dso_local local_unnamed_addr global [800040 x i32], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5queryiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq i32 %1, %2
  br i1 %5, label %6, label %11

6:                                                ; preds = %4
  %7 = sext i32 %3 to i64
  %8 = getelementptr inbounds [800040 x i32], ptr @MAX, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = sub nsw i32 %9, %0
  store i32 %10, ptr %8, align 4, !tbaa !5
  br label %25

11:                                               ; preds = %4
  %12 = add nsw i32 %2, %1
  %13 = ashr i32 %12, 1
  %14 = shl i32 %3, 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [800040 x i32], ptr @MAX, i64 0, i64 %15
  %17 = load i32, ptr %16, align 8, !tbaa !5
  %.not = icmp slt i32 %17, %0
  br i1 %.not, label %20, label %18

18:                                               ; preds = %11
  %19 = tail call noundef i32 @_Z5queryiiii(i32 noundef %0, i32 noundef %1, i32 noundef %13, i32 noundef %14)
  br label %24

20:                                               ; preds = %11
  %21 = add nsw i32 %13, 1
  %22 = or disjoint i32 %14, 1
  %23 = tail call noundef i32 @_Z5queryiiii(i32 noundef %0, i32 noundef %21, i32 noundef %2, i32 noundef %22)
  br label %24

24:                                               ; preds = %20, %18
  %.0 = phi i32 [ %19, %18 ], [ %23, %20 ]
  tail call void @_Z6pushupi(i32 noundef %3)
  br label %25

25:                                               ; preds = %24, %6
  %.020 = phi i32 [ %1, %6 ], [ %.0, %24 ]
  ret i32 %.020
}

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

!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,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,TailCallElimPass