; LLVM IR from tangjz/acm-icpc :: 51nod/1559.ll (Z3queiiiii)

; 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 [262145 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #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 i32 @_Z3queiiiii(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 sle 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 sle 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 [262145 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 %82

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 @_Z3queiiiii(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 %81

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 @_Z3queiiiii(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 %81

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 %11, align 4, !tbaa !5
  %68 = call noundef i32 @_Z3queiiiii(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 %10, align 4, !tbaa !5
  %77 = load i32, ptr %11, align 4, !tbaa !5
  %78 = call noundef i32 @_Z3queiiiii(i32 noundef %72, i32 noundef %74, i32 noundef %75, i32 noundef %76, i32 noundef %77)
  store i32 %78, ptr %15, align 4, !tbaa !5
  %79 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %14, ptr noundef nonnull align 4 dereferenceable(4) %15)
  %80 = load i32, ptr %79, align 4, !tbaa !5
  store i32 %80, 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 %81

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

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

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


; 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 [262145 x i32], 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 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) 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 i32 @_Z3queiiiii(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
  %.not58 = icmp sgt i32 %3, %1
  %.not425159 = icmp sgt i32 %2, %4
  %or.cond5260 = or i1 %.not58, %.not425159
  br i1 %or.cond5260, label %.lr.ph, label %tailrecurse.outer._crit_edge

.lr.ph:                                           ; preds = %5, %tailrecurse.outer
  %.not64 = phi i1 [ %.not, %tailrecurse.outer ], [ %.not58, %5 ]
  %.tr45.ph63 = phi i32 [ %.us-phi57, %tailrecurse.outer ], [ %2, %5 ]
  %.tr44.ph62 = phi i32 [ %20, %tailrecurse.outer ], [ %1, %5 ]
  %.tr.ph61 = phi i32 [ %19, %tailrecurse.outer ], [ %0, %5 ]
  br i1 %.not64, label %tailrecurse.us, label %.lr.ph.split

tailrecurse.us:                                   ; preds = %.lr.ph, %tailrecurse.us
  %.tr4554.us = phi i32 [ %9, %tailrecurse.us ], [ %.tr45.ph63, %.lr.ph ]
  %.tr53.us = phi i32 [ %10, %tailrecurse.us ], [ %.tr.ph61, %.lr.ph ]
  %8 = add i32 %.tr4554.us, %.tr44.ph62
  %9 = ashr i32 %8, 1
  %.not43.us = icmp slt i32 %9, %4
  %10 = shl nsw i32 %.tr53.us, 1
  br i1 %.not43.us, label %.split.us, label %tailrecurse.us

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %5
  %.tr.lcssa = phi i32 [ %0, %5 ], [ %16, %tailrecurse ], [ %19, %tailrecurse.outer ]
  %11 = sext i32 %.tr.lcssa to i64
  %12 = getelementptr inbounds [262145 x i32], ptr @seg, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  br label %common.ret129

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr4554 = phi i32 [ %15, %tailrecurse ], [ %.tr45.ph63, %.lr.ph ]
  %.tr53 = phi i32 [ %16, %tailrecurse ], [ %.tr.ph61, %.lr.ph ]
  %14 = add i32 %.tr4554, %.tr44.ph62
  %15 = ashr i32 %14, 1
  %.not43 = icmp slt i32 %15, %4
  br i1 %.not43, label %.split.us, label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph.split
  %16 = shl nsw i32 %.tr53, 1
  %.not42 = icmp sgt i32 %15, %4
  br i1 %.not42, label %.lr.ph.split, label %tailrecurse.outer._crit_edge

.split.us:                                        ; preds = %.lr.ph.split, %tailrecurse.us
  %.us-phi = phi i32 [ %9, %tailrecurse.us ], [ %15, %.lr.ph.split ]
  %.us-phi56 = phi i32 [ %.tr53.us, %tailrecurse.us ], [ %.tr53, %.lr.ph.split ]
  %.us-phi57 = phi i32 [ %.tr4554.us, %tailrecurse.us ], [ %.tr4554, %.lr.ph.split ]
  %17 = icmp slt i32 %.us-phi, %3
  br i1 %17, label %tailrecurse.outer, label %21

tailrecurse.outer:                                ; preds = %.split.us
  %18 = shl nsw i32 %.us-phi56, 1
  %19 = or disjoint i32 %18, 1
  %20 = add nsw i32 %.us-phi, 1
  %.not = icmp slt i32 %20, %3
  %.not4251 = icmp sgt i32 %.us-phi57, %4
  %or.cond52 = or i1 %.not, %.not4251
  br i1 %or.cond52, label %.lr.ph, label %tailrecurse.outer._crit_edge

common.ret129:                                    ; preds = %21, %tailrecurse.outer._crit_edge
  %common.ret129.op = phi i32 [ %13, %tailrecurse.outer._crit_edge ], [ %28, %21 ]
  ret i32 %common.ret129.op

21:                                               ; preds = %.split.us
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %22 = shl nsw i32 %.us-phi56, 1
  %23 = tail call noundef i32 @_Z3queiiiii(i32 noundef %22, i32 noundef %.tr44.ph62, i32 noundef %.us-phi, i32 noundef %3, i32 noundef %4)
  store i32 %23, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #3
  %24 = or disjoint i32 %22, 1
  %25 = add nsw i32 %.us-phi, 1
  %26 = tail call noundef i32 @_Z3queiiiii(i32 noundef %24, i32 noundef %25, i32 noundef %.us-phi57, i32 noundef %3, i32 noundef %4)
  store i32 %26, ptr %7, align 4, !tbaa !5
  %27 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %28 = load i32, ptr %27, 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.ret129
}

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 = !{!"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