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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5buildii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %7 = load i32, ptr @cur, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @cur, align 4, !tbaa !5
  store i32 %8, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %11
  %13 = getelementptr inbounds %struct.segment, ptr %12, i32 0, i32 0
  store i32 %9, ptr %13, align 16, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.segment, ptr %17, i32 0, i32 1
  store i32 %14, ptr %18, align 4, !tbaa !12
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = icmp slt i32 %19, %20
  br i1 %21, label %22, label %42

22:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = add nsw i32 %23, %24
  %26 = ashr i32 %25, 1
  store i32 %26, ptr %6, align 4, !tbaa !5
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = call noundef i32 @_Z5buildii(i32 noundef %27, i32 noundef %28)
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.segment, ptr %32, i32 0, i32 2
  store i32 %29, ptr %33, align 8, !tbaa !13
  %34 = load i32, ptr %6, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = call noundef i32 @_Z5buildii(i32 noundef %35, i32 noundef %36)
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.segment, ptr %40, i32 0, i32 3
  store i32 %37, ptr %41, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %42

42:                                               ; preds = %22, %2
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %44
  %46 = getelementptr inbounds %struct.segment, ptr %45, i32 0, i32 4
  store double 0.000000e+00, ptr %46, align 16, !tbaa !15
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.segment, ptr %49, i32 0, i32 5
  store double 0xC1D0000000000000, ptr %50, align 8, !tbaa !16
  %51 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %51
}

; 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

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


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

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

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 -2147483647, -2147483648) i32 @_Z5buildii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @cur, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr @cur, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [800020 x %struct.segment], ptr @t, i64 0, i64 %5
  store i32 %0, ptr %6, align 16, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 %1, ptr %7, align 4, !tbaa !12
  %8 = icmp slt i32 %0, %1
  br i1 %8, label %9, label %17

9:                                                ; preds = %2
  %10 = add nsw i32 %1, %0
  %11 = ashr i32 %10, 1
  %12 = tail call noundef i32 @_Z5buildii(i32 noundef %0, i32 noundef %11)
  %13 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 %12, ptr %13, align 8, !tbaa !13
  %14 = add nsw i32 %11, 1
  %15 = tail call noundef i32 @_Z5buildii(i32 noundef %14, i32 noundef %1)
  %16 = getelementptr inbounds i8, ptr %6, i64 12
  store i32 %15, ptr %16, align 4, !tbaa !14
  br label %17

17:                                               ; preds = %9, %2
  %18 = getelementptr inbounds i8, ptr %6, i64 16
  store <2 x double> <double 0.000000e+00, double 0xC1D0000000000000>, ptr %18, align 16, !tbaa !15
  ret i32 %4
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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 = !{!10, !6, i64 0}
!10 = !{!"_ZTS7segment", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !11, i64 16, !11, i64 24}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !6, i64 4}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !6, i64 12}
!15 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,TailCallElimPass