; LLVM IR from tangjz/acm-icpc :: lydsy/2993.ll (Z7seg_queiiii)

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

%struct.Segment = type { [3 x i32], i32 }

@seg = external dso_local global [600003 x %struct.Segment], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z8seg_downR7SegmentS0_S0_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) #0

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) #2

; 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 @_Z7seg_queiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %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
  %12 = alloca i32, align 4
  %13 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = call noundef i32 @_Z7seg_idxii(i32 noundef %14, i32 noundef %15)
  store i32 %16, ptr %10, align 4, !tbaa !5
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !5
  %19 = icmp sle i32 %17, %18
  br i1 %19, label %20, label %29

20:                                               ; preds = %4
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = load i32, ptr %9, align 4, !tbaa !5
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %24, label %29

24:                                               ; preds = %20
  %25 = load i32, ptr %10, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %26
  %28 = call noundef i32 @_ZN7Segment5valueEv(ptr noundef nonnull align 4 dereferenceable(16) %27)
  store i32 %28, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %74

29:                                               ; preds = %20, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = load i32, ptr %7, align 4, !tbaa !5
  %32 = add nsw i32 %30, %31
  %33 = ashr i32 %32, 1
  store i32 %33, ptr %13, align 4, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %35
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = load i32, ptr %13, align 4, !tbaa !5
  %39 = call noundef i32 @_Z7seg_idxii(i32 noundef %37, i32 noundef %38)
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %40
  %42 = load i32, ptr %13, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = call noundef i32 @_Z7seg_idxii(i32 noundef %43, i32 noundef %44)
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %46
  call void @_Z8seg_downR7SegmentS0_S0_(ptr noundef nonnull align 4 dereferenceable(16) %36, ptr noundef nonnull align 4 dereferenceable(16) %41, ptr noundef nonnull align 4 dereferenceable(16) %47)
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = load i32, ptr %13, align 4, !tbaa !5
  %50 = icmp sle i32 %48, %49
  br i1 %50, label %51, label %59

51:                                               ; preds = %29
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = load i32, ptr %13, align 4, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = call noundef i32 @_Z7seg_queiiii(i32 noundef %52, i32 noundef %53, i32 noundef %54, i32 noundef %55)
  %57 = load i32, ptr %12, align 4, !tbaa !5
  %58 = xor i32 %57, %56
  store i32 %58, ptr %12, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %51, %29
  %60 = load i32, ptr %9, align 4, !tbaa !5
  %61 = load i32, ptr %13, align 4, !tbaa !5
  %62 = icmp sgt i32 %60, %61
  br i1 %62, label %63, label %72

63:                                               ; preds = %59
  %64 = load i32, ptr %13, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = load i32, ptr %9, align 4, !tbaa !5
  %69 = call noundef i32 @_Z7seg_queiiii(i32 noundef %65, i32 noundef %66, i32 noundef %67, i32 noundef %68)
  %70 = load i32, ptr %12, align 4, !tbaa !5
  %71 = xor i32 %70, %69
  store i32 %71, ptr %12, align 4, !tbaa !5
  br label %72

72:                                               ; preds = %63, %59
  %73 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %73, ptr %5, align 4
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %74

74:                                               ; preds = %72, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %75 = load i32, ptr %5, align 4
  ret i32 %75
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7Segment5valueEv(ptr noundef nonnull align 4 dereferenceable(16)) #3 align 2

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

%struct.Segment = type { [3 x i32], i32 }

@seg = external dso_local global [600003 x %struct.Segment], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z8seg_downR7SegmentS0_S0_(ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z7seg_queiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %1)
  %.not42 = icmp sgt i32 %2, %0
  %.not34 = icmp sgt i32 %1, %3
  %or.cond43 = or i1 %.not34, %.not42
  br i1 %or.cond43, label %.lr.ph, label %tailrecurse._crit_edge

.lr.ph:                                           ; preds = %4
  br i1 %.not34, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %tailrecurse.us
  %6 = phi i32 [ %23, %tailrecurse.us ], [ %5, %.lr.ph ]
  %.tr45.us = phi i32 [ %14, %tailrecurse.us ], [ %0, %.lr.ph ]
  %accumulator.tr44.us = phi i32 [ %22, %tailrecurse.us ], [ 0, %.lr.ph ]
  %7 = add nsw i32 %.tr45.us, %1
  %8 = ashr i32 %7, 1
  %9 = sext i32 %6 to i64
  %10 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %9
  %11 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %.tr45.us, i32 noundef %8)
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %12
  %14 = add nsw i32 %8, 1
  %15 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %14, i32 noundef %1)
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %16
  tail call void @_Z8seg_downR7SegmentS0_S0_(ptr noundef nonnull align 4 dereferenceable(16) %10, ptr noundef nonnull align 4 dereferenceable(16) %13, ptr noundef nonnull align 4 dereferenceable(16) %17)
  %.not35.us = icmp slt i32 %8, %2
  br i1 %.not35.us, label %20, label %18

18:                                               ; preds = %.lr.ph.split.us
  %19 = tail call noundef i32 @_Z7seg_queiiii(i32 noundef %.tr45.us, i32 noundef %8, i32 noundef %2, i32 noundef %3)
  br label %20

20:                                               ; preds = %18, %.lr.ph.split.us
  %.030.us = phi i32 [ %19, %18 ], [ 0, %.lr.ph.split.us ]
  %21 = icmp slt i32 %8, %3
  br i1 %21, label %tailrecurse.us, label %.loopexit

tailrecurse.us:                                   ; preds = %20
  %22 = xor i32 %.030.us, %accumulator.tr44.us
  %23 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %14, i32 noundef %1)
  br label %.lr.ph.split.us

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %4
  %accumulator.tr.lcssa = phi i32 [ 0, %4 ], [ %43, %tailrecurse ]
  %.lcssa = phi i32 [ %5, %4 ], [ %44, %tailrecurse ]
  %24 = sext i32 %.lcssa to i64
  %25 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %24
  %26 = tail call noundef i32 @_ZN7Segment5valueEv(ptr noundef nonnull align 4 dereferenceable(16) %25)
  br label %.loopexit

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse
  %27 = phi i32 [ %44, %tailrecurse ], [ %5, %.lr.ph ]
  %.tr45 = phi i32 [ %35, %tailrecurse ], [ %0, %.lr.ph ]
  %accumulator.tr44 = phi i32 [ %43, %tailrecurse ], [ 0, %.lr.ph ]
  %28 = add nsw i32 %.tr45, %1
  %29 = ashr i32 %28, 1
  %30 = sext i32 %27 to i64
  %31 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %30
  %32 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %.tr45, i32 noundef %29)
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %33
  %35 = add nsw i32 %29, 1
  %36 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %35, i32 noundef %1)
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [600003 x %struct.Segment], ptr @seg, i64 0, i64 %37
  tail call void @_Z8seg_downR7SegmentS0_S0_(ptr noundef nonnull align 4 dereferenceable(16) %31, ptr noundef nonnull align 4 dereferenceable(16) %34, ptr noundef nonnull align 4 dereferenceable(16) %38)
  %.not35 = icmp slt i32 %29, %2
  br i1 %.not35, label %41, label %39

39:                                               ; preds = %.lr.ph.split
  %40 = tail call noundef i32 @_Z7seg_queiiii(i32 noundef %.tr45, i32 noundef %29, i32 noundef %2, i32 noundef %3)
  br label %41

41:                                               ; preds = %39, %.lr.ph.split
  %.030 = phi i32 [ %40, %39 ], [ 0, %.lr.ph.split ]
  %42 = icmp slt i32 %29, %3
  br i1 %42, label %tailrecurse, label %.loopexit

tailrecurse:                                      ; preds = %41
  %43 = xor i32 %.030, %accumulator.tr44
  %44 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %35, i32 noundef %1)
  %.not = icmp slt i32 %35, %2
  br i1 %.not, label %.lr.ph.split, label %tailrecurse._crit_edge

.loopexit:                                        ; preds = %41, %20, %tailrecurse._crit_edge
  %accumulator.tr41 = phi i32 [ %accumulator.tr.lcssa, %tailrecurse._crit_edge ], [ %accumulator.tr44.us, %20 ], [ %accumulator.tr44, %41 ]
  %.0 = phi i32 [ %26, %tailrecurse._crit_edge ], [ %.030.us, %20 ], [ %.030, %41 ]
  %accumulator.ret.tr = xor i32 %.0, %accumulator.tr41
  ret i32 %accumulator.ret.tr
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7Segment5valueEv(ptr noundef nonnull align 4 dereferenceable(16)) local_unnamed_addr #2 align 2

attributes #0 = { 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 #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" }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass