; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x49-总结与练习/261. 旅馆.ll (Z6pushupi)

; 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: mustprogress uwtable
define dso_local void @_Z6pushupi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = mul nsw i32 2, %6
  store i32 %7, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = mul nsw i32 2, %8
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %4, align 4, !tbaa !5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %12
  %14 = getelementptr inbounds %struct.SegmentTree, ptr %13, i32 0, i32 3
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.SegmentTree, ptr %18, i32 0, i32 3
  store i64 %15, ptr %19, align 8, !tbaa !9
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.SegmentTree, ptr %22, i32 0, i32 2
  %24 = load i64, ptr %23, align 8, !tbaa !12
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.SegmentTree, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !13
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.SegmentTree, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !14
  %35 = sub nsw i32 %29, %34
  %36 = add nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = icmp eq i64 %24, %37
  br i1 %38, label %39, label %55

39:                                               ; preds = %1
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.SegmentTree, ptr %42, i32 0, i32 2
  %44 = load i64, ptr %43, align 8, !tbaa !12
  %45 = load i32, ptr %4, 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 3
  %49 = load i64, ptr %48, align 8, !tbaa !9
  %50 = add nsw i64 %44, %49
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.SegmentTree, ptr %53, i32 0, i32 3
  store i64 %50, ptr %54, align 8, !tbaa !9
  br label %55

55:                                               ; preds = %39, %1
  %56 = load i32, ptr %4, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.SegmentTree, ptr %58, i32 0, i32 4
  %60 = load i64, ptr %59, align 8, !tbaa !15
  %61 = load i32, ptr %2, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %62
  %64 = getelementptr inbounds %struct.SegmentTree, ptr %63, i32 0, i32 4
  store i64 %60, ptr %64, align 8, !tbaa !15
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %66
  %68 = getelementptr inbounds %struct.SegmentTree, ptr %67, i32 0, i32 2
  %69 = load i64, ptr %68, align 8, !tbaa !12
  %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 1
  %74 = load i32, ptr %73, align 4, !tbaa !13
  %75 = load i32, ptr %4, 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 0
  %79 = load i32, ptr %78, align 8, !tbaa !14
  %80 = sub nsw i32 %74, %79
  %81 = add nsw i32 %80, 1
  %82 = sext i32 %81 to i64
  %83 = icmp eq i64 %69, %82
  br i1 %83, label %84, label %100

84:                                               ; preds = %55
  %85 = load i32, ptr %4, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %86
  %88 = getelementptr inbounds %struct.SegmentTree, ptr %87, i32 0, i32 2
  %89 = load i64, ptr %88, align 8, !tbaa !12
  %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 4
  %94 = load i64, ptr %93, align 8, !tbaa !15
  %95 = add nsw i64 %89, %94
  %96 = load i32, ptr %2, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %97
  %99 = getelementptr inbounds %struct.SegmentTree, ptr %98, i32 0, i32 4
  store i64 %95, ptr %99, align 8, !tbaa !15
  br label %100

100:                                              ; preds = %84, %55
  %101 = load i32, ptr %3, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %102
  %104 = getelementptr inbounds %struct.SegmentTree, ptr %103, i32 0, i32 2
  %105 = load i32, ptr %4, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %106
  %108 = getelementptr inbounds %struct.SegmentTree, ptr %107, i32 0, i32 2
  %109 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %104, ptr noundef nonnull align 8 dereferenceable(8) %108)
  %110 = load i64, ptr %109, align 8, !tbaa !16
  %111 = load i32, ptr %2, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %112
  %114 = getelementptr inbounds %struct.SegmentTree, ptr %113, i32 0, i32 2
  store i64 %110, ptr %114, align 8, !tbaa !12
  %115 = load i32, ptr %2, align 4, !tbaa !5
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %116
  %118 = getelementptr inbounds %struct.SegmentTree, ptr %117, i32 0, i32 2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %119 = load i32, ptr %3, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %120
  %122 = getelementptr inbounds %struct.SegmentTree, ptr %121, i32 0, i32 4
  %123 = load i64, ptr %122, align 8, !tbaa !15
  %124 = load i32, ptr %4, align 4, !tbaa !5
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %125
  %127 = getelementptr inbounds %struct.SegmentTree, ptr %126, i32 0, i32 3
  %128 = load i64, ptr %127, align 8, !tbaa !9
  %129 = add nsw i64 %123, %128
  store i64 %129, ptr %5, align 8, !tbaa !16
  %130 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %118, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %131 = load i64, ptr %130, align 8, !tbaa !16
  %132 = load i32, ptr %2, align 4, !tbaa !5
  %133 = sext i32 %132 to i64
  %134 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %133
  %135 = getelementptr inbounds %struct.SegmentTree, ptr %134, i32 0, i32 2
  store i64 %131, ptr %135, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #2

; 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 = { inlinehint 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, !11, i64 16}
!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, !11, i64 8}
!13 = !{!10, !6, i64 4}
!14 = !{!10, !6, i64 0}
!15 = !{!10, !11, i64 24}
!16 = !{!11, !11, 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 { i32, i32, i64, i64, i64, i64 }

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6pushupi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, align 8
  %3 = shl nsw i32 %0, 1
  %4 = or disjoint i32 %3, 1
  %5 = sext i32 %3 to i64
  %6 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %5
  %7 = getelementptr inbounds i8, ptr %6, i64 16
  %8 = load i64, ptr %7, align 16, !tbaa !5
  %9 = sext i32 %0 to i64
  %10 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  store i64 %8, ptr %11, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %6, i64 8
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %6, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = load i32, ptr %6, align 16, !tbaa !13
  %17 = add i32 %15, 1
  %18 = sub i32 %17, %16
  %19 = sext i32 %18 to i64
  %20 = icmp eq i64 %13, %19
  %21 = sext i32 %4 to i64
  br i1 %20, label %22, label %._crit_edge

22:                                               ; preds = %1
  %23 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %21, i32 3
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = add nsw i64 %24, %13
  store i64 %25, ptr %11, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %1, %22
  %26 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %21
  %27 = getelementptr inbounds i8, ptr %26, i64 24
  %28 = load i64, ptr %27, align 16, !tbaa !14
  %29 = getelementptr inbounds i8, ptr %10, i64 24
  store i64 %28, ptr %29, align 8, !tbaa !14
  %30 = getelementptr inbounds i8, ptr %26, i64 8
  %31 = load i64, ptr %30, align 16, !tbaa !11
  %32 = getelementptr inbounds i8, ptr %26, i64 4
  %33 = load i32, ptr %32, align 4, !tbaa !12
  %34 = load i32, ptr %26, align 8, !tbaa !13
  %35 = add i32 %33, 1
  %36 = sub i32 %35, %34
  %37 = sext i32 %36 to i64
  %38 = icmp eq i64 %31, %37
  br i1 %38, label %39, label %43

39:                                               ; preds = %._crit_edge
  %40 = getelementptr inbounds i8, ptr %6, i64 24
  %41 = load i64, ptr %40, align 8, !tbaa !14
  %42 = add nsw i64 %41, %31
  store i64 %42, ptr %29, align 8, !tbaa !14
  br label %43

43:                                               ; preds = %39, %._crit_edge
  %44 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %12, ptr noundef nonnull align 8 dereferenceable(8) %30)
  %45 = load i64, ptr %44, align 8, !tbaa !15
  %46 = getelementptr inbounds i8, ptr %10, i64 8
  store i64 %45, ptr %46, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #3
  %47 = getelementptr inbounds i8, ptr %6, i64 24
  %48 = load i64, ptr %47, align 8, !tbaa !14
  %49 = getelementptr inbounds i8, ptr %26, i64 16
  %50 = load i64, ptr %49, align 8, !tbaa !5
  %51 = add nsw i64 %50, %48
  store i64 %51, ptr %2, align 8, !tbaa !15
  %52 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %46, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %53 = load i64, ptr %52, align 8, !tbaa !15
  store i64 %53, ptr %46, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #3
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #2

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

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 = { inlinehint 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, !10, i64 16}
!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, !10, i64 8}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !10, i64 24}
!15 = !{!10, !10, i64 0}


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