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

; 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
@pL = 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_findLiiiiRi(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 %48

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 %42, 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 %41

38:                                               ; preds = %26
  %39 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %39, ptr @pL, align 4, !tbaa !5
  %40 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 2, ptr %40, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %38, %33
  br label %44

42:                                               ; preds = %22
  %43 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %43, ptr @pL, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %42, %41
  %45 = load ptr, ptr %10, align 8, !tbaa !9
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %45, align 4, !tbaa !5
  store i32 1, ptr %12, align 4
  br label %125

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

63:                                               ; preds = %48
  %64 = load i32, ptr %8, align 4, !tbaa !5
  %65 = load i32, ptr %13, align 4, !tbaa !5
  %66 = icmp sle i32 %64, %65
  br i1 %66, label %67, label %73

67:                                               ; preds = %63
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = load i32, ptr %13, align 4, !tbaa !5
  %70 = load i32, ptr %8, align 4, !tbaa !5
  %71 = load i32, ptr %9, align 4, !tbaa !5
  %72 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_Z9seg_findLiiiiRi(i32 noundef %68, i32 noundef %69, i32 noundef %70, i32 noundef %71, ptr noundef nonnull align 4 dereferenceable(4) %72)
  br label %85

73:                                               ; preds = %63
  %74 = load i32, ptr %13, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  %76 = load i32, ptr %7, align 4, !tbaa !5
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = load i32, ptr %9, align 4, !tbaa !5
  %79 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_Z9seg_findLiiiiRi(i32 noundef %75, i32 noundef %76, i32 noundef %77, i32 noundef %78, ptr noundef nonnull align 4 dereferenceable(4) %79)
  %80 = load i32, ptr %14, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [3300100 x i32], ptr @seg, i64 0, i64 %81
  %83 = 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) %82)
  %84 = load i32, ptr %83, align 4, !tbaa !5
  store i32 %84, ptr @pV, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %73, %67
  %86 = load ptr, ptr %10, align 8, !tbaa !9
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = icmp eq i32 %87, 1
  br i1 %88, label %89, label %102

89:                                               ; preds = %85
  %90 = load i32, ptr @pV, align 4, !tbaa !5
  %91 = load i32, ptr %9, align 4, !tbaa !5
  %92 = icmp slt i32 %90, %91
  br i1 %92, label %93, label %102

93:                                               ; preds = %89
  %94 = load ptr, ptr %10, align 8, !tbaa !9
  %95 = load i32, ptr %94, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %94, align 4, !tbaa !5
  %97 = load i32, ptr %6, align 4, !tbaa !5
  %98 = load i32, ptr %13, align 4, !tbaa !5
  %99 = load i32, ptr %8, align 4, !tbaa !5
  %100 = load i32, ptr %9, align 4, !tbaa !5
  %101 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_Z9seg_findLiiiiRi(i32 noundef %97, i32 noundef %98, i32 noundef %99, i32 noundef %100, ptr noundef nonnull align 4 dereferenceable(4) %101)
  br label %102

102:                                              ; preds = %93, %89, %85
  store i32 1, ptr %12, align 4
  br label %124

103:                                              ; preds = %48
  %104 = load i32, ptr %15, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [3300100 x i32], ptr @seg, i64 0, i64 %105
  %107 = load i32, ptr %106, align 4, !tbaa !5
  %108 = load i32, ptr %9, align 4, !tbaa !5
  %109 = icmp sge i32 %107, %108
  br i1 %109, label %110, label %116

110:                                              ; preds = %103
  %111 = load i32, ptr %6, align 4, !tbaa !5
  %112 = load i32, ptr %13, align 4, !tbaa !5
  %113 = load i32, ptr %8, align 4, !tbaa !5
  %114 = load i32, ptr %9, align 4, !tbaa !5
  %115 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_Z9seg_findLiiiiRi(i32 noundef %111, i32 noundef %112, i32 noundef %113, i32 noundef %114, ptr noundef nonnull align 4 dereferenceable(4) %115)
  br label %123

116:                                              ; preds = %103
  %117 = load i32, ptr %13, align 4, !tbaa !5
  %118 = add nsw i32 %117, 1
  %119 = load i32, ptr %7, align 4, !tbaa !5
  %120 = load i32, ptr %8, align 4, !tbaa !5
  %121 = load i32, ptr %9, align 4, !tbaa !5
  %122 = load ptr, ptr %10, align 8, !tbaa !9
  call void @_Z9seg_findLiiiiRi(i32 noundef %118, i32 noundef %119, i32 noundef %120, i32 noundef %121, ptr noundef nonnull align 4 dereferenceable(4) %122)
  br label %123

123:                                              ; preds = %116, %110
  store i32 0, ptr %12, align 4
  br label %124

124:                                              ; preds = %123, %102
  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 %125

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

127:                                              ; preds = %125, %125
  ret void

128:                                              ; preds = %125
  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
@pL = 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_findLiiiiRi(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
  %.tr64.ph84 = phi i32 [ %.tr64., %tailrecurse.outer ], [ %1, %5 ]
  %.tr.ph83 = phi i32 [ %..tr, %tailrecurse.outer ], [ %0, %5 ]
  br label %19

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %5
  %.tr.ph.lcssa78 = phi i32 [ %0, %5 ], [ %.tr.ph83, %tailrecurse ], [ %..tr, %tailrecurse.outer ]
  %.lcssa = phi i32 [ %6, %5 ], [ %38, %tailrecurse ], [ %43, %tailrecurse.outer ]
  %8 = load i32, ptr %4, align 4, !tbaa !5
  %.not61 = icmp eq i32 %8, 0
  br i1 %.not61, label %9, label %15

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
  %.not62 = icmp slt i32 %12, %3
  br i1 %.not62, label %14, label %13

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

14:                                               ; preds = %9
  store i32 %.tr.ph.lcssa78, ptr @pL, align 4, !tbaa !5
  store i32 2, ptr %4, align 4, !tbaa !5
  br label %16

15:                                               ; preds = %tailrecurse.outer._crit_edge
  store i32 %.tr.ph.lcssa78, ptr @pL, align 4, !tbaa !5
  br label %16

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

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

26:                                               ; preds = %19
  %.not59 = icmp slt i32 %21, %2
  br i1 %.not59, label %28, label %27

27:                                               ; preds = %26
  tail call void @_Z9seg_findLiiiiRi(i32 noundef %.tr.ph83, i32 noundef %21, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %.pre = load i32, ptr @pV, align 4
  br label %33

28:                                               ; preds = %26
  tail call void @_Z9seg_findLiiiiRi(i32 noundef %23, i32 noundef %.tr6479, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %29 = sext i32 %22 to i64
  %30 = getelementptr inbounds [3300100 x i32], ptr @seg, i64 0, i64 %29
  %31 = 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) %30)
  %32 = load i32, ptr %31, align 4, !tbaa !5
  store i32 %32, ptr @pV, align 4, !tbaa !5
  br label %33

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

tailrecurse:                                      ; preds = %33
  store i32 2, ptr %4, align 4, !tbaa !5
  %38 = tail call noundef i32 @_Z7seg_idxii(i32 noundef %.tr.ph83, i32 noundef %21)
  %39 = icmp eq i32 %.tr.ph83, %21
  br i1 %39, label %tailrecurse.outer._crit_edge, label %19

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

.loopexit:                                        ; preds = %33, %16
  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