; LLVM IR from tangjz/acm-icpc :: codeforces/482B.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 [262144 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: 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 @_Z5queryiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %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 eq i32 %14, %15
  br i1 %16, label %17, label %26

17:                                               ; preds = %5
  %18 = load i32, ptr %11, align 4, !tbaa !5
  %19 = load i32, ptr %9, align 4, !tbaa !5
  %20 = icmp eq 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 %76

26:                                               ; preds = %17, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %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 %42

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

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

46:                                               ; preds = %42
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = shl i32 %47, 1
  %49 = add nsw i32 %48, 1
  %50 = load i32, ptr %12, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  %52 = load i32, ptr %9, align 4, !tbaa !5
  %53 = load i32, ptr %10, align 4, !tbaa !5
  %54 = load i32, ptr %11, align 4, !tbaa !5
  %55 = call noundef i32 @_Z5queryiiiii(i32 noundef %49, i32 noundef %51, i32 noundef %52, i32 noundef %53, i32 noundef %54)
  store i32 %55, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %75

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

75:                                               ; preds = %56, %46, %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  br label %76

76:                                               ; preds = %75, %21
  %77 = load i32, ptr %6, align 4
  ret i32 %77
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 nofree nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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 #0 {
  %6 = icmp eq i32 %3, %1
  %7 = icmp eq i32 %4, %2
  %or.cond505866 = and i1 %7, %6
  br i1 %or.cond505866, label %tailrecurse.outer42._crit_edge, label %.lr.ph.lr.ph

.lr.ph.lr.ph:                                     ; preds = %5, %tailrecurse.outer
  %8 = phi i1 [ true, %tailrecurse.outer ], [ %6, %5 ]
  %.tr40.ph71 = phi i32 [ %28, %tailrecurse.outer ], [ %3, %5 ]
  %.tr39.ph70 = phi i32 [ %.us-phi57, %tailrecurse.outer ], [ %2, %5 ]
  %.tr38.ph69 = phi i32 [ %28, %tailrecurse.outer ], [ %1, %5 ]
  %.tr.ph68 = phi i32 [ %27, %tailrecurse.outer ], [ %0, %5 ]
  %accumulator.tr.ph67 = phi i32 [ %29, %tailrecurse.outer ], [ -1, %5 ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.lr.ph, %tailrecurse.outer42
  %9 = phi i1 [ %8, %.lr.ph.lr.ph ], [ %24, %tailrecurse.outer42 ]
  %.tr39.ph4561 = phi i32 [ %.tr39.ph70, %.lr.ph.lr.ph ], [ %.us-phi57, %tailrecurse.outer42 ]
  %.tr38.ph4460 = phi i32 [ %.tr38.ph69, %.lr.ph.lr.ph ], [ %23, %tailrecurse.outer42 ]
  %.tr.ph4359 = phi i32 [ %.tr.ph68, %.lr.ph.lr.ph ], [ %22, %tailrecurse.outer42 ]
  br i1 %9, label %.lr.ph.split, label %tailrecurse.us

tailrecurse.us:                                   ; preds = %.lr.ph, %tailrecurse.us
  %.tr3952.us = phi i32 [ %11, %tailrecurse.us ], [ %.tr39.ph4561, %.lr.ph ]
  %.tr51.us = phi i32 [ %12, %tailrecurse.us ], [ %.tr.ph4359, %.lr.ph ]
  %10 = add i32 %.tr3952.us, %.tr38.ph4460
  %11 = ashr i32 %10, 1
  %.not.us = icmp slt i32 %11, %4
  %12 = shl i32 %.tr51.us, 1
  br i1 %.not.us, label %.split.us, label %tailrecurse.us

tailrecurse.outer42._crit_edge:                   ; preds = %tailrecurse.outer, %tailrecurse.outer42, %tailrecurse, %5
  %accumulator.tr.ph.lcssa = phi i32 [ -1, %5 ], [ %accumulator.tr.ph67, %tailrecurse ], [ %accumulator.tr.ph67, %tailrecurse.outer42 ], [ %29, %tailrecurse.outer ]
  %.tr.lcssa = phi i32 [ %0, %5 ], [ %18, %tailrecurse ], [ %22, %tailrecurse.outer42 ], [ %27, %tailrecurse.outer ]
  %13 = sext i32 %.tr.lcssa to i64
  %14 = getelementptr inbounds [262144 x i32], ptr @seg, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %accumulator.ret.tr = and i32 %15, %accumulator.tr.ph.lcssa
  ret i32 %accumulator.ret.tr

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %.tr3952 = phi i32 [ %17, %tailrecurse ], [ %.tr39.ph4561, %.lr.ph ]
  %.tr51 = phi i32 [ %18, %tailrecurse ], [ %.tr.ph4359, %.lr.ph ]
  %16 = add i32 %.tr3952, %.tr38.ph4460
  %17 = ashr i32 %16, 1
  %.not = icmp slt i32 %17, %4
  br i1 %.not, label %.split.us, label %tailrecurse

tailrecurse:                                      ; preds = %.lr.ph.split
  %18 = shl i32 %.tr51, 1
  %19 = icmp eq i32 %17, %4
  br i1 %19, label %tailrecurse.outer42._crit_edge, label %.lr.ph.split

.split.us:                                        ; preds = %tailrecurse.us, %.lr.ph.split
  %.us-phi = phi i32 [ %17, %.lr.ph.split ], [ %11, %tailrecurse.us ]
  %.us-phi56 = phi i32 [ %.tr51, %.lr.ph.split ], [ %.tr51.us, %tailrecurse.us ]
  %.us-phi57 = phi i32 [ %.tr3952, %.lr.ph.split ], [ %.tr3952.us, %tailrecurse.us ]
  %20 = icmp slt i32 %.us-phi, %.tr40.ph71
  %21 = shl i32 %.us-phi56, 1
  br i1 %20, label %tailrecurse.outer42, label %tailrecurse.outer

tailrecurse.outer42:                              ; preds = %.split.us
  %22 = or disjoint i32 %21, 1
  %23 = add nsw i32 %.us-phi, 1
  %24 = icmp eq i32 %.tr40.ph71, %23
  %25 = icmp eq i32 %.us-phi57, %4
  %or.cond50 = and i1 %25, %24
  br i1 %or.cond50, label %tailrecurse.outer42._crit_edge, label %.lr.ph

tailrecurse.outer:                                ; preds = %.split.us
  %26 = tail call noundef i32 @_Z5queryiiiii(i32 noundef %21, i32 noundef %.tr38.ph4460, i32 noundef %.us-phi, i32 noundef %.tr40.ph71, i32 noundef %.us-phi)
  %27 = or disjoint i32 %21, 1
  %28 = add nsw i32 %.us-phi, 1
  %29 = and i32 %26, %accumulator.tr.ph67
  %30 = icmp eq i32 %.us-phi57, %4
  br i1 %30, label %tailrecurse.outer42._crit_edge, label %.lr.ph.lr.ph
}

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass