; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x43-线段树/248. 窗内的星星.ll (Z6changeiiii)

; 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 { i32, i32, i32, i32 }

@tree = external dso_local global [80080 x %struct.SegmentTree], 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
declare dso_local void @_Z6pushupi(i32 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6spreadi(i32 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6changeiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.SegmentTree, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 16, !tbaa !9
  %16 = icmp sle i32 %10, %15
  br i1 %16, label %17, label %40

17:                                               ; preds = %4
  %18 = load i32, ptr %7, align 4, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.SegmentTree, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = icmp sge i32 %18, %23
  br i1 %24, label %25, label %40

25:                                               ; preds = %17
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.SegmentTree, ptr %29, i32 0, i32 2
  %31 = load i32, ptr %30, align 8, !tbaa !12
  %32 = add nsw i32 %31, %26
  store i32 %32, ptr %30, align 8, !tbaa !12
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.SegmentTree, ptr %36, i32 0, i32 3
  %38 = load i32, ptr %37, align 4, !tbaa !13
  %39 = add nsw i32 %38, %33
  store i32 %39, ptr %37, align 4, !tbaa !13
  br label %77

40:                                               ; preds = %17, %4
  %41 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z6spreadi(i32 noundef %41)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.SegmentTree, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 16, !tbaa !9
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.SegmentTree, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !11
  %52 = add nsw i32 %46, %51
  %53 = ashr i32 %52, 1
  store i32 %53, ptr %9, align 4, !tbaa !5
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = icmp sle i32 %54, %55
  br i1 %56, label %57, label %63

57:                                               ; preds = %40
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = mul nsw i32 2, %58
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z6changeiiii(i32 noundef %59, i32 noundef %60, i32 noundef %61, i32 noundef %62)
  br label %63

63:                                               ; preds = %57, %40
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = load i32, ptr %9, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  %67 = icmp sge i32 %64, %66
  br i1 %67, label %68, label %75

68:                                               ; preds = %63
  %69 = load i32, ptr %5, align 4, !tbaa !5
  %70 = mul nsw i32 2, %69
  %71 = add nsw i32 %70, 1
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = load i32, ptr %7, align 4, !tbaa !5
  %74 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z6changeiiii(i32 noundef %71, i32 noundef %72, i32 noundef %73, i32 noundef %74)
  br label %75

75:                                               ; preds = %68, %63
  %76 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z6pushupi(i32 noundef %76)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %77

77:                                               ; preds = %75, %25
  ret void
}

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 = { 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 0}
!10 = !{!"_ZTS11SegmentTree", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 12}


; 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 { i32, i32, i32, i32 }

@tree = external dso_local local_unnamed_addr global [80080 x %struct.SegmentTree], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6pushupi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6spreadi(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6changeiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %5
  %7 = load i32, ptr %6, align 16, !tbaa !5
  %.not = icmp slt i32 %7, %1
  br i1 %.not, label %17, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %6, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !10
  %.not25 = icmp sgt i32 %10, %2
  br i1 %.not25, label %17, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %6, i64 8
  %13 = load <2 x i32>, ptr %12, align 8, !tbaa !11
  %14 = insertelement <2 x i32> poison, i32 %3, i64 0
  %15 = shufflevector <2 x i32> %14, <2 x i32> poison, <2 x i32> zeroinitializer
  %16 = add nsw <2 x i32> %13, %15
  store <2 x i32> %16, ptr %12, align 8, !tbaa !11
  br label %30

17:                                               ; preds = %8, %4
  tail call void @_Z6spreadi(i32 noundef %0)
  %18 = load i32, ptr %6, align 16, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %6, i64 4
  %20 = load i32, ptr %19, align 4, !tbaa !10
  %21 = add nsw i32 %20, %18
  %22 = ashr i32 %21, 1
  %.not26 = icmp slt i32 %22, %1
  br i1 %.not26, label %25, label %23

23:                                               ; preds = %17
  %24 = shl nsw i32 %0, 1
  tail call void @_Z6changeiiii(i32 noundef %24, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  br label %25

25:                                               ; preds = %23, %17
  %.not27.not = icmp slt i32 %22, %2
  br i1 %.not27.not, label %26, label %29

26:                                               ; preds = %25
  %27 = shl nsw i32 %0, 1
  %28 = or disjoint i32 %27, 1
  tail call void @_Z6changeiiii(i32 noundef %28, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  br label %29

29:                                               ; preds = %26, %25
  tail call void @_Z6pushupi(i32 noundef %0)
  br label %30

30:                                               ; preds = %29, %11
  ret void
}

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

!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, !7, i64 0}
!6 = !{!"_ZTS11SegmentTree", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,TailCallElimPass