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

@seg = external dso_local global [1048809 x i32], align 16
@lazy = external dso_local global [1048809 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 @_Z5queryiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %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 %9, align 4, !tbaa !5
  %13 = load i32, ptr %7, align 4, !tbaa !5
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %15, label %24

15:                                               ; preds = %4
  %16 = load i32, ptr %9, 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 %24

19:                                               ; preds = %15
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [1048809 x i32], ptr @seg, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  store i32 %23, ptr %5, align 4
  br label %129

24:                                               ; preds = %15, %4
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = icmp ne i32 %25, %26
  br i1 %27, label %28, label %102

28:                                               ; preds = %24
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %102

34:                                               ; preds = %28
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = add nsw i32 %35, %36
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1048809 x i32], ptr @seg, i64 0, i64 %38
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %41
  %43 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %39, ptr noundef nonnull align 4 dereferenceable(4) %42)
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = add nsw i32 %45, %46
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [1048809 x i32], ptr @seg, i64 0, i64 %48
  store i32 %44, ptr %49, align 4, !tbaa !5
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = add nsw i32 %50, %51
  %53 = add nsw i32 %52, 1
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [1048809 x i32], ptr @seg, i64 0, i64 %54
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %57
  %59 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %55, ptr noundef nonnull align 4 dereferenceable(4) %58)
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = add nsw i32 %61, %62
  %64 = add nsw i32 %63, 1
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [1048809 x i32], ptr @seg, i64 0, i64 %65
  store i32 %60, ptr %66, align 4, !tbaa !5
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = add nsw i32 %67, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %70
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %73
  %75 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %71, ptr noundef nonnull align 4 dereferenceable(4) %74)
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = add nsw i32 %77, %78
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %80
  store i32 %76, ptr %81, align 4, !tbaa !5
  %82 = load i32, ptr %6, align 4, !tbaa !5
  %83 = load i32, ptr %6, align 4, !tbaa !5
  %84 = add nsw i32 %82, %83
  %85 = add nsw i32 %84, 1
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %86
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %89
  %91 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %87, ptr noundef nonnull align 4 dereferenceable(4) %90)
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = load i32, ptr %6, align 4, !tbaa !5
  %94 = load i32, ptr %6, align 4, !tbaa !5
  %95 = add nsw i32 %93, %94
  %96 = add nsw i32 %95, 1
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %97
  store i32 %92, ptr %98, align 4, !tbaa !5
  %99 = load i32, ptr %6, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %100
  store i32 0, ptr %101, align 4, !tbaa !5
  br label %102

102:                                              ; preds = %34, %28, %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %103 = load i32, ptr %7, align 4, !tbaa !5
  %104 = load i32, ptr %8, align 4, !tbaa !5
  %105 = add nsw i32 %103, %104
  %106 = ashr i32 %105, 1
  store i32 %106, ptr %10, align 4, !tbaa !5
  %107 = load i32, ptr %9, align 4, !tbaa !5
  %108 = load i32, ptr %10, align 4, !tbaa !5
  %109 = icmp sle i32 %107, %108
  br i1 %109, label %110, label %118

110:                                              ; preds = %102
  %111 = load i32, ptr %6, align 4, !tbaa !5
  %112 = load i32, ptr %6, align 4, !tbaa !5
  %113 = add nsw i32 %111, %112
  %114 = load i32, ptr %7, align 4, !tbaa !5
  %115 = load i32, ptr %10, align 4, !tbaa !5
  %116 = load i32, ptr %9, align 4, !tbaa !5
  %117 = call noundef i32 @_Z5queryiiii(i32 noundef %113, i32 noundef %114, i32 noundef %115, i32 noundef %116)
  store i32 %117, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %128

118:                                              ; preds = %102
  %119 = load i32, ptr %6, align 4, !tbaa !5
  %120 = load i32, ptr %6, align 4, !tbaa !5
  %121 = add nsw i32 %119, %120
  %122 = add nsw i32 %121, 1
  %123 = load i32, ptr %10, align 4, !tbaa !5
  %124 = add nsw i32 %123, 1
  %125 = load i32, ptr %8, align 4, !tbaa !5
  %126 = load i32, ptr %9, align 4, !tbaa !5
  %127 = call noundef i32 @_Z5queryiiii(i32 noundef %122, i32 noundef %124, i32 noundef %125, i32 noundef %126)
  store i32 %127, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %128

128:                                              ; preds = %118, %110
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %129

