; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/LONG/APRIL15/FRMQ/frmq.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"

@tree = external dso_local global [500000 x i64], 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1

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

19:                                               ; preds = %5
  %20 = load i32, ptr %9, align 4, !tbaa !5
  %21 = load i32, ptr %11, align 4, !tbaa !5
  %22 = icmp eq i32 %20, %21
  br i1 %22, label %23, label %28

23:                                               ; preds = %19
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [500000 x i64], ptr @tree, i64 0, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !9
  store i64 %27, ptr %6, align 8
  br label %79

28:                                               ; preds = %19, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %29 = load i32, ptr %8, align 4, !tbaa !5
  %30 = load i32, ptr %9, align 4, !tbaa !5
  %31 = add nsw i32 %29, %30
  %32 = sdiv i32 %31, 2
  store i32 %32, ptr %12, align 4, !tbaa !5
  %33 = load i32, ptr %10, align 4, !tbaa !5
  %34 = load i32, ptr %12, align 4, !tbaa !5
  %35 = icmp sgt i32 %33, %34
  br i1 %35, label %36, label %46

36:                                               ; preds = %28
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = mul nsw i32 2, %37
  %39 = add nsw i32 %38, 1
  %40 = load i32, ptr %12, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  %42 = load i32, ptr %9, align 4, !tbaa !5
  %43 = load i32, ptr %10, align 4, !tbaa !5
  %44 = load i32, ptr %11, align 4, !tbaa !5
  %45 = call noundef i64 @_Z5queryiiiii(i32 noundef %39, i32 noundef %41, i32 noundef %42, i32 noundef %43, i32 noundef %44)
  store i64 %45, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %78

46:                                               ; preds = %28
  %47 = load i32, ptr %11, align 4, !tbaa !5
  %48 = load i32, ptr %12, align 4, !tbaa !5
  %49 = icmp sle i32 %47, %48
  br i1 %49, label %50, label %58

50:                                               ; preds = %46
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = mul nsw i32 2, %51
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = load i32, ptr %12, align 4, !tbaa !5
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = load i32, ptr %11, align 4, !tbaa !5
  %57 = call noundef i64 @_Z5queryiiiii(i32 noundef %52, i32 noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef %56)
  store i64 %57, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %78

58:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = mul nsw i32 2, %59
  %61 = load i32, ptr %8, align 4, !tbaa !5
  %62 = load i32, ptr %12, align 4, !tbaa !5
  %63 = load i32, ptr %10, align 4, !tbaa !5
  %64 = load i32, ptr %12, align 4, !tbaa !5
  %65 = call noundef i64 @_Z5queryiiiii(i32 noundef %60, i32 noundef %61, i32 noundef %62, i32 noundef %63, i32 noundef %64)
  store i64 %65, ptr %14, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = mul nsw i32 2, %66
  %68 = add nsw i32 %67, 1
  %69 = load i32, ptr %12, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  %71 = load i32, ptr %9, align 4, !tbaa !5
  %72 = load i32, ptr %12, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  %74 = load i32, ptr %11, align 4, !tbaa !5
  %75 = call noundef i64 @_Z5queryiiiii(i32 noundef %68, i32 noundef %70, i32 noundef %71, i32 noundef %73, i32 noundef %74)
  store i64 %75, ptr %15, align 8, !tbaa !9
  %76 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %14, ptr noundef nonnull align 8 dereferenceable(8) %15)
  %77 = load i64, ptr %76, align 8, !tbaa !9
  store i64 %77, ptr %6, align 8
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %78

78:                                               ; preds = %58, %50, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %79

79:                                               ; preds = %78, %23
  %80 = load i64, ptr %6, align 8
  ret i64 %80
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #2 = { 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 #3 = { 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 = !{!"long long", !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"

@tree = external dso_local local_unnamed_addr global [500000 x i64], align 16

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z5queryiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = icmp eq i32 %1, %3
  %9 = icmp eq i32 %2, %4
  %or.cond4866 = and i1 %8, %9
  br i1 %or.cond4866, label %tailrecurse.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %tailrecurse.outer
  %10 = phi i1 [ %28, %tailrecurse.outer ], [ %8, %5 ]
  %.tr39.ph69 = phi i32 [ %.us-phi53, %tailrecurse.outer ], [ %2, %5 ]
  %.tr38.ph68 = phi i32 [ %27, %tailrecurse.outer ], [ %1, %5 ]
  %.tr.ph67 = phi i32 [ %26, %tailrecurse.outer ], [ %0, %5 ]
  br i1 %10, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph
  %11 = add i32 %.tr39.ph69, %.tr38.ph68
  %12 = sdiv i32 %11, 2
  %13 = icmp slt i32 %12, %3
  br i1 %13, label %tailrecurse.outer, label %.lr.ph62.preheader

.lr.ph62.preheader:                               ; preds = %.lr.ph.split.us
  %.not.us134 = icmp slt i32 %12, %4
  br i1 %.not.us134, label %.split55.us, label %tailrecurse.us

.lr.ph62:                                         ; preds = %tailrecurse.us
  %.not.us = icmp slt i32 %17, %4
  br i1 %.not.us, label %.split55.us, label %tailrecurse.us

tailrecurse.us:                                   ; preds = %.lr.ph62.preheader, %.lr.ph62
  %.tr49.us61135 = phi i32 [ %15, %.lr.ph62 ], [ %.tr.ph67, %.lr.ph62.preheader ]
  %14 = phi i32 [ %17, %.lr.ph62 ], [ %12, %.lr.ph62.preheader ]
  %15 = shl nsw i32 %.tr49.us61135, 1
  %16 = add i32 %14, %.tr38.ph68
  %17 = sdiv i32 %16, 2
  %18 = icmp slt i32 %17, %3
  br i1 %18, label %tailrecurse.outer, label %.lr.ph62

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %5
  %.tr.lcssa = phi i32 [ %0, %5 ], [ %31, %tailrecurse ], [ %26, %tailrecurse.outer ]
  %19 = sext i32 %.tr.lcssa to i64
  %20 = getelementptr inbounds [500000 x i64], ptr @tree, i64 0, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !5
  br label %common.ret205

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr3950 = phi i32 [ %23, %tailrecurse ], [ %.tr39.ph69, %.lr.ph ]
  %.tr49 = phi i32 [ %31, %tailrecurse ], [ %.tr.ph67, %.lr.ph ]
  %22 = add i32 %.tr3950, %.tr38.ph68
  %23 = sdiv i32 %22, 2
  %24 = icmp slt i32 %23, %3
  br i1 %24, label %tailrecurse.outer, label %30

tailrecurse.outer:                                ; preds = %tailrecurse.us, %.lr.ph.split, %.lr.ph.split.us
  %.us-phi = phi i32 [ %12, %.lr.ph.split.us ], [ %23, %.lr.ph.split ], [ %17, %tailrecurse.us ]
  %.us-phi52 = phi i32 [ %.tr.ph67, %.lr.ph.split.us ], [ %.tr49, %.lr.ph.split ], [ %15, %tailrecurse.us ]
  %.us-phi53 = phi i32 [ %.tr39.ph69, %.lr.ph.split.us ], [ %.tr3950, %.lr.ph.split ], [ %14, %tailrecurse.us ]
  %25 = shl nsw i32 %.us-phi52, 1
  %26 = or disjoint i32 %25, 1
  %27 = add nsw i32 %.us-phi, 1
  %28 = icmp eq i32 %27, %3
  %29 = icmp eq i32 %.us-phi53, %4
  %or.cond48 = and i1 %28, %29
  br i1 %or.cond48, label %tailrecurse.outer._crit_edge, label %.lr.ph

30:                                               ; preds = %.lr.ph.split
  %.not = icmp slt i32 %23, %4
  br i1 %.not, label %.split55.us, label %tailrecurse

tailrecurse:                                      ; preds = %30
  %31 = shl nsw i32 %.tr49, 1
  %32 = icmp eq i32 %23, %4
  br i1 %32, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

common.ret205:                                    ; preds = %.split55.us, %tailrecurse.outer._crit_edge
  %common.ret205.op = phi i64 [ %21, %tailrecurse.outer._crit_edge ], [ %39, %.split55.us ]
  ret i64 %common.ret205.op

.split55.us:                                      ; preds = %.lr.ph62.preheader, %.lr.ph62, %30
  %.us-phi57 = phi i32 [ %23, %30 ], [ %17, %.lr.ph62 ], [ %12, %.lr.ph62.preheader ]
  %.us-phi58 = phi i32 [ %.tr49, %30 ], [ %15, %.lr.ph62 ], [ %.tr.ph67, %.lr.ph62.preheader ]
  %.us-phi59 = phi i32 [ %.tr3950, %30 ], [ %14, %.lr.ph62 ], [ %.tr39.ph69, %.lr.ph62.preheader ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %33 = shl nsw i32 %.us-phi58, 1
  %34 = tail call noundef i64 @_Z5queryiiiii(i32 noundef %33, i32 noundef %.tr38.ph68, i32 noundef %.us-phi57, i32 noundef %3, i32 noundef %.us-phi57)
  store i64 %34, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  %35 = or disjoint i32 %33, 1
  %36 = add nsw i32 %.us-phi57, 1
  %37 = tail call noundef i64 @_Z5queryiiiii(i32 noundef %35, i32 noundef %36, i32 noundef %.us-phi59, i32 noundef %36, i32 noundef %4)
  store i64 %37, ptr %7, align 8, !tbaa !5
  %38 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %7)
  %39 = load i64, ptr %38, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  br label %common.ret205
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 #2 = { 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 #3 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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