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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6pushupi(i32 noundef) #0

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6spreadi(i32 noundef) #2

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

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 [200040 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 %74

25:                                               ; preds = %17
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %54

28:                                               ; preds = %25
  %29 = load i32, ptr %5, 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 1
  %33 = load i32, ptr %32, align 4, !tbaa !12
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.SegmentTree, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !9
  %39 = sub nsw i32 %33, %38
  %40 = add nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.SegmentTree, ptr %44, i32 0, i32 4
  store i64 %41, ptr %45, align 8, !tbaa !13
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.SegmentTree, ptr %48, i32 0, i32 3
  store i64 %41, ptr %49, align 8, !tbaa !14
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.SegmentTree, ptr %52, i32 0, i32 2
  store i64 %41, ptr %53, align 8, !tbaa !15
  br label %67

54:                                               ; preds = %25
  %55 = load i32, ptr %5, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.SegmentTree, ptr %57, i32 0, i32 4
  store i64 0, ptr %58, align 8, !tbaa !13
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %60
  %62 = getelementptr inbounds %struct.SegmentTree, ptr %61, i32 0, i32 3
  store i64 0, ptr %62, align 8, !tbaa !14
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %64
  %66 = getelementptr inbounds %struct.SegmentTree, ptr %65, i32 0, i32 2
  store i64 0, ptr %66, align 8, !tbaa !15
  br label %67

67:                                               ; preds = %54, %28
  %68 = load i32, ptr %8, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = load i32, ptr %5, 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 5
  store i64 %69, ptr %73, align 8, !tbaa !16
  br label %111

74:                                               ; preds = %17, %4
  %75 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z6spreadi(i32 noundef %75)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %76 = load i32, ptr %5, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %77
  %79 = getelementptr inbounds %struct.SegmentTree, ptr %78, i32 0, i32 0
  %80 = load i32, ptr %79, align 8, !tbaa !9
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [200040 x %struct.SegmentTree], ptr @tree, i64 0, i64 %82
  %84 = getelementptr inbounds %struct.SegmentTree, ptr %83, i32 0, i32 1
  %85 = load i32, ptr %84, align 4, !tbaa !12
  %86 = add nsw i32 %80, %85
  %87 = ashr i32 %86, 1
  store i32 %87, ptr %9, align 4, !tbaa !5
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = load i32, ptr %9, align 4, !tbaa !5
  %90 = icmp sle i32 %88, %89
  br i1 %90, label %91, label %97

91:                                               ; preds = %74
  %92 = load i32, ptr %5, align 4, !tbaa !5
  %93 = mul nsw i32 2, %92
  %94 = load i32, ptr %6, align 4, !tbaa !5
  %95 = load i32, ptr %7, align 4, !tbaa !5
  %96 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z6changeiiii(i32 noundef %93, i32 noundef %94, i32 noundef %95, i32 noundef %96)
  br label %97

97:                                               ; preds = %91, %74
  %98 = load i32, ptr %7, align 4, !tbaa !5
  %99 = load i32, ptr %9, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  %101 = icmp sge i32 %98, %100
  br i1 %101, label %102, label %109

102:                                              ; preds = %97
  %103 = load i32, ptr %5, align 4, !tbaa !5
  %104 = mul nsw i32 2, %103
  %105 = add nsw i32 %104, 1
  %106 = load i32, ptr %6, align 4, !tbaa !5
  %107 = load i32, ptr %7, align 4, !tbaa !5
  %108 = load i32, ptr %8, align 4, !tbaa !5
  call void @_Z6changeiiii(i32 noundef %105, i32 noundef %106, i32 noundef %107, i32 noundef %108)
  br label %109

109:                                              ; preds = %102, %97
  %110 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z6pushupi(i32 noundef %110)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %111

111:                                              ; preds = %109, %67
  ret void
}

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 = { 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, !6, i64 0}
!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, !11, i64 24}
!14 = !{!10, !11, i64 16}
!15 = !{!10, !11, i64 8}
!16 = !{!10, !11, i64 32}


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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6spreadi(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress 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 [200040 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 %19, label %8

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

11:                                               ; preds = %8
  %12 = icmp eq i32 %3, 1
  %reass.sub = sub i32 %10, %7
  %13 = add i32 %reass.sub, 1
  %narrow = select i1 %12, i32 %13, i32 0
  %.sink38 = sext i32 %narrow to i64
  %14 = getelementptr inbounds i8, ptr %6, i64 24
  store i64 %.sink38, ptr %14, align 8
  %15 = getelementptr inbounds i8, ptr %6, i64 16
  store i64 %.sink38, ptr %15, align 8
  %16 = getelementptr inbounds i8, ptr %6, i64 8
  store i64 %.sink38, ptr %16, align 8
  %17 = sext i32 %3 to i64
  %18 = getelementptr inbounds i8, ptr %6, i64 32
  store i64 %17, ptr %18, align 8, !tbaa !12
  br label %32

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

25:                                               ; preds = %19
  %26 = shl nsw i32 %0, 1
  tail call void @_Z6changeiiii(i32 noundef %26, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  br label %27

27:                                               ; preds = %25, %19
  %.not36.not = icmp slt i32 %24, %2
  br i1 %.not36.not, label %28, label %31

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

31:                                               ; preds = %28, %27
  tail call void @_Z6pushupi(i32 noundef %0)
  br label %32

32:                                               ; preds = %31, %11
  ret void
}

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 = { 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, !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, !10, i64 32}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MergedLoadStoreMotionPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass