; LLVM IR from tangjz/acm-icpc :: codeforces/complete/936E.ll (Z8tree_updi)

; 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.std::pair" = type { i32, i32 }

@pre = external dso_local global [300001 x i32], align 16
@suf = external dso_local global [300001 x i32], align 16
@idx = external dso_local global [19 x [300001 x i32]], align 16
@seg = external dso_local global [300001 x %"struct.std::pair"], align 16
@dis = external dso_local global [19 x [300001 x %"struct.std::pair"]], 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 void @_Z8tree_updi(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %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
  %14 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %137, %1
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 19
  br i1 %17, label %18, label %27

18:                                               ; preds = %15
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [19 x [300001 x i32]], ptr @idx, i64 0, i64 %20
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [300001 x i32], ptr %21, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = icmp ne i32 %25, 0
  br label %27

27:                                               ; preds = %18, %15
  %28 = phi i1 [ false, %15 ], [ %26, %18 ]
  br i1 %28, label %30, label %29

29:                                               ; preds = %27
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %140

30:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [19 x [300001 x i32]], ptr @idx, i64 0, i64 %32
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [300001 x i32], ptr %33, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  store i32 %37, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [300001 x %"struct.std::pair"], ptr @seg, i64 0, i64 %39
  %41 = getelementptr inbounds %"struct.std::pair", ptr %40, i32 0, i32 1
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [300001 x %"struct.std::pair"], ptr @seg, i64 0, i64 %44
  %46 = getelementptr inbounds %"struct.std::pair", ptr %45, i32 0, i32 0
  %47 = load i32, ptr %46, align 8, !tbaa !11
  %48 = sub nsw i32 %42, %47
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [300001 x %"struct.std::pair"], ptr @seg, i64 0, i64 %51
  %53 = getelementptr inbounds %"struct.std::pair", ptr %52, i32 0, i32 0
  %54 = load i32, ptr %53, align 8, !tbaa !11
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr @pre, i64 %55
  %57 = getelementptr inbounds i32, ptr %56, i64 -1
  store ptr %57, ptr %7, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [300001 x %"struct.std::pair"], ptr @seg, i64 0, i64 %59
  %61 = getelementptr inbounds %"struct.std::pair", ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !11
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr @suf, i64 %63
  %65 = getelementptr inbounds i32, ptr %64, i64 -1
  store ptr %65, ptr %8, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %66 = load i32, ptr %3, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [19 x [300001 x %"struct.std::pair"]], ptr @dis, i64 0, i64 %67
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [300001 x %"struct.std::pair"], ptr %68, i64 0, i64 %70
  %72 = getelementptr inbounds %"struct.std::pair", ptr %71, i32 0, i32 0
  %73 = load i32, ptr %72, align 8, !tbaa !11
  store i32 %73, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %74 = load i32, ptr %3, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [19 x [300001 x %"struct.std::pair"]], ptr @dis, i64 0, i64 %75
  %77 = load i32, ptr %2, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [300001 x %"struct.std::pair"], ptr %76, i64 0, i64 %78
  %80 = getelementptr inbounds %"struct.std::pair", ptr %79, i32 0, i32 1
  %81 = load i32, ptr %80, align 4, !tbaa !9
  store i32 %81, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %82 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %82, ptr %11, align 4, !tbaa !5
  br label %83

83:                                               ; preds = %102, %30
  %84 = load i32, ptr %11, align 4, !tbaa !5
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = icmp sle i32 %84, %85
  br i1 %86, label %88, label %87

87:                                               ; preds = %83
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %109

88:                                               ; preds = %83
  %89 = load ptr, ptr %7, align 8, !tbaa !12
  %90 = load i32, ptr %11, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds i32, ptr %89, i64 %91
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %93 = load i32, ptr %9, align 4, !tbaa !5
  %94 = load i32, ptr %10, align 4, !tbaa !5
  %95 = sub nsw i32 %93, %94
  store i32 %95, ptr %12, align 4, !tbaa !5
  %96 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %92, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %97 = load i32, ptr %96, align 4, !tbaa !5
  %98 = load ptr, ptr %7, align 8, !tbaa !12
  %99 = load i32, ptr %11, align 4, !tbaa !5
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds i32, ptr %98, i64 %100
  store i32 %97, ptr %101, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %102

102:                                              ; preds = %88
  %103 = load i32, ptr %11, align 4, !tbaa !5
  %104 = load i32, ptr %11, align 4, !tbaa !5
  %105 = sub nsw i32 0, %104
  %106 = and i32 %103, %105
  %107 = load i32, ptr %11, align 4, !tbaa !5
  %108 = add nsw i32 %107, %106
  store i32 %108, ptr %11, align 4, !tbaa !5
  br label %83, !llvm.loop !14

109:                                              ; preds = %87
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %110 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %110, ptr %13, align 4, !tbaa !5
  br label %111

111:                                              ; preds = %129, %109
  %112 = load i32, ptr %13, align 4, !tbaa !5
  %113 = icmp sgt i32 %112, 0
  br i1 %113, label %115, label %114

114:                                              ; preds = %111
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %136

115:                                              ; preds = %111
  %116 = load ptr, ptr %8, align 8, !tbaa !12
  %117 = load i32, ptr %13, align 4, !tbaa !5
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds i32, ptr %116, i64 %118
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %120 = load i32, ptr %9, align 4, !tbaa !5
  %121 = load i32, ptr %10, align 4, !tbaa !5
  %122 = add nsw i32 %120, %121
  store i32 %122, ptr %14, align 4, !tbaa !5
  %123 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %119, ptr noundef nonnull align 4 dereferenceable(4) %14)
  %124 = load i32, ptr %123, align 4, !tbaa !5
  %125 = load ptr, ptr %8, align 8, !tbaa !12
  %126 = load i32, ptr %13, align 4, !tbaa !5
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds i32, ptr %125, i64 %127
  store i32 %124, ptr %128, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %129

129:                                              ; preds = %115
  %130 = load i32, ptr %13, align 4, !tbaa !5
  %131 = load i32, ptr %13, align 4, !tbaa !5
  %132 = sub nsw i32 0, %131
  %133 = and i32 %130, %132
  %134 = load i32, ptr %13, align 4, !tbaa !5
  %135 = sub nsw i32 %134, %133
  store i32 %135, ptr %13, align 4, !tbaa !5
  br label %111, !llvm.loop !16

136:                                              ; preds = %114
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %137

137:                                              ; preds = %136
  %138 = load i32, ptr %3, align 4, !tbaa !5
  %139 = add nsw i32 %138, 1
  store i32 %139, ptr %3, align 4, !tbaa !5
  br label %15, !llvm.loop !17

140:                                              ; preds = %29
  ret void
}

; 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)) #2

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 = { 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 = { 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, !6, i64 4}
!10 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = distinct !{!17, !15}


; 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.std::pair" = type { i32, i32 }

@pre = external dso_local global [300001 x i32], align 16
@suf = external dso_local global [300001 x i32], align 16
@idx = external dso_local local_unnamed_addr global [19 x [300001 x i32]], align 16
@seg = external dso_local local_unnamed_addr global [300001 x %"struct.std::pair"], align 16
@dis = external dso_local local_unnamed_addr global [19 x [300001 x %"struct.std::pair"]], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8tree_updi(i32 noundef %0) local_unnamed_addr #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = sext i32 %0 to i64
  br label %5

5:                                                ; preds = %1, %._crit_edge
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %._crit_edge ]
  %6 = getelementptr inbounds [19 x [300001 x i32]], ptr @idx, i64 0, i64 %indvars.iv, i64 %4
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %.critedge, label %8

.critedge:                                        ; preds = %._crit_edge, %5
  ret void

8:                                                ; preds = %5
  %9 = sext i32 %7 to i64
  %10 = getelementptr inbounds [300001 x %"struct.std::pair"], ptr @seg, i64 0, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = load i32, ptr %10, align 8, !tbaa !11
  %14 = add i32 %12, 1
  %15 = sub i32 %14, %13
  %16 = sext i32 %13 to i64
  %gep = getelementptr i32, ptr getelementptr (i8, ptr @pre, i64 -4), i64 %16
  %gep45 = getelementptr i32, ptr getelementptr (i8, ptr @suf, i64 -4), i64 %16
  %17 = getelementptr inbounds [19 x [300001 x %"struct.std::pair"]], ptr @dis, i64 0, i64 %indvars.iv, i64 %4
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %17, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %.not3941 = icmp sgt i32 %20, %15
  br i1 %.not3941, label %.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %8
  %21 = sub nsw i32 %18, %20
  br label %24

.preheader:                                       ; preds = %24, %8
  %22 = icmp sgt i32 %20, 0
  br i1 %22, label %.lr.ph44, label %._crit_edge

.lr.ph44:                                         ; preds = %.preheader
  %23 = add nsw i32 %20, %18
  br label %32

24:                                               ; preds = %.lr.ph, %24
  %.03642 = phi i32 [ %20, %.lr.ph ], [ %31, %24 ]
  %25 = sext i32 %.03642 to i64
  %26 = getelementptr inbounds i32, ptr %gep, i64 %25
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  store i32 %21, ptr %2, align 4, !tbaa !5
  %27 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %26, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %28 = load i32, ptr %27, align 4, !tbaa !5
  store i32 %28, ptr %26, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  %29 = sub nsw i32 0, %.03642
  %30 = and i32 %.03642, %29
  %31 = add nsw i32 %30, %.03642
  %.not39 = icmp sgt i32 %31, %15
  br i1 %.not39, label %.preheader, label %24, !llvm.loop !12

._crit_edge:                                      ; preds = %32, %.preheader
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 19
  br i1 %exitcond.not, label %.critedge, label %5, !llvm.loop !14

32:                                               ; preds = %.lr.ph44, %32
  %.043 = phi i32 [ %20, %.lr.ph44 ], [ %37, %32 ]
  %33 = zext nneg i32 %.043 to i64
  %34 = getelementptr inbounds i32, ptr %gep45, i64 %33
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  store i32 %23, ptr %3, align 4, !tbaa !5
  %35 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %34, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %36 = load i32, ptr %35, align 4, !tbaa !5
  store i32 %36, ptr %34, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  %.not40 = add nsw i32 %.043, -1
  %37 = and i32 %.not40, %.043
  %.not48 = icmp eq i32 %37, 0
  br i1 %.not48, label %._crit_edge, label %32, !llvm.loop !15
}

; 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 #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = { 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, !6, i64 4}
!10 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!11 = !{!10, !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass