; LLVM IR from tangjz/acm-icpc :: lydsy/3306.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 [262144 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3minii(i32 noundef, i32 noundef) #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 @_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
  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
  %14 = load i32, ptr %10, align 4, !tbaa !5
  %15 = load i32, ptr %8, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %17, label %26

17:                                               ; preds = %5
  %18 = load i32, ptr %9, align 4, !tbaa !5
  %19 = load i32, ptr %11, align 4, !tbaa !5
  %20 = icmp sle i32 %18, %19
  br i1 %20, label %21, label %26

21:                                               ; preds = %17
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [262144 x i32], ptr @seg, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  store i32 %25, ptr %6, align 4
  br label %79

26:                                               ; preds = %17, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = add nsw i32 %27, %28
  %30 = ashr i32 %29, 1
  store i32 %30, ptr %12, align 4, !tbaa !5
  %31 = load i32, ptr %11, align 4, !tbaa !5
  %32 = load i32, ptr %12, align 4, !tbaa !5
  %33 = icmp sle i32 %31, %32
  br i1 %33, label %34, label %43

34:                                               ; preds = %26
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = add nsw i32 %35, %36
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = load i32, ptr %12, align 4, !tbaa !5
  %40 = load i32, ptr %10, align 4, !tbaa !5
  %41 = load i32, ptr %11, align 4, !tbaa !5
  %42 = call noundef i32 @_Z3queiiiii(i32 noundef %37, i32 noundef %38, i32 noundef %39, i32 noundef %40, i32 noundef %41)
  store i32 %42, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %78

43:                                               ; preds = %26
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = load i32, ptr %12, align 4, !tbaa !5
  %46 = icmp sgt i32 %44, %45
  br i1 %46, label %47, label %58

47:                                               ; preds = %43
  %48 = load i32, ptr %7, align 4, !tbaa !5
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = add nsw i32 %48, %49
  %51 = add nsw i32 %50, 1
  %52 = load i32, ptr %12, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  %54 = load i32, ptr %9, 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 i32 @_Z3queiiiii(i32 noundef %51, i32 noundef %53, i32 noundef %54, i32 noundef %55, i32 noundef %56)
  store i32 %57, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %78

58:                                               ; preds = %43
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = add nsw i32 %59, %60
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = load i32, ptr %12, align 4, !tbaa !5
  %64 = load i32, ptr %10, align 4, !tbaa !5
  %65 = load i32, ptr %11, align 4, !tbaa !5
  %66 = call noundef i32 @_Z3queiiiii(i32 noundef %61, i32 noundef %62, i32 noundef %63, i32 noundef %64, i32 noundef %65)
  %67 = load i32, ptr %7, align 4, !tbaa !5
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = add nsw i32 %67, %68
  %70 = add nsw i32 %69, 1
  %71 = load i32, ptr %12, align 4, !tbaa !5
  %72 = add nsw i32 %71, 1
  %73 = load i32, ptr %9, align 4, !tbaa !5
  %74 = load i32, ptr %10, align 4, !tbaa !5
  %75 = load i32, ptr %11, align 4, !tbaa !5
  %76 = call noundef i32 @_Z3queiiiii(i32 noundef %70, i32 noundef %72, i32 noundef %73, i32 noundef %74, i32 noundef %75)
  %77 = call noundef i32 @_Z3minii(i32 noundef %66, i32 noundef %76)
  store i32 %77, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %78

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

79:                                               ; preds = %78, %21
  %80 = load i32, ptr %6, align 4
  ret i32 %80
}

attributes #0 = { 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 [262144 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3minii(i32 noundef, i32 noundef) local_unnamed_addr #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 #0 {
  %.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 [ %18, %tailrecurse.outer ], [ %1, %5 ]
  %.tr.ph61 = phi i32 [ %17, %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 [ %7, %tailrecurse.us ], [ %.tr45.ph63, %.lr.ph ]
  %.tr53.us = phi i32 [ %8, %tailrecurse.us ], [ %.tr.ph61, %.lr.ph ]
  %6 = add i32 %.tr4554.us, %.tr44.ph62
  %7 = ashr i32 %6, 1
  %.not43.us = icmp slt i32 %7, %4
  %8 = 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 ], [ %14, %tailrecurse ], [ %17, %tailrecurse.outer ]
  %9 = sext i32 %.tr.lcssa to i64
  %10 = getelementptr inbounds [262144 x i32], ptr @seg, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  br label %common.ret131

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

tailrecurse:                                      ; preds = %.lr.ph.split
  %14 = shl nsw i32 %.tr53, 1
  %.not42 = icmp sgt i32 %13, %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 [ %7, %tailrecurse.us ], [ %13, %.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 ]
  %15 = icmp slt i32 %.us-phi, %3
  %16 = shl nsw i32 %.us-phi56, 1
  br i1 %15, label %tailrecurse.outer, label %19

tailrecurse.outer:                                ; preds = %.split.us
  %17 = or disjoint i32 %16, 1
  %18 = add nsw i32 %.us-phi, 1
  %.not = icmp slt i32 %18, %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.ret131:                                    ; preds = %19, %tailrecurse.outer._crit_edge
  %common.ret131.op = phi i32 [ %11, %tailrecurse.outer._crit_edge ], [ %24, %19 ]
  ret i32 %common.ret131.op

19:                                               ; preds = %.split.us
  %20 = tail call noundef i32 @_Z3queiiiii(i32 noundef %16, i32 noundef %.tr44.ph62, i32 noundef %.us-phi, i32 noundef %3, i32 noundef %4)
  %21 = or disjoint i32 %16, 1
  %22 = add nsw i32 %.us-phi, 1
  %23 = tail call noundef i32 @_Z3queiiiii(i32 noundef %21, i32 noundef %22, i32 noundef %.us-phi57, i32 noundef %3, i32 noundef %4)
  %24 = tail call noundef i32 @_Z3minii(i32 noundef %20, i32 noundef %23)
  br label %common.ret131
}

attributes #0 = { 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: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass