; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/李超线段树.ll (Z6insertiiidd)

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

@t = external dso_local global [800020 x %struct.segment], 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 uwtable
declare dso_local void @_Z8pushdownidd(i32 noundef, double noundef, double noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6insertiiidd(i32 noundef %0, i32 noundef %1, i32 noundef %2, double noundef %3, double noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store double %3, ptr %9, align 8, !tbaa !9
  store double %4, ptr %10, align 8, !tbaa !9
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = load i32, ptr %6, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %14
  %16 = getelementptr inbounds %struct.segment, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 16, !tbaa !11
  %18 = icmp sle i32 %12, %17
  br i1 %18, label %19, label %31

19:                                               ; preds = %5
  %20 = load i32, ptr %8, align 4, !tbaa !5
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.segment, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = icmp sge i32 %20, %25
  br i1 %26, label %27, label %31

27:                                               ; preds = %19
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = load double, ptr %9, align 8, !tbaa !9
  %30 = load double, ptr %10, align 8, !tbaa !9
  call void @_Z8pushdownidd(i32 noundef %28, double noundef %29, double noundef %30)
  br label %72

31:                                               ; preds = %19, %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #2
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.segment, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 16, !tbaa !11
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.segment, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !13
  %42 = add nsw i32 %36, %41
  %43 = ashr i32 %42, 1
  store i32 %43, ptr %11, align 4, !tbaa !5
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = load i32, ptr %11, align 4, !tbaa !5
  %46 = icmp sle i32 %44, %45
  br i1 %46, label %47, label %57

47:                                               ; preds = %31
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %49
  %51 = getelementptr inbounds %struct.segment, ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 8, !tbaa !14
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = load i32, ptr %8, align 4, !tbaa !5
  %55 = load double, ptr %9, align 8, !tbaa !9
  %56 = load double, ptr %10, align 8, !tbaa !9
  call void @_Z6insertiiidd(i32 noundef %52, i32 noundef %53, i32 noundef %54, double noundef %55, double noundef %56)
  br label %57

57:                                               ; preds = %47, %31
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = load i32, ptr %11, align 4, !tbaa !5
  %60 = icmp sgt i32 %58, %59
  br i1 %60, label %61, label %71

61:                                               ; preds = %57
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %63
  %65 = getelementptr inbounds %struct.segment, ptr %64, i32 0, i32 3
  %66 = load i32, ptr %65, align 4, !tbaa !15
  %67 = load i32, ptr %7, align 4, !tbaa !5
  %68 = load i32, ptr %8, align 4, !tbaa !5
  %69 = load double, ptr %9, align 8, !tbaa !9
  %70 = load double, ptr %10, align 8, !tbaa !9
  call void @_Z6insertiiidd(i32 noundef %66, i32 noundef %67, i32 noundef %68, double noundef %69, double noundef %70)
  br label %71

71:                                               ; preds = %61, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #2
  br label %72

72:                                               ; preds = %71, %27
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS7segment", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !10, i64 16, !10, i64 24}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !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.segment = type { i32, i32, i32, i32, double, double }

@t = external dso_local local_unnamed_addr global [800020 x %struct.segment], align 16

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6insertiiidd(i32 noundef %0, i32 noundef %1, i32 noundef %2, double noundef %3, double noundef %4) local_unnamed_addr #0 {
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %6
  %8 = load i32, ptr %7, align 16, !tbaa !5
  %.not33 = icmp slt i32 %8, %1
  %.phi.trans.insert34 = getelementptr inbounds i8, ptr %7, i64 4
  %.pre35 = load i32, ptr %.phi.trans.insert34, align 4, !tbaa !11
  %.not2336 = icmp sgt i32 %.pre35, %2
  %or.cond37 = select i1 %.not33, i1 true, i1 %.not2336
  br i1 %or.cond37, label %tailrecurse._crit_edge, label %tailrecurse._crit_edge39

tailrecurse._crit_edge39:                         ; preds = %tailrecurse, %5
  %.tr.lcssa = phi i32 [ %0, %5 ], [ %19, %tailrecurse ]
  tail call void @_Z8pushdownidd(i32 noundef %.tr.lcssa, double noundef %3, double noundef %4)
  br label %.loopexit

tailrecurse._crit_edge:                           ; preds = %5, %tailrecurse
  %.pre38 = phi i32 [ %.pre, %tailrecurse ], [ %.pre35, %5 ]
  %9 = phi i32 [ %22, %tailrecurse ], [ %8, %5 ]
  %10 = phi ptr [ %21, %tailrecurse ], [ %7, %5 ]
  %11 = add nsw i32 %.pre38, %9
  %12 = ashr i32 %11, 1
  %.not24 = icmp slt i32 %12, %1
  br i1 %.not24, label %16, label %13

13:                                               ; preds = %tailrecurse._crit_edge
  %14 = getelementptr inbounds i8, ptr %10, i64 8
  %15 = load i32, ptr %14, align 8, !tbaa !12
  tail call void @_Z6insertiiidd(i32 noundef %15, i32 noundef %1, i32 noundef %2, double noundef %3, double noundef %4)
  br label %16

16:                                               ; preds = %13, %tailrecurse._crit_edge
  %17 = icmp slt i32 %12, %2
  br i1 %17, label %tailrecurse, label %.loopexit

tailrecurse:                                      ; preds = %16
  %18 = getelementptr inbounds i8, ptr %10, i64 12
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %20
  %22 = load i32, ptr %21, align 16, !tbaa !5
  %.not = icmp slt i32 %22, %1
  %.phi.trans.insert = getelementptr inbounds i8, ptr %21, i64 4
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !11
  %.not23 = icmp sgt i32 %.pre, %2
  %or.cond = select i1 %.not, i1 true, i1 %.not23
  br i1 %or.cond, label %tailrecurse._crit_edge, label %tailrecurse._crit_edge39

.loopexit:                                        ; preds = %16, %tailrecurse._crit_edge39
  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" }

!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 = !{!"_ZTS7segment", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !7, i64 12}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass