; LLVM IR from tangjz/acm-icpc :: lydsy/4299.ll (Z7seg_updRiiii)

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

@que = external dso_local global [100001 x i32], align 16
@stot = external dso_local global i32, align 4
@lch = external dso_local global [1700017 x i32], align 16
@rch = external dso_local global [1700017 x i32], align 16
@sum = external dso_local global [1700017 x i32], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7seg_updRiiii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %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
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %13, ptr %9, align 4, !tbaa !9
  %14 = load i32, ptr @stot, align 4, !tbaa !9
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr @stot, align 4, !tbaa !9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %15, ptr %16, align 4, !tbaa !9
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1700017 x i32], ptr @lch, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [1700017 x i32], ptr @lch, i64 0, i64 %23
  store i32 %20, ptr %24, align 4, !tbaa !9
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [1700017 x i32], ptr @rch, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1700017 x i32], ptr @rch, i64 0, i64 %31
  store i32 %28, ptr %32, align 4, !tbaa !9
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [1700017 x i32], ptr @sum, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = add nsw i32 %36, %37
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1700017 x i32], ptr @sum, i64 0, i64 %41
  store i32 %38, ptr %42, align 4, !tbaa !9
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = icmp eq i32 %43, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %4
  store i32 1, ptr %10, align 4
  br label %85

47:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = add nsw i32 %48, %49
  %51 = ashr i32 %50, 1
  store i32 %51, ptr %11, align 4, !tbaa !9
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = icmp sle i32 %52, %56
  br i1 %57, label %58, label %66

58:                                               ; preds = %47
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load i32, ptr %59, align 4, !tbaa !9
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [1700017 x i32], ptr @lch, i64 0, i64 %61
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = load i32, ptr %11, align 4, !tbaa !9
  %65 = load i32, ptr %8, align 4, !tbaa !9
  call void @_Z7seg_updRiiii(ptr noundef nonnull align 4 dereferenceable(4) %62, i32 noundef %63, i32 noundef %64, i32 noundef %65)
  br label %84

66:                                               ; preds = %47
  %67 = load i32, ptr %8, align 4, !tbaa !9
  %68 = load i32, ptr %11, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !9
  %73 = icmp sge i32 %67, %72
  br i1 %73, label %74, label %83

74:                                               ; preds = %66
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = load i32, ptr %75, align 4, !tbaa !9
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [1700017 x i32], ptr @rch, i64 0, i64 %77
  %79 = load i32, ptr %11, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = load i32, ptr %8, align 4, !tbaa !9
  call void @_Z7seg_updRiiii(ptr noundef nonnull align 4 dereferenceable(4) %78, i32 noundef %80, i32 noundef %81, i32 noundef %82)
  br label %83

83:                                               ; preds = %74, %66
  br label %84

84:                                               ; preds = %83, %58
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  store i32 0, ptr %10, align 4
  br label %85

85:                                               ; preds = %84, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %86 = load i32, ptr %10, align 4
  switch i32 %86, label %88 [
    i32 0, label %87
    i32 1, label %87
  ]

87:                                               ; preds = %85, %85
  ret void

88:                                               ; preds = %85
  unreachable
}

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

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

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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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"

@que = external dso_local local_unnamed_addr global [100001 x i32], align 16
@stot = external dso_local local_unnamed_addr global i32, align 4
@lch = external dso_local local_unnamed_addr global [1700017 x i32], align 16
@rch = external dso_local local_unnamed_addr global [1700017 x i32], align 16
@sum = external dso_local local_unnamed_addr global [1700017 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z7seg_updRiiii(ptr nocapture noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %40, %4
  %.tr.ph = phi ptr [ %43, %40 ], [ %0, %4 ]
  %.tr27.ph = phi i32 [ %36, %40 ], [ %1, %4 ]
  %.tr28.ph = phi i32 [ %.tr28, %40 ], [ %2, %4 ]
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.outer, %31
  %.tr = phi ptr [ %34, %31 ], [ %.tr.ph, %tailrecurse.outer ]
  %.tr28 = phi i32 [ %27, %31 ], [ %.tr28.ph, %tailrecurse.outer ]
  %5 = load i32, ptr %.tr, align 4, !tbaa !5
  %6 = load i32, ptr @stot, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @stot, align 4, !tbaa !5
  store i32 %7, ptr %.tr, align 4, !tbaa !5
  %8 = sext i32 %5 to i64
  %9 = getelementptr inbounds [1700017 x i32], ptr @lch, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = sext i32 %7 to i64
  %12 = getelementptr inbounds [1700017 x i32], ptr @lch, i64 0, i64 %11
  store i32 %10, ptr %12, align 4, !tbaa !5
  %13 = getelementptr inbounds [1700017 x i32], ptr @rch, i64 0, i64 %8
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = load i32, ptr %.tr, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1700017 x i32], ptr @rch, i64 0, i64 %16
  store i32 %14, ptr %17, align 4, !tbaa !5
  %18 = getelementptr inbounds [1700017 x i32], ptr @sum, i64 0, i64 %8
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = add nsw i32 %19, %3
  %21 = load i32, ptr %.tr, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1700017 x i32], ptr @sum, i64 0, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !5
  %24 = icmp eq i32 %.tr27.ph, %.tr28
  br i1 %24, label %.loopexit, label %25

25:                                               ; preds = %tailrecurse
  %26 = add nsw i32 %.tr28, %.tr27.ph
  %27 = ashr i32 %26, 1
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %.not = icmp slt i32 %30, %3
  br i1 %.not, label %35, label %31

31:                                               ; preds = %25
  %32 = load i32, ptr %.tr, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [1700017 x i32], ptr @lch, i64 0, i64 %33
  br label %tailrecurse

35:                                               ; preds = %25
  %36 = add nsw i32 %27, 1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100001 x i32], ptr @que, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %.not26 = icmp sgt i32 %39, %3
  br i1 %.not26, label %.loopexit, label %40

40:                                               ; preds = %35
  %41 = load i32, ptr %.tr, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [1700017 x i32], ptr @rch, i64 0, i64 %42
  br label %tailrecurse.outer

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, 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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass