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

; 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: mustprogress nounwind uwtable
define dso_local void @_Z6spreadi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %4
  %6 = getelementptr inbounds %struct.SegmentTree, ptr %5, i32 0, i32 3
  %7 = load i32, ptr %6, align 4, !tbaa !9
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %64

9:                                                ; preds = %1
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %11
  %13 = getelementptr inbounds %struct.SegmentTree, ptr %12, i32 0, i32 3
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = mul nsw i32 2, %15
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.SegmentTree, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !11
  %21 = add nsw i32 %20, %14
  store i32 %21, ptr %19, align 8, !tbaa !11
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.SegmentTree, ptr %24, i32 0, i32 3
  %26 = load i32, ptr %25, align 4, !tbaa !9
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = mul nsw i32 2, %27
  %29 = add nsw i32 %28, 1
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.SegmentTree, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = add nsw i32 %33, %26
  store i32 %34, ptr %32, align 8, !tbaa !11
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.SegmentTree, ptr %37, i32 0, i32 3
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = mul nsw i32 2, %40
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.SegmentTree, ptr %43, i32 0, i32 3
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = add nsw i32 %45, %39
  store i32 %46, ptr %44, align 4, !tbaa !9
  %47 = load i32, ptr %2, 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 3
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = mul nsw i32 2, %52
  %54 = add nsw i32 %53, 1
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.SegmentTree, ptr %56, i32 0, i32 3
  %58 = load i32, ptr %57, align 4, !tbaa !9
  %59 = add nsw i32 %58, %51
  store i32 %59, ptr %57, align 4, !tbaa !9
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %61
  %63 = getelementptr inbounds %struct.SegmentTree, ptr %62, i32 0, i32 3
  store i32 0, ptr %63, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %9, %1
  ret void
}

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

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


; 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 nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z6spreadi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %2, i32 3
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %23, label %5

5:                                                ; preds = %1
  %6 = shl nsw i32 %0, 1
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %7, i32 2
  %9 = or disjoint i32 %6, 1
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [80080 x %struct.SegmentTree], ptr @tree, i64 0, i64 %10
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  %13 = load i32, ptr %12, align 8, !tbaa !10
  %14 = add nsw i32 %13, %4
  store i32 %14, ptr %12, align 8, !tbaa !10
  %15 = load <2 x i32>, ptr %8, align 8, !tbaa !11
  %16 = insertelement <2 x i32> poison, i32 %4, i64 0
  %17 = shufflevector <2 x i32> %16, <2 x i32> poison, <2 x i32> zeroinitializer
  %18 = add nsw <2 x i32> %15, %17
  store <2 x i32> %18, ptr %8, align 8, !tbaa !11
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %11, i64 12
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %21, %19
  store i32 %22, ptr %20, align 4, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %5, %1
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, 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, !7, i64 12}
!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 8}
!11 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass