; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x43-线段树/243. 一个简单的整数问题2.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, i64, i64 }

@tree = external dso_local global [400040 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 @_Z6spreadi(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 [400040 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 8, !tbaa !9
  %16 = icmp sle i32 %10, %15
  br i1 %16, label %17, label %56

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 [400040 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 !12
  %24 = icmp sge i32 %18, %23
  br i1 %24, label %25, label %56

25:                                               ; preds = %17
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [400040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.SegmentTree, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !12
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [400040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %34
  %36 = getelementptr inbounds %struct.SegmentTree, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !9
  %38 = sub nsw i32 %32, %37
  %39 = add nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = mul nsw i64 %27, %40
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [400040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.SegmentTree, ptr %44, i32 0, i32 2
  %46 = load i64, ptr %45, align 8, !tbaa !13
  %47 = add nsw i64 %46, %41
  store i64 %47, ptr %45, align 8, !tbaa !13
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [400040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.SegmentTree, ptr %52, i32 0, i32 3
  %54 = load i64, ptr %53, align 8, !tbaa !14
  %55 = add nsw i64 %54, %49
  store i64 %55, ptr %53, align 8, !tbaa !14
  br label %110

56:                                               ; preds = %17, %4
  %57 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z6spreadi(i32 noundef %57)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [400040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.SegmentTree, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !9
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [400040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %64
  %66 = getelementptr inbounds %struct.SegmentTree, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 4, !tbaa !12
  %68 = add nsw i32 %62, %67
  %69 = ashr i32 %68, 1
  store i32 %69, ptr %9, align 4, !tbaa !5
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = load i32, ptr %9, align 4, !tbaa !5
  %72 = icmp sle i32 %70, %71
  br i1 %72, label %73, label %79

73:                                               ; preds = %56
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = mul nsw i32 2, %74
  %76 = load i32, ptr %6, align 4, !tbaa !5
  %77 = load i32, ptr %7, align 4, !tbaa !5
  %78 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z6changeiiii(i32 noundef %75, i32 noundef %76, i32 noundef %77, i32 noundef %78)
  br label %79

79:                                               ; preds = %73, %56
  %80 = load i32, ptr %7, align 4, !tbaa !5
  %81 = load i32, ptr %9, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  %83 = icmp sge i32 %80, %82
  br i1 %83, label %84, label %91

84:                                               ; preds = %79
  %85 = load i32, ptr %5, align 4, !tbaa !5
  %86 = mul nsw i32 2, %85
  %87 = add nsw i32 %86, 1
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = load i32, ptr %7, align 4, !tbaa !5
  %90 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z6changeiiii(i32 noundef %87, i32 noundef %88, i32 noundef %89, i32 noundef %90)
  br label %91

91:                                               ; preds = %84, %79
  %92 = load i32, ptr %5, align 4, !tbaa !5
  %93 = mul nsw i32 2, %92
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [400040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %94
  %96 = getelementptr inbounds %struct.SegmentTree, ptr %95, i32 0, i32 2
  %97 = load i64, ptr %96, align 8, !tbaa !13
  %98 = load i32, ptr %5, align 4, !tbaa !5
  %99 = mul nsw i32 2, %98
  %100 = add nsw i32 %99, 1
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [400040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %101
  %103 = getelementptr inbounds %struct.SegmentTree, ptr %102, i32 0, i32 2
  %104 = load i64, ptr %103, align 8, !tbaa !13
  %105 = add nsw i64 %97, %104
  %106 = load i32, ptr %5, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [400040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %107
  %109 = getelementptr inbounds %struct.SegmentTree, ptr %108, i32 0, i32 2
  store i64 %105, ptr %109, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %110

110:                                              ; preds = %91, %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, !11, i64 8, !11, i64 16}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !6, i64 4}
!13 = !{!10, !11, i64 8}
!14 = !{!10, !11, i64 16}


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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6spreadi(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 [400040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %5
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %.not = icmp slt i32 %7, %1
  br i1 %.not, label %22, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %6, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %.not31 = icmp sgt i32 %10, %2
  br i1 %.not31, label %22, label %11

11:                                               ; preds = %8
  %12 = sext i32 %3 to i64
  %reass.sub = sub i32 %10, %7
  %13 = add i32 %reass.sub, 1
  %14 = sext i32 %13 to i64
  %15 = mul nsw i64 %14, %12
  %16 = getelementptr inbounds i8, ptr %6, i64 8
  %17 = load i64, ptr %16, align 8, !tbaa !12
  %18 = add nsw i64 %17, %15
  store i64 %18, ptr %16, align 8, !tbaa !12
  %19 = getelementptr inbounds i8, ptr %6, i64 16
  %20 = load i64, ptr %19, align 8, !tbaa !13
  %21 = add nsw i64 %20, %12
  store i64 %21, ptr %19, align 8, !tbaa !13
  br label %42

22:                                               ; preds = %8, %4
  tail call void @_Z6spreadi(i32 noundef %0)
  %23 = load i32, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %6, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = add nsw i32 %25, %23
  %27 = ashr i32 %26, 1
  %.not32 = icmp slt i32 %27, %1
  br i1 %.not32, label %30, label %28

28:                                               ; preds = %22
  %29 = shl nsw i32 %0, 1
  tail call void @_Z6changeiiii(i32 noundef %29, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  br label %30

30:                                               ; preds = %28, %22
  %.not33.not = icmp slt i32 %27, %2
  %31 = shl nsw i32 %0, 1
  %32 = or disjoint i32 %31, 1
  br i1 %.not33.not, label %33, label %._crit_edge

33:                                               ; preds = %30
  tail call void @_Z6changeiiii(i32 noundef %32, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  br label %._crit_edge

._crit_edge:                                      ; preds = %30, %33
  %34 = sext i32 %31 to i64
  %35 = getelementptr inbounds [400040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %34, i32 2
  %36 = load i64, ptr %35, align 8, !tbaa !12
  %37 = sext i32 %32 to i64
  %38 = getelementptr inbounds [400040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %37, i32 2
  %39 = load i64, ptr %38, align 16, !tbaa !12
  %40 = add nsw i64 %39, %36
  %41 = getelementptr inbounds i8, ptr %6, i64 8
  store i64 %40, ptr %41, align 8, !tbaa !12
  br label %42

42:                                               ; preds = %._crit_edge, %11
  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, !10, i64 8, !10, i64 16}
!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, !10, i64 8}
!13 = !{!6, !10, i64 16}


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