; LLVM IR from tangjz/acm-icpc :: lydsy/2762.ll (Z5checkii)

; 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.SegmentTree = type { [4194304 x i32] }

@num = external dso_local global [100001 x [2 x i32]], align 16
@tot = external dso_local global i32, align 4
@vis = external dso_local global [100001 x i8], align 16
@Tree = external dso_local global %struct.SegmentTree, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5checkii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 1000000
  br i1 %8, label %16, label %9

9:                                                ; preds = %2
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = icmp slt i32 %10, -1000000
  br i1 %11, label %16, label %12

12:                                               ; preds = %9
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = icmp sgt i32 %13, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %12, %9, %2
  br label %70

17:                                               ; preds = %12
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = icmp slt i32 %18, -1000000
  br i1 %19, label %20, label %25

20:                                               ; preds = %17
  %21 = load i32, ptr @tot, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100001 x [2 x i32]], ptr @num, i64 0, i64 %22
  %24 = getelementptr inbounds [2 x i32], ptr %23, i64 0, i64 0
  store i32 -1000000, ptr %24, align 8, !tbaa !5
  br label %31

25:                                               ; preds = %17
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = load i32, ptr @tot, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100001 x [2 x i32]], ptr @num, i64 0, i64 %28
  %30 = getelementptr inbounds [2 x i32], ptr %29, i64 0, i64 0
  store i32 %26, ptr %30, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %25, %20
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = icmp sgt i32 %32, 1000000
  br i1 %33, label %34, label %39

34:                                               ; preds = %31
  %35 = load i32, ptr @tot, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100001 x [2 x i32]], ptr @num, i64 0, i64 %36
  %38 = getelementptr inbounds [2 x i32], ptr %37, i64 0, i64 1
  store i32 1000000, ptr %38, align 4, !tbaa !5
  br label %45

39:                                               ; preds = %31
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = load i32, ptr @tot, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100001 x [2 x i32]], ptr @num, i64 0, i64 %42
  %44 = getelementptr inbounds [2 x i32], ptr %43, i64 0, i64 1
  store i32 %40, ptr %44, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %39, %34
  %46 = load i32, ptr @tot, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [100001 x [2 x i32]], ptr @num, i64 0, i64 %47
  %49 = getelementptr inbounds [2 x i32], ptr %48, i64 0, i64 0
  %50 = load i32, ptr %49, align 8, !tbaa !5
  %51 = add nsw i32 %50, 1000001
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !5
  call void @_ZN11SegmentTree6changeEiRKi(ptr noundef nonnull align 4 dereferenceable(16777216) @Tree, i32 noundef %51, ptr noundef nonnull align 4 dereferenceable(4) %5)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  %52 = load i32, ptr @tot, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100001 x [2 x i32]], ptr @num, i64 0, i64 %53
  %55 = getelementptr inbounds [2 x i32], ptr %54, i64 0, i64 1
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = icmp slt i32 %56, 1000000
  br i1 %57, label %58, label %66

58:                                               ; preds = %45
  %59 = load i32, ptr @tot, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100001 x [2 x i32]], ptr @num, i64 0, i64 %60
  %62 = getelementptr inbounds [2 x i32], ptr %61, i64 0, i64 1
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  %65 = add nsw i32 %64, 1000001
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 -1, ptr %6, align 4, !tbaa !5
  call void @_ZN11SegmentTree6changeEiRKi(ptr noundef nonnull align 4 dereferenceable(16777216) @Tree, i32 noundef %65, ptr noundef nonnull align 4 dereferenceable(4) %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %66

66:                                               ; preds = %58, %45
  %67 = load i32, ptr @tot, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %68
  store i8 1, ptr %69, align 1, !tbaa !9
  br label %70

70:                                               ; preds = %66, %16
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11SegmentTree6changeEiRKi(ptr noundef nonnull align 4 dereferenceable(16777216), i32 noundef, ptr noundef nonnull align 4 dereferenceable(4)) #1 align 2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"bool", !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"

%struct.SegmentTree = type { [4194304 x i32] }

@num = external dso_local local_unnamed_addr global [100001 x [2 x i32]], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4
@vis = external dso_local local_unnamed_addr global [100001 x i8], align 16
@Tree = external dso_local global %struct.SegmentTree, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5checkii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = icmp sgt i32 %0, 1000000
  %6 = icmp slt i32 %1, -1000000
  %or.cond = or i1 %5, %6
  %7 = icmp sgt i32 %0, %1
  %or.cond11 = or i1 %7, %or.cond
  br i1 %or.cond11, label %29, label %8

8:                                                ; preds = %2
  %9 = icmp slt i32 %0, -1000000
  %10 = load i32, ptr @tot, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [100001 x [2 x i32]], ptr @num, i64 0, i64 %11
  br i1 %9, label %13, label %14

13:                                               ; preds = %8
  store i32 -1000000, ptr %12, align 8, !tbaa !5
  br label %16

14:                                               ; preds = %8
  store i32 %0, ptr %12, align 8, !tbaa !5
  %15 = add nsw i32 %0, 1000001
  br label %16

16:                                               ; preds = %14, %13
  %17 = phi i32 [ %15, %14 ], [ 1, %13 ]
  %. = tail call i32 @llvm.smin.i32(i32 %1, i32 1000000)
  %18 = sext i32 %10 to i64
  %19 = getelementptr inbounds [100001 x [2 x i32]], ptr @num, i64 0, i64 %18, i64 1
  store i32 %., ptr %19, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  store i32 1, ptr %3, align 4, !tbaa !5
  call void @_ZN11SegmentTree6changeEiRKi(ptr noundef nonnull align 4 dereferenceable(16777216) @Tree, i32 noundef %17, ptr noundef nonnull align 4 dereferenceable(4) %3)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  %20 = load i32, ptr @tot, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [100001 x [2 x i32]], ptr @num, i64 0, i64 %21, i64 1
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = icmp slt i32 %23, 1000000
  br i1 %24, label %25, label %27

25:                                               ; preds = %16
  %26 = add nsw i32 %23, 1000002
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #3
  store i32 -1, ptr %4, align 4, !tbaa !5
  call void @_ZN11SegmentTree6changeEiRKi(ptr noundef nonnull align 4 dereferenceable(16777216) @Tree, i32 noundef %26, ptr noundef nonnull align 4 dereferenceable(4) %4)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  %.pre = load i32, ptr @tot, align 4, !tbaa !5
  %.pre12 = sext i32 %.pre to i64
  br label %27

27:                                               ; preds = %25, %16
  %.pre-phi13 = phi i64 [ %.pre12, %25 ], [ %21, %16 ]
  %28 = getelementptr inbounds [100001 x i8], ptr @vis, i64 0, i64 %.pre-phi13
  store i8 1, ptr %28, align 1, !tbaa !9
  br label %29

29:                                               ; preds = %2, %27
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN11SegmentTree6changeEiRKi(ptr noundef nonnull align 4 dereferenceable(16777216), i32 noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #0 align 2

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #2

attributes #0 = { 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"bool", !7, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass