; LLVM IR from tangjz/acm-icpc :: lydsy/1039.ll (Z9seg_findRiiiiRi)

; 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 [3300100 x i32], align 16
@pR = external dso_local global i32, align 4
@pV = external dso_local global i32, align 4

; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) #1

; 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: mustprogress uwtable
define dso_local void @_Z9seg_findRiiiiRi(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 4 dereferenceable(4) %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %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 %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
  store ptr %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = call noundef i32 @_Z7seg_idxii(i32 noundef %16, i32 noundef %17)
  store i32 %18, ptr %11, align 4, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = icmp eq i32 %19, %20
  br i1 %21, label %22, label %50

22:                                               ; preds = %5
  %23 = load ptr, ptr %10, align 8, !tbaa !9
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %43, label %26

26:                                               ; preds = %22
  %27 = load i32, ptr %11, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [3300100 x i32], ptr @seg, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = icmp sge i32 %30, %31
  br i1 %32, label %33, label %38

33:                                               ; preds = %26
  %34 = load i32, ptr %11, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [3300100 x i32], ptr @seg, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  store i32 %37, ptr @pV, align 4, !tbaa !5
  br label %42

38:                                               ; preds = %26
  %39 = load i32, ptr %7, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  store i32 %40, ptr @pR, align 4, !tbaa !5
  %41 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 2, ptr %41, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %38, %33
  br label %46

43:                                               ; preds = %22
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = sub nsw i32 %44, 1
  store i32 %45, ptr @pR, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %43, %42
  %47 = load ptr, ptr %10, align 8, !tbaa !9
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %47, align 4, !tbaa !5
  store i32 1, ptr %12, align 4
  br label %128

50:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %51 = load i32, ptr %6, align 4, !tbaa !5
  %52 = load i32, ptr %7, align 4, !tbaa !5
  %53 = add nsw i32 %51, %52
  %54 = ashr i32 %53, 1
  store i32 %54, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = load i32, ptr %13, align 4, !tbaa !5
  %57 = call noundef i32 @_Z7seg_idxii(i32 noundef %55, i32 noundef %56)
  store i32 %57, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %58 = load i32, ptr %13, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = call noundef i32 @_Z7seg_idxii(i32 noundef %59, i32 noundef %60)
  store i32 %61, ptr %15, align 4, !tbaa !5
  %62 = load ptr, ptr %10, align 8, !tbaa !9
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %106, label %65

65:                                               ; preds = %50
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = load i32, ptr %13, align 4, !tbaa !5
  %68 = icmp sle i32 %66, %67
  br i1 %68, label %69, label %80

69:                                               ; preds = %65
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = load i32, ptr %13, align 4, !tbaa !5
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = load i32, ptr %9, align 4, !tbaa !5
  %74 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_Z9seg_findRiiiiRi(i32 noundef %70, i32 noundef %71, i32 noundef %72, i32 noundef %73, ptr noundef nonnull align 4 dereferenceable(4) %74)
  %75 = load i32, ptr %15, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [3300100 x i32], ptr @seg, i64 0, i64 %76
  %78 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @pV, ptr noundef nonnull align 4 dereferenceable(4) %77)
  %79 = load i32, ptr %78, align 4, !tbaa !5
  store i32 %79, ptr @pV, align 4, !tbaa !5
  br label %87

80:                                               ; preds = %65
  %81 = load i32, ptr %13, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  %83 = load i32, ptr %7, align 4, !tbaa !5
  %84 = load i32, ptr %8, align 4, !tbaa !5
  %85 = load i32, ptr %9, align 4, !tbaa !5
  %86 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_Z9seg_findRiiiiRi(i32 noundef %82, i32 noundef %83, i32 noundef %84, i32 noundef %85, ptr noundef nonnull align 4 dereferenceable(4) %86)
  br label %87

87:                                               ; preds = %80, %69
  %88 = load ptr, ptr %10, align 8, !tbaa !9
  %89 = load i32, ptr %88, align 4, !tbaa !5
  %90 = icmp eq i32 %89, 1
  br i1 %90, label %91, label %105

91:                                               ; preds = %87
  %92 = load i32, ptr @pV, align 4, !tbaa !5
  %93 = load i32, ptr %9, align 4, !tbaa !5
  %94 = icmp slt i32 %92, %93
  br i1 %94, label %95, label %105

95:                                               ; preds = %91
  %96 = load ptr, ptr %10, align 8, !tbaa !9
  %97 = load i32, ptr %96, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %96, align 4, !tbaa !5
  %99 = load i32, ptr %13, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  %101 = load i32, ptr %7, align 4, !tbaa !5
  %102 = load i32, ptr %8, align 4, !tbaa !5
  %103 = load i32, ptr %9, align 4, !tbaa !5
  %104 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_Z9seg_findRiiiiRi(i32 noundef %100, i32 noundef %101, i32 noundef %102, i32 noundef %103, ptr noundef nonnull align 4 dereferenceable(4) %104)
  br label %105

105:                                              ; preds = %95, %91, %87
  store i32 1, ptr %12, align 4
  br label %127

106:                                              ; preds = %50
  %107 = load i32, ptr %14, align 4, !tbaa !5
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [3300100 x i32], ptr @seg, i64 0, i64 %108
  %110 = load i32, ptr %109, align 4, !tbaa !5
  %111 = load i32, ptr %9, align 4, !tbaa !5
  %112 = icmp slt i32 %110, %111
  br i1 %112, label %113, label %119

113:                                              ; preds = %106
  %114 = load i32, ptr %6, align 4, !tbaa !5
  %115 = load i32, ptr %13, align 4, !tbaa !5
  %116 = load i32, ptr %8, align 4, !tbaa !5
  %117 = load i32, ptr %9, align 4, !tbaa !5
  %118 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_Z9seg_findRiiiiRi(i32 noundef %114, i32 noundef %115, i32 noundef %116, i32 noundef %117, ptr noundef nonnull align 4 dereferenceable(4) %118)
  br label %126

119:                                              ; preds = %106
  %120 = load i32, ptr %13, align 4, !tbaa !5
  %121 = add nsw i32 %120, 1
  %122 = load i32, ptr %7, align 4, !tbaa !5
  %123 = load i32, ptr %8, align 4, !tbaa !5
  %124 = load i32, ptr %9, align 4, !tbaa !5
  %125 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_Z9seg_findRiiiiRi(i32 noundef %121, i32 noundef %122, i32 noundef %123, i32 noundef %124, ptr noundef nonnull align 4 dereferenceable(4) %125)
  br label %126

126:                                              ; preds = %119, %113
  store i32 0, ptr %12, align 4
  br label %127

127:                                              ; preds = %126, %105
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %128

128:                                              ; preds = %127, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %129 = load i32, ptr %12, align 4
  switch i32 %129, label %131 [
    i32 0, label %130
    i32 1, label %130
  ]

130:                                              ; preds = %128, %128
  ret void

131:                                              ; preds = %128
  unreachable
}

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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


; 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 [3300100 x i32], align 16
@pR = external dso_local local_unnamed_addr global i32, align 4
@pV = external dso_local global i32, align 4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7seg_idxii(i32 noundef, i32 noundef) local_unnamed_addr #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 #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z9seg_findRiiiiRi(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 4 dereferenceable(4) %4) local_unnamed_addr #1 {
  %6 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %0, i32 noundef %1)
  %7 = icmp eq i32 %0, %1
  br i1 %7, label %tailrecurse.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %tailrecurse.outer
  %.tr63.ph83 = phi i32 [ %..tr63, %tailrecurse.outer ], [ %1, %5 ]
  %.tr.ph82 = phi i32 [ %.tr., %tailrecurse.outer ], [ %0, %5 ]
  br label %21

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %5
  %.tr63.ph.lcssa77 = phi i32 [ %0, %5 ], [ %.tr63.ph83, %tailrecurse ], [ %.tr., %tailrecurse.outer ]
  %.lcssa = phi i32 [ %6, %5 ], [ %40, %tailrecurse ], [ %46, %tailrecurse.outer ]
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %.not60 = icmp eq i32 %8, 0
  br i1 %.not60, label %9, label %16

9:                                                ; preds = %tailrecurse.outer._crit_edge
  %10 = sext i32 %.lcssa to i64
  %11 = getelementptr inbounds [3300100 x i32], ptr @seg, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %.not61 = icmp slt i32 %12, %3
  br i1 %.not61, label %14, label %13

13:                                               ; preds = %9
  store i32 %12, ptr @pV, align 4, !tbaa !5
  br label %18

14:                                               ; preds = %9
  %15 = add nsw i32 %.tr63.ph.lcssa77, -1
  store i32 %15, ptr @pR, align 4, !tbaa !5
  store i32 2, ptr %4, align 4, !tbaa !5
  br label %18

16:                                               ; preds = %tailrecurse.outer._crit_edge
  %17 = add nsw i32 %.tr63.ph.lcssa77, -1
  store i32 %17, ptr @pR, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %13, %14, %16
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %4, align 4, !tbaa !5
  br label %.loopexit

21:                                               ; preds = %.lr.ph, %tailrecurse
  %.tr78 = phi i32 [ %.tr.ph82, %.lr.ph ], [ %25, %tailrecurse ]
  %22 = add nsw i32 %.tr63.ph83, %.tr78
  %23 = ashr i32 %22, 1
  %24 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %.tr78, i32 noundef %23)
  %25 = add nsw i32 %23, 1
  %26 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %25, i32 noundef %.tr63.ph83)
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp eq i32 %27, 0
  br i1 %.not, label %28, label %tailrecurse.outer

28:                                               ; preds = %21
  %.not59 = icmp slt i32 %23, %2
  br i1 %.not59, label %34, label %29

29:                                               ; preds = %28
  tail call void @_Z9seg_findRiiiiRi(i32 noundef %.tr78, i32 noundef %23, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %30 = sext i32 %26 to i64
  %31 = getelementptr inbounds [3300100 x i32], ptr @seg, i64 0, i64 %30
  %32 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @pV, ptr noundef nonnull align 4 dereferenceable(4) %31)
  %33 = load i32, ptr %32, align 4, !tbaa !5
  store i32 %33, ptr @pV, align 4, !tbaa !5
  br label %35

34:                                               ; preds = %28
  tail call void @_Z9seg_findRiiiiRi(i32 noundef %25, i32 noundef %.tr63.ph83, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %.pre = load i32, ptr @pV, align 4
  br label %35

35:                                               ; preds = %34, %29
  %36 = phi i32 [ %.pre, %34 ], [ %33, %29 ]
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = icmp eq i32 %37, 1
  %39 = icmp slt i32 %36, %3
  %or.cond = select i1 %38, i1 %39, i1 false
  br i1 %or.cond, label %tailrecurse, label %.loopexit

tailrecurse:                                      ; preds = %35
  store i32 2, ptr %4, align 4, !tbaa !5
  %40 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %25, i32 noundef %.tr63.ph83)
  %41 = icmp eq i32 %25, %.tr63.ph83
  br i1 %41, label %tailrecurse.outer._crit_edge, label %21

tailrecurse.outer:                                ; preds = %21
  %42 = sext i32 %24 to i64
  %43 = getelementptr inbounds [3300100 x i32], ptr @seg, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = icmp slt i32 %44, %3
  %.tr. = select i1 %45, i32 %.tr78, i32 %25
  %..tr63 = select i1 %45, i32 %23, i32 %.tr63.ph83
  %46 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %.tr., i32 noundef %..tr63)
  %47 = icmp eq i32 %.tr., %..tr63
  br i1 %47, label %tailrecurse.outer._crit_edge, label %.lr.ph

.loopexit:                                        ; preds = %35, %18
  ret void
}

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