; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd/727.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"

@seg = external dso_local global [262377 x i32], align 16

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #0

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

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

; 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) #2 {
  %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
  %15 = 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
  %16 = load i32, ptr %10, align 4, !tbaa !5
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = icmp eq i32 %16, %17
  br i1 %18, label %19, label %28

19:                                               ; preds = %5
  %20 = load i32, ptr %11, align 4, !tbaa !5
  %21 = load i32, ptr %9, 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 [262377 x i32], ptr @seg, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  store i32 %27, ptr %6, align 4
  br label %83

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 = ashr i32 %31, 1
  store i32 %32, ptr %12, align 4, !tbaa !5
  %33 = load i32, ptr %11, align 4, !tbaa !5
  %34 = load i32, ptr %12, align 4, !tbaa !5
  %35 = icmp sle i32 %33, %34
  br i1 %35, label %36, label %45

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

45:                                               ; preds = %28
  %46 = load i32, ptr %10, align 4, !tbaa !5
  %47 = load i32, ptr %12, align 4, !tbaa !5
  %48 = icmp sgt i32 %46, %47
  br i1 %48, label %49, label %60

49:                                               ; preds = %45
  %50 = load i32, ptr %7, align 4, !tbaa !5
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = add nsw i32 %50, %51
  %53 = add nsw i32 %52, 1
  %54 = load i32, ptr %12, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = load i32, ptr %10, align 4, !tbaa !5
  %58 = load i32, ptr %11, align 4, !tbaa !5
  %59 = call noundef i32 @_Z5queryiiiii(i32 noundef %53, i32 noundef %55, i32 noundef %56, i32 noundef %57, i32 noundef %58)
  store i32 %59, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %82

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

82:                                               ; preds = %60, %49, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %83

83:                                               ; preds = %82, %23
  %84 = load i32, ptr %6, align 4
  ret i32 %84
}

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


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

@seg = external dso_local local_unnamed_addr global [262377 x i32], align 16

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind 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 #2 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = icmp eq i32 %3, %1
  %9 = icmp eq i32 %4, %2
  %or.cond4955 = and i1 %8, %9
  br i1 %or.cond4955, label %tailrecurse.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %tailrecurse.outer
  %10 = phi i1 [ %25, %tailrecurse.outer ], [ %8, %5 ]
  %.tr43.ph58 = phi i32 [ %.us-phi54, %tailrecurse.outer ], [ %2, %5 ]
  %.tr42.ph57 = phi i32 [ %24, %tailrecurse.outer ], [ %1, %5 ]
  %.tr.ph56 = phi i32 [ %23, %tailrecurse.outer ], [ %0, %5 ]
  br i1 %10, label %.lr.ph.split, label %tailrecurse.us

tailrecurse.us:                                   ; preds = %.lr.ph, %tailrecurse.us
  %.tr4351.us = phi i32 [ %12, %tailrecurse.us ], [ %.tr43.ph58, %.lr.ph ]
  %.tr50.us = phi i32 [ %13, %tailrecurse.us ], [ %.tr.ph56, %.lr.ph ]
  %11 = add i32 %.tr4351.us, %.tr42.ph57
  %12 = ashr i32 %11, 1
  %.not.us = icmp slt i32 %12, %4
  %13 = shl nsw i32 %.tr50.us, 1
  br i1 %.not.us, label %.split.us, label %tailrecurse.us

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %5
  %.tr.lcssa = phi i32 [ %0, %5 ], [ %19, %tailrecurse ], [ %23, %tailrecurse.outer ]
  %14 = sext i32 %.tr.lcssa to i64
  %15 = getelementptr inbounds [262377 x i32], ptr @seg, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  br label %common.ret123

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr4351 = phi i32 [ %18, %tailrecurse ], [ %.tr43.ph58, %.lr.ph ]
  %.tr50 = phi i32 [ %19, %tailrecurse ], [ %.tr.ph56, %.lr.ph ]
  %17 = add i32 %.tr4351, %.tr42.ph57
  %18 = ashr i32 %17, 1
  %.not = icmp slt i32 %18, %4
  br i1 %.not, label %.split.us, label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph.split
  %19 = shl nsw i32 %.tr50, 1
  %20 = icmp eq i32 %18, %4
  br i1 %20, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

.split.us:                                        ; preds = %tailrecurse.us, %.lr.ph.split
  %.us-phi = phi i32 [ %18, %.lr.ph.split ], [ %12, %tailrecurse.us ]
  %.us-phi53 = phi i32 [ %.tr50, %.lr.ph.split ], [ %.tr50.us, %tailrecurse.us ]
  %.us-phi54 = phi i32 [ %.tr4351, %.lr.ph.split ], [ %.tr4351.us, %tailrecurse.us ]
  %21 = icmp slt i32 %.us-phi, %3
  br i1 %21, label %tailrecurse.outer, label %27

tailrecurse.outer:                                ; preds = %.split.us
  %22 = shl nsw i32 %.us-phi53, 1
  %23 = or disjoint i32 %22, 1
  %24 = add nsw i32 %.us-phi, 1
  %25 = icmp eq i32 %24, %3
  %26 = icmp eq i32 %.us-phi54, %4
  %or.cond49 = and i1 %25, %26
  br i1 %or.cond49, label %tailrecurse.outer._crit_edge, label %.lr.ph

common.ret123:                                    ; preds = %27, %tailrecurse.outer._crit_edge
  %common.ret123.op = phi i32 [ %16, %tailrecurse.outer._crit_edge ], [ %34, %27 ]
  ret i32 %common.ret123.op

27:                                               ; preds = %.split.us
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %28 = shl nsw i32 %.us-phi53, 1
  %29 = tail call noundef i32 @_Z5queryiiiii(i32 noundef %28, i32 noundef %.tr42.ph57, i32 noundef %.us-phi, i32 noundef %3, i32 noundef %.us-phi)
  store i32 %29, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  %30 = or disjoint i32 %28, 1
  %31 = add nsw i32 %.us-phi, 1
  %32 = tail call noundef i32 @_Z5queryiiiii(i32 noundef %30, i32 noundef %31, i32 noundef %.us-phi54, i32 noundef %31, i32 noundef %4)
  store i32 %32, ptr %7, align 4, !tbaa !5
  %33 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %34 = load i32, ptr %33, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  br label %common.ret123
}

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