; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/可持久化线段树.ll (Z6updateiiii)

; 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.node = type { i32, i32, i32, i32, i32, i32 }

@t = external dso_local global [2200000 x %struct.node], align 16
@cur = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z8maintaini(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 uwtable
define dso_local noundef i32 @_Z6updateiiii(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
  %10 = 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
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %11 = load i32, ptr @cur, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @cur, align 4, !tbaa !5
  store i32 %12, ptr %9, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %14
  %16 = load i32, ptr %9, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %17
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %18, ptr align 8 %15, i64 24, i1 false), !tbaa.struct !9
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = load i32, ptr %9, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.node, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !10
  %25 = icmp sle i32 %19, %24
  br i1 %25, label %26, label %45

26:                                               ; preds = %4
  %27 = load i32, ptr %7, align 4, !tbaa !5
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.node, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %31, align 4, !tbaa !12
  %33 = icmp sge i32 %27, %32
  br i1 %33, label %34, label %45

34:                                               ; preds = %26
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.node, ptr %37, i32 0, i32 5
  %39 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %38, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.node, ptr %43, i32 0, i32 5
  store i32 %40, ptr %44, align 4, !tbaa !13
  br label %94

45:                                               ; preds = %26, %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %46 = load i32, ptr %9, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.node, ptr %48, i32 0, i32 0
  %50 = load i32, ptr %49, align 8, !tbaa !10
  %51 = load i32, ptr %9, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.node, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %54, align 4, !tbaa !12
  %56 = add nsw i32 %50, %55
  %57 = ashr i32 %56, 1
  store i32 %57, ptr %10, align 4, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = load i32, ptr %10, align 4, !tbaa !5
  %60 = icmp sle i32 %58, %59
  br i1 %60, label %61, label %75

61:                                               ; preds = %45
  %62 = load i32, ptr %9, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.node, ptr %64, i32 0, i32 2
  %66 = load i32, ptr %65, align 8, !tbaa !14
  %67 = load i32, ptr %6, align 4, !tbaa !5
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = call noundef i32 @_Z6updateiiii(i32 noundef %66, i32 noundef %67, i32 noundef %68, i32 noundef %69)
  %71 = load i32, ptr %9, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %72
  %74 = getelementptr inbounds %struct.node, ptr %73, i32 0, i32 2
  store i32 %70, ptr %74, align 8, !tbaa !14
  br label %75

75:                                               ; preds = %61, %45
  %76 = load i32, ptr %7, align 4, !tbaa !5
  %77 = load i32, ptr %10, align 4, !tbaa !5
  %78 = icmp sgt i32 %76, %77
  br i1 %78, label %79, label %93

79:                                               ; preds = %75
  %80 = load i32, ptr %9, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %81
  %83 = getelementptr inbounds %struct.node, ptr %82, i32 0, i32 3
  %84 = load i32, ptr %83, align 4, !tbaa !15
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = load i32, ptr %7, align 4, !tbaa !5
  %87 = load i32, ptr %8, align 4, !tbaa !5
  %88 = call noundef i32 @_Z6updateiiii(i32 noundef %84, i32 noundef %85, i32 noundef %86, i32 noundef %87)
  %89 = load i32, ptr %9, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %90
  %92 = getelementptr inbounds %struct.node, ptr %91, i32 0, i32 3
  store i32 %88, ptr %92, align 4, !tbaa !15
  br label %93

93:                                               ; preds = %79, %75
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %94

94:                                               ; preds = %93, %34
  %95 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z8maintaini(i32 noundef %95)
  %96 = load i32, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret i32 %96
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5, i64 16, i64 4, !5, i64 20, i64 4, !5}
!10 = !{!11, !6, i64 0}
!11 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20}
!12 = !{!11, !6, i64 4}
!13 = !{!11, !6, i64 20}
!14 = !{!11, !6, i64 8}
!15 = !{!11, !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.node = type { i32, i32, i32, i32, i32, i32 }

@t = external dso_local global [2200000 x %struct.node], align 16
@cur = external dso_local local_unnamed_addr global i32, align 4

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -2147483647, -2147483648) i32 @_Z6updateiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  store i32 %3, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr @cur, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @cur, align 4, !tbaa !5
  %8 = sext i32 %0 to i64
  %9 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %8
  %10 = sext i32 %7 to i64
  %11 = getelementptr inbounds [2200000 x %struct.node], ptr @t, i64 0, i64 %10
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %11, ptr noundef nonnull align 8 dereferenceable(24) %9, i64 24, i1 false), !tbaa.struct !9
  %12 = load i32, ptr %11, align 8, !tbaa !10
  %.not = icmp slt i32 %12, %1
  %.phi.trans.insert = getelementptr inbounds i8, ptr %11, i64 4
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !12
  %.not25 = icmp sgt i32 %.pre, %2
  %or.cond = select i1 %.not, i1 true, i1 %.not25
  br i1 %or.cond, label %._crit_edge, label %13

13:                                               ; preds = %4
  %14 = getelementptr inbounds i8, ptr %11, i64 20
  %15 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %14, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %16 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %16, ptr %14, align 4, !tbaa !13
  br label %29

._crit_edge:                                      ; preds = %4
  %17 = add nsw i32 %.pre, %12
  %18 = ashr i32 %17, 1
  %.not26 = icmp slt i32 %18, %1
  br i1 %.not26, label %23, label %19

19:                                               ; preds = %._crit_edge
  %20 = getelementptr inbounds i8, ptr %11, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !14
  %22 = tail call noundef i32 @_Z6updateiiii(i32 noundef %21, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  store i32 %22, ptr %20, align 8, !tbaa !14
  br label %23

23:                                               ; preds = %19, %._crit_edge
  %24 = icmp slt i32 %18, %2
  br i1 %24, label %25, label %29

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %11, i64 12
  %27 = load i32, ptr %26, align 4, !tbaa !15
  %28 = tail call noundef i32 @_Z6updateiiii(i32 noundef %27, i32 noundef %1, i32 noundef %2, i32 noundef %3)
  store i32 %28, ptr %26, align 4, !tbaa !15
  br label %29

29:                                               ; preds = %23, %25, %13
  call void @_Z8maintaini(i32 noundef %7)
  ret i32 %7
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

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 nocallback nofree 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" }

!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 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5, i64 16, i64 4, !5, i64 20, i64 4, !5}
!10 = !{!11, !6, i64 0}
!11 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20}
!12 = !{!11, !6, i64 4}
!13 = !{!11, !6, i64 20}
!14 = !{!11, !6, i64 8}
!15 = !{!11, !6, i64 12}


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