; LLVM IR from upupming/algorithm :: acwing/日常刷题/扫描线/1228. 油漆面积.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, i32, i32 }

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6pushupi(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 [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %4
  %6 = getelementptr inbounds %struct.SegmentTree, ptr %5, i32 0, i32 2
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %9, label %26

9:                                                ; preds = %1
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %11
  %13 = getelementptr inbounds %struct.SegmentTree, ptr %12, i32 0, i32 1
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.SegmentTree, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 16, !tbaa !12
  %20 = sub nsw i32 %14, %19
  %21 = add nsw i32 %20, 1
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.SegmentTree, ptr %24, i32 0, i32 3
  store i32 %21, ptr %25, align 4, !tbaa !13
  br label %63

26:                                               ; preds = %1
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.SegmentTree, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 16, !tbaa !12
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.SegmentTree, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = icmp eq i32 %31, %36
  br i1 %37, label %38, label %43

38:                                               ; preds = %26
  %39 = load i32, ptr %2, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %40
  %42 = getelementptr inbounds %struct.SegmentTree, ptr %41, i32 0, i32 3
  store i32 0, ptr %42, align 4, !tbaa !13
  br label %62

43:                                               ; preds = %26
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = mul nsw i32 2, %44
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %46
  %48 = getelementptr inbounds %struct.SegmentTree, ptr %47, i32 0, i32 3
  %49 = load i32, ptr %48, align 4, !tbaa !13
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = mul nsw i32 2, %50
  %52 = add nsw i32 %51, 1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.SegmentTree, ptr %54, i32 0, i32 3
  %56 = load i32, ptr %55, align 4, !tbaa !13
  %57 = add nsw i32 %49, %56
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.SegmentTree, ptr %60, i32 0, i32 3
  store i32 %57, ptr %61, align 4, !tbaa !13
  br label %62

62:                                               ; preds = %43, %38
  br label %63

63:                                               ; preds = %62, %9
  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 8}
!10 = !{!"_ZTS11SegmentTree", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 0}
!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 [40040 x %struct.SegmentTree], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z6pushupi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %2
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %7, label %13

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %3, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !10
  %10 = load i32, ptr %3, align 16, !tbaa !11
  %11 = add i32 %9, 1
  %12 = sub i32 %11, %10
  br label %28

13:                                               ; preds = %1
  %14 = load i32, ptr %3, align 16, !tbaa !11
  %15 = getelementptr inbounds i8, ptr %3, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !10
  %17 = icmp eq i32 %14, %16
  br i1 %17, label %28, label %18

18:                                               ; preds = %13
  %19 = shl nsw i32 %0, 1
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %20, i32 3
  %22 = load i32, ptr %21, align 4, !tbaa !12
  %23 = or disjoint i32 %19, 1
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %24, i32 3
  %26 = load i32, ptr %25, align 4, !tbaa !12
  %27 = add nsw i32 %26, %22
  br label %28

28:                                               ; preds = %13, %18, %7
  %.sink = phi i32 [ %27, %18 ], [ %12, %7 ], [ 0, %13 ]
  %29 = getelementptr inbounds i8, ptr %3, i64 12
  store i32 %.sink, ptr %29, align 4, !tbaa !12
  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 8}
!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 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 12}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass