; 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.tmp = type { [1050000 x i32] }
%struct.segment = type { i32, i32, i32, i32, i32, i32, i32, i32, i32 }

@A = external dso_local global %struct.tmp, align 4
@cur = external dso_local global i32, align 4
@t = external dso_local global [840000 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) #5
  %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 [840000 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 4, !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 [840000 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 [840000 x %struct.segment], ptr @t, i64 0, i64 %20
  %22 = getelementptr inbounds %struct.segment, ptr %21, i32 0, i32 8
  store i32 0, ptr %22, align 4, !tbaa !12
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.segment, ptr %25, i32 0, i32 7
  store i32 -1, ptr %26, align 4, !tbaa !13
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.segment, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %33
  %35 = getelementptr inbounds %struct.segment, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = icmp eq i32 %31, %36
  br i1 %37, label %38, label %43

38:                                               ; preds = %2
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN3tmpixEi(ptr noundef nonnull align 4 dereferenceable(4200000) @A, i32 noundef %40)
  %42 = load i32, ptr %41, align 4, !tbaa !5
  call void @_Z4markiii(i32 noundef %39, i32 noundef 0, i32 noundef %42)
  br label %72

43:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.segment, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.segment, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !11
  %54 = add nsw i32 %48, %53
  %55 = ashr i32 %54, 1
  store i32 %55, ptr %6, align 4, !tbaa !5
  %56 = load i32, ptr %3, align 4, !tbaa !5
  %57 = load i32, ptr %6, align 4, !tbaa !5
  %58 = call noundef i32 @_Z5buildii(i32 noundef %56, i32 noundef %57)
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %60
  %62 = getelementptr inbounds %struct.segment, ptr %61, i32 0, i32 2
  store i32 %58, ptr %62, align 4, !tbaa !14
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = call noundef i32 @_Z5buildii(i32 noundef %64, i32 noundef %65)
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [840000 x %struct.segment], ptr @t, i64 0, i64 %68
  %70 = getelementptr inbounds %struct.segment, ptr %69, i32 0, i32 3
  store i32 %66, ptr %70, align 4, !tbaa !15
  %71 = load i32, ptr %5, align 4, !tbaa !5
  call void @_Z8maintaini(i32 noundef %71)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %72

72:                                               ; preds = %43, %38
  %73 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret i32 %73
}

; 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 @_Z4markiii(i32 noundef, i32 noundef, i32 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN3tmpixEi(ptr noundef nonnull align 4 dereferenceable(4200000), i32 noundef) #3 align 2

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

; 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 = { 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 = { inlinehint 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 #5 = { 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, !6, i64 24, !6, i64 28, !6, i64 32}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 32}
!13 = !{!10, !6, i64 28}
!14 = !{!10, !6, i64 8}
!15 = !{!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.tmp = type { [1050000 x i32] }
%struct.segment = type { i32, i32, i32, i32, i32, i32, i32, i32, i32 }

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

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

common.ret:                                       ; preds = %2
  %11 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN3tmpixEi(ptr noundef nonnull align 4 dereferenceable(4200000) @A, i32 noundef %0)
  %12 = load i32, ptr %11, align 4, !tbaa !5
  tail call void @_Z4markiii(i32 noundef %4, i32 noundef 0, i32 noundef %12)
  br label %common.ret21

common.ret21:                                     ; 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 4, !tbaa !14
  %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 !15
  tail call void @_Z8maintaini(i32 noundef %4)
  br label %common.ret21
}

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z8maintaini(i32 noundef) local_unnamed_addr #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 = { 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 #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 = { inlinehint 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, !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, !6, i64 24, !6, i64 28, !6, i64 32}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 32}
!13 = !{!10, !6, i64 28}
!14 = !{!10, !6, i64 8}
!15 = !{!10, !6, i64 12}


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