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

@cur = external dso_local global i32, align 4
@val = external dso_local global [110000 x i32], align 16
@t = external dso_local global [440000 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) #3
  %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 [440000 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 8, !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 [440000 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 !11
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [440000 x %struct.segment], ptr @t, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.segment, ptr %21, i32 0, i32 5
  store i32 0, ptr %22, align 4, !tbaa !12
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %32

26:                                               ; preds = %2
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [110000 x i32], ptr @val, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  call void @_Z4markii(i32 noundef %27, i32 noundef %31)
  br label %53

32:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = add nsw i32 %33, %34
  %36 = ashr i32 %35, 1
  store i32 %36, ptr %6, align 4, !tbaa !5
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = call noundef i32 @_Z5buildii(i32 noundef %37, i32 noundef %38)
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [440000 x %struct.segment], ptr @t, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.segment, ptr %42, i32 0, i32 2
  store i32 %39, ptr %43, align 8, !tbaa !13
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = call noundef i32 @_Z5buildii(i32 noundef %45, i32 noundef %46)
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [440000 x %struct.segment], ptr @t, i64 0, i64 %49
  %51 = getelementptr inbounds %struct.segment, ptr %50, i32 0, i32 3
  store i32 %47, ptr %51, align 4, !tbaa !14
  %52 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z8maintaini(i32 noundef %52)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %53

53:                                               ; preds = %32, %26
  %54 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %54
}

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

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

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

; 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 = { 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 #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 = !{!"_ZTS7segment", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 20}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !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, i32, i32 }

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

; Function Attrs: mustprogress nounwind 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 [440000 x %struct.segment], ptr @t, i64 0, i64 %5
  store i32 %0, ptr %6, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 %1, ptr %7, align 4, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %6, i64 20
  store i32 0, ptr %8, align 4, !tbaa !12
  %9 = icmp eq i32 %0, %1
  br i1 %9, label %common.ret, label %13

common.ret:                                       ; preds = %2
  %10 = sext i32 %0 to i64
  %11 = getelementptr inbounds [110000 x i32], ptr @val, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  tail call void @_Z4markii(i32 noundef %4, i32 noundef %12)
  br label %common.ret20

common.ret20:                                     ; preds = %13, %common.ret
  ret i32 %4

13:                                               ; preds = %2
  %14 = add nsw i32 %1, %0
  %15 = ashr i32 %14, 1
  %16 = tail call noundef i32 @_Z5buildii(i32 noundef %0, i32 noundef %15)
  %17 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 %16, ptr %17, align 8, !tbaa !13
  %18 = add nsw i32 %15, 1
  %19 = tail call noundef i32 @_Z5buildii(i32 noundef %18, i32 noundef %1)
  %20 = getelementptr inbounds i8, ptr %6, i64 12
  store i32 %19, ptr %20, align 4, !tbaa !14
  tail call void @_Z8maintaini(i32 noundef %4)
  br label %common.ret20
}

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

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

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" }
attributes #1 = { 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 = !{!10, !6, i64 0}
!10 = !{!"_ZTS7segment", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 20}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !6, i64 12}


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