129:                                              ; preds = %128, %19
  %130 = load i32, ptr %5, align 4
  ret i32 %130
}

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 global [1048809 x i32], align 16
@lazy = external dso_local global [1048809 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 nounwind uwtable
define dso_local noundef i32 @_Z5queryiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = icmp eq i32 %3, %1
  %6 = icmp eq i32 %3, %2
  %or.cond5561 = and i1 %5, %6
  br i1 %or.cond5561, label %tailrecurse.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %tailrecurse.outer
  %7 = phi i1 [ %62, %tailrecurse.outer ], [ %5, %4 ]
  %.tr51.ph64 = phi i32 [ %.us-phi60, %tailrecurse.outer ], [ %2, %4 ]
  %.tr50.ph63 = phi i32 [ %61, %tailrecurse.outer ], [ %1, %4 ]
  %.tr.ph62 = phi i32 [ %60, %tailrecurse.outer ], [ %0, %4 ]
  br i1 %7, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph, %tailrecurse.us
  %.tr5157.us = phi i32 [ %30, %tailrecurse.us ], [ %.tr51.ph64, %.lr.ph ]
  %.tr56.us = phi i32 [ %31, %tailrecurse.us ], [ %.tr.ph62, %.lr.ph ]
  %.not.us = icmp eq i32 %.tr50.ph63, %.tr5157.us
  br i1 %.not.us, label %tailrecurse.us, label %8

8:                                                ; preds = %.lr.ph.split.us
  %9 = sext i32 %.tr56.us to i64
  %10 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %.not48.us = icmp eq i32 %11, 0
  br i1 %.not48.us, label %tailrecurse.us, label %12

12:                                               ; preds = %8
  %13 = shl nsw i32 %.tr56.us, 1
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1048809 x i32], ptr @seg, i64 0, i64 %14
  %16 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %15, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %17 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %17, ptr %15, align 8, !tbaa !5
  %18 = or disjoint i32 %13, 1
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [1048809 x i32], ptr @seg, i64 0, i64 %19
  %21 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %20, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %22 = load i32, ptr %21, align 4, !tbaa !5
  store i32 %22, ptr %20, align 4, !tbaa !5
  %23 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %14
  %24 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %23, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %25 = load i32, ptr %24, align 4, !tbaa !5
  store i32 %25, ptr %23, align 8, !tbaa !5
  %26 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %19
  %27 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %26, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %28 = load i32, ptr %27, align 4, !tbaa !5
  store i32 %28, ptr %26, align 4, !tbaa !5
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %tailrecurse.us

tailrecurse.us:                                   ; preds = %12, %8, %.lr.ph.split.us
  %29 = add i32 %.tr5157.us, %.tr50.ph63
  %30 = ashr i32 %29, 1
  %.not49.us = icmp slt i32 %30, %3
  %31 = shl nsw i32 %.tr56.us, 1
  br i1 %.not49.us, label %tailrecurse.outer, label %.lr.ph.split.us

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %4
  %.tr.lcssa = phi i32 [ %0, %4 ], [ %.pre, %tailrecurse ], [ %60, %tailrecurse.outer ]
  %32 = sext i32 %.tr.lcssa to i64
  %33 = getelementptr inbounds [1048809 x i32], ptr @seg, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  ret i32 %34

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr5157 = phi i32 [ %58, %tailrecurse ], [ %.tr51.ph64, %.lr.ph ]
  %.tr56 = phi i32 [ %.pre, %tailrecurse ], [ %.tr.ph62, %.lr.ph ]
  %.not = icmp eq i32 %.tr50.ph63, %.tr5157
  br i1 %.not, label %56, label %35

35:                                               ; preds = %.lr.ph.split
  %36 = sext i32 %.tr56 to i64
  %37 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %.not48 = icmp eq i32 %38, 0
  br i1 %.not48, label %56, label %39

39:                                               ; preds = %35
  %40 = shl nsw i32 %.tr56, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1048809 x i32], ptr @seg, i64 0, i64 %41
  %43 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %42, ptr noundef nonnull align 4 dereferenceable(4) %37)
  %44 = load i32, ptr %43, align 4, !tbaa !5
  store i32 %44, ptr %42, align 8, !tbaa !5
  %45 = or disjoint i32 %40, 1
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [1048809 x i32], ptr @seg, i64 0, i64 %46
  %48 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %47, ptr noundef nonnull align 4 dereferenceable(4) %37)
  %49 = load i32, ptr %48, align 4, !tbaa !5
  store i32 %49, ptr %47, align 4, !tbaa !5
  %50 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %41
  %51 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %50, ptr noundef nonnull align 4 dereferenceable(4) %37)
  %52 = load i32, ptr %51, align 4, !tbaa !5
  store i32 %52, ptr %50, align 8, !tbaa !5
  %53 = getelementptr inbounds [1048809 x i32], ptr @lazy, i64 0, i64 %46
  %54 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %53, ptr noundef nonnull align 4 dereferenceable(4) %37)
  %55 = load i32, ptr %54, align 4, !tbaa !5
  store i32 %55, ptr %53, align 4, !tbaa !5
  store i32 0, ptr %37, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %39, %35, %.lr.ph.split
  %57 = add i32 %.tr5157, %.tr50.ph63
  %58 = ashr i32 %57, 1
  %.not49 = icmp slt i32 %58, %3
  %.pre = shl nsw i32 %.tr56, 1
  br i1 %.not49, label %tailrecurse.outer, label %tailrecurse

tailrecurse:                                      ; preds = %56
  %59 = icmp eq i32 %58, %3
  br i1 %59, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

tailrecurse.outer:                                ; preds = %tailrecurse.us, %56
  %.pre-phi = phi i32 [ %.pre, %56 ], [ %31, %tailrecurse.us ]
  %.us-phi = phi i32 [ %58, %56 ], [ %30, %tailrecurse.us ]
  %.us-phi60 = phi i32 [ %.tr5157, %56 ], [ %.tr5157.us, %tailrecurse.us ]
  %60 = or disjoint i32 %.pre-phi, 1
  %61 = add nsw i32 %.us-phi, 1
  %62 = icmp eq i32 %61, %3
  %63 = icmp eq i32 %.us-phi60, %3
  %or.cond55 = and i1 %62, %63
  br i1 %or.cond55, label %tailrecurse.outer._crit_edge, label %.lr.ph
}

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

!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: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass