; LLVM IR from upupming/algorithm :: acwing/日常刷题/扫描线/1228. 油漆面积.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 [40040 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
declare dso_local void @_Z6pushupi(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6changeiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %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 [40040 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 %34

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 [40040 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 %34

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 [40040 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 %5, align 4, !tbaa !5
  call void @_Z6pushupi(i32 noundef %33)
  br label %70

34:                                               ; preds = %17, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.SegmentTree, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 16, !tbaa !9
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.SegmentTree, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 4, !tbaa !11
  %45 = add nsw i32 %39, %44
  %46 = ashr i32 %45, 1
  store i32 %46, ptr %9, align 4, !tbaa !5
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = load i32, ptr %9, align 4, !tbaa !5
  %49 = icmp sle i32 %47, %48
  br i1 %49, label %50, label %56

50:                                               ; preds = %34
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = mul nsw i32 2, %51
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = load i32, ptr %7, align 4, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z6changeiiii(i32 noundef %52, i32 noundef %53, i32 noundef %54, i32 noundef %55)
  br label %56

56:                                               ; preds = %50, %34
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = load i32, ptr %9, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  %60 = icmp sge i32 %57, %59
  br i1 %60, label %61, label %68

61:                                               ; preds = %56
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = mul nsw i32 2, %62
  %64 = add nsw i32 %63, 1
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = load i32, ptr %7, align 4, !tbaa !5
  %67 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z6changeiiii(i32 noundef %64, i32 noundef %65, i32 noundef %66, i32 noundef %67)
  br label %68

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

70:                                               ; preds = %68, %25
  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 = { 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 #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}


; 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 nounwind uwtable
declare dso_local void @_Z6pushupi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind 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 [40040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %5
  %7 = load i32, ptr %6, align 16, !tbaa !5
  %.not = icmp slt i32 %7, %1
  %.phi.trans.insert = getelementptr inbounds i8, ptr %6, i64 4
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !10
  %.not23 = icmp sgt i32 %.pre, %2
  %or.cond = select i1 %.not, i1 true, i1 %.not23
  br i1 %or.cond, label %._crit_edge, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %6, i64 8
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = add nsw i32 %10, %3
  store i32 %11, ptr %9, align 8, !tbaa !11
  br label %20

._crit_edge:                                      ; preds = %4
  %12 = add nsw i32 %.pre, %7
  %13 = ashr i32 %12, 1
  %.not24 = icmp slt i32 %13, %1
  br i1 %.not24, label %16, label %14

14:                                               ; preds = %._crit_edge
  %15 = shl nsw i32 %0, 1
  tail call void @_Z6changeiiii(i32 noundef %15, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  br label %16

16:                                               ; preds = %14, %._crit_edge
  %.not25.not = icmp slt i32 %13, %2
  br i1 %.not25.not, label %17, label %20

17:                                               ; preds = %16
  %18 = shl nsw i32 %0, 1
  %19 = or disjoint i32 %18, 1
  tail call void @_Z6changeiiii(i32 noundef %19, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  br label %20

20:                                               ; preds = %16, %17, %8
  tail call void @_Z6pushupi(i32 noundef %0)
  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, !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 = !{!6, !7, i64 8}


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