; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x49-总结与练习/261. 旅馆.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, i64, i64, i64, i64 }

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

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = mul nsw i32 2, %12
  store i32 %13, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = mul nsw i32 2, %14
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %4, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.SegmentTree, ptr %19, i32 0, i32 5
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = icmp eq i64 %21, 1
  br i1 %22, label %23, label %74

23:                                               ; preds = %11
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %25
  %27 = getelementptr inbounds %struct.SegmentTree, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !12
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.SegmentTree, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !13
  %34 = sub nsw i32 %28, %33
  %35 = add nsw i32 %34, 1
  %36 = sext i32 %35 to i64
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.SegmentTree, ptr %39, i32 0, i32 4
  store i64 %36, ptr %40, align 8, !tbaa !14
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.SegmentTree, ptr %43, i32 0, i32 3
  store i64 %36, ptr %44, align 8, !tbaa !15
  %45 = load i32, ptr %3, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %46
  %48 = getelementptr inbounds %struct.SegmentTree, ptr %47, i32 0, i32 2
  store i64 %36, ptr %48, align 8, !tbaa !16
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.SegmentTree, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !12
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.SegmentTree, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !13
  %59 = sub nsw i32 %53, %58
  %60 = add nsw i32 %59, 1
  %61 = sext i32 %60 to i64
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.SegmentTree, ptr %64, i32 0, i32 4
  store i64 %61, ptr %65, align 8, !tbaa !14
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %67
  %69 = getelementptr inbounds %struct.SegmentTree, ptr %68, i32 0, i32 3
  store i64 %61, ptr %69, align 8, !tbaa !15
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %71
  %73 = getelementptr inbounds %struct.SegmentTree, ptr %72, i32 0, i32 2
  store i64 %61, ptr %73, align 8, !tbaa !16
  br label %107

74:                                               ; preds = %11
  %75 = load i32, ptr %2, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %76
  %78 = getelementptr inbounds %struct.SegmentTree, ptr %77, i32 0, i32 5
  %79 = load i64, ptr %78, align 8, !tbaa !9
  %80 = icmp eq i64 %79, 2
  br i1 %80, label %81, label %106

81:                                               ; preds = %74
  %82 = load i32, ptr %3, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %83
  %85 = getelementptr inbounds %struct.SegmentTree, ptr %84, i32 0, i32 4
  store i64 0, ptr %85, align 8, !tbaa !14
  %86 = load i32, ptr %3, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %87
  %89 = getelementptr inbounds %struct.SegmentTree, ptr %88, i32 0, i32 3
  store i64 0, ptr %89, align 8, !tbaa !15
  %90 = load i32, ptr %3, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %91
  %93 = getelementptr inbounds %struct.SegmentTree, ptr %92, i32 0, i32 2
  store i64 0, ptr %93, align 8, !tbaa !16
  %94 = load i32, ptr %4, align 4, !tbaa !5
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %95
  %97 = getelementptr inbounds %struct.SegmentTree, ptr %96, i32 0, i32 4
  store i64 0, ptr %97, align 8, !tbaa !14
  %98 = load i32, ptr %4, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %99
  %101 = getelementptr inbounds %struct.SegmentTree, ptr %100, i32 0, i32 3
  store i64 0, ptr %101, align 8, !tbaa !15
  %102 = load i32, ptr %4, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %103
  %105 = getelementptr inbounds %struct.SegmentTree, ptr %104, i32 0, i32 2
  store i64 0, ptr %105, align 8, !tbaa !16
  br label %106

106:                                              ; preds = %81, %74
  br label %107

107:                                              ; preds = %106, %23
  %108 = load i32, ptr %2, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %109
  %111 = getelementptr inbounds %struct.SegmentTree, ptr %110, i32 0, i32 5
  %112 = load i64, ptr %111, align 8, !tbaa !9
  %113 = load i32, ptr %4, align 4, !tbaa !5
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %114
  %116 = getelementptr inbounds %struct.SegmentTree, ptr %115, i32 0, i32 5
  store i64 %112, ptr %116, align 8, !tbaa !9
  %117 = load i32, ptr %3, align 4, !tbaa !5
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %118
  %120 = getelementptr inbounds %struct.SegmentTree, ptr %119, i32 0, i32 5
  store i64 %112, ptr %120, align 8, !tbaa !9
  %121 = load i32, ptr %2, align 4, !tbaa !5
  %122 = sext i32 %121 to i64
  %123 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %122
  %124 = getelementptr inbounds %struct.SegmentTree, ptr %123, i32 0, i32 5
  store i64 0, ptr %124, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %125

125:                                              ; preds = %107, %1
  ret void
}

attributes #0 = { 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 = { 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, !11, i64 32}
!10 = !{!"_ZTS11SegmentTree", !6, i64 0, !6, i64 4, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !6, i64 4}
!13 = !{!10, !6, i64 0}
!14 = !{!10, !11, i64 24}
!15 = !{!10, !11, i64 16}
!16 = !{!10, !11, 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, i64, i64, i64, i64 }

@tree = external dso_local local_unnamed_addr global [200040 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 [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %2, i32 5
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %39, label %5

5:                                                ; preds = %1
  %6 = shl nsw i32 %0, 1
  %7 = or disjoint i32 %6, 1
  switch i64 %4, label %._crit_edge [
    i64 1, label %8
    i64 2, label %31
  ]

._crit_edge:                                      ; preds = %5
  %.pre = sext i32 %7 to i64
  %.pre26 = sext i32 %6 to i64
  br label %36

8:                                                ; preds = %5
  %9 = sext i32 %6 to i64
  %10 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = load i32, ptr %10, align 16, !tbaa !12
  %14 = add i32 %12, 1
  %15 = sub i32 %14, %13
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %10, i64 24
  store i64 %16, ptr %17, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %10, i64 16
  store i64 %16, ptr %18, align 16, !tbaa !14
  %19 = getelementptr inbounds i8, ptr %10, i64 8
  store i64 %16, ptr %19, align 8, !tbaa !15
  %20 = sext i32 %7 to i64
  %21 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %20
  %22 = getelementptr inbounds i8, ptr %21, i64 4
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = load i32, ptr %21, align 8, !tbaa !12
  %25 = add i32 %23, 1
  %26 = sub i32 %25, %24
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %21, i64 24
  store i64 %27, ptr %28, align 16, !tbaa !13
  %29 = getelementptr inbounds i8, ptr %21, i64 16
  store i64 %27, ptr %29, align 8, !tbaa !14
  %30 = getelementptr inbounds i8, ptr %21, i64 8
  store i64 %27, ptr %30, align 16, !tbaa !15
  br label %36

31:                                               ; preds = %5
  %32 = sext i32 %6 to i64
  %33 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %32, i32 2
  %34 = sext i32 %7 to i64
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %33, i8 0, i64 24, i1 false)
  %35 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %34, i32 2
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(24) %35, i8 0, i64 24, i1 false)
  br label %36

36:                                               ; preds = %._crit_edge, %31, %8
  %.pre-phi27 = phi i64 [ %.pre26, %._crit_edge ], [ %32, %31 ], [ %9, %8 ]
  %.pre-phi = phi i64 [ %.pre, %._crit_edge ], [ %34, %31 ], [ %20, %8 ]
  %37 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %.pre-phi, i32 5
  store i64 %4, ptr %37, align 8, !tbaa !5
  %38 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %.pre-phi27, i32 5
  store i64 %4, ptr %38, align 8, !tbaa !5
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %39

39:                                               ; preds = %36, %1
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }

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


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