; LLVM IR from CZWin32768/ACMICPC-Templates-in-Latex :: atl/codes/Tree/Persistent-Segment-Tree.ll (ZN3PST5buildEii)

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

@_ZN3PST3totE = external dso_local global i32, align 4
@_ZN3PST4lsonE = external dso_local global [4000200 x i32], align 16
@_ZN3PST4rsonE = external dso_local global [4000200 x i32], align 16
@_ZN3PST1cE = external dso_local global [4000200 x i32], 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
define dso_local noundef i32 @_ZN3PST5buildEii(i32 noundef %0, i32 noundef %1) #1 {
  %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 @_ZN3PST3totE, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @_ZN3PST3totE, align 4, !tbaa !5
  store i32 %7, ptr %5, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST1cE, i64 0, i64 %10
  store i32 0, ptr %11, align 4, !tbaa !5
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = icmp ne i32 %12, %13
  br i1 %14, label %15, label %33

15:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = add nsw i32 %16, %17
  %19 = ashr i32 %18, 1
  store i32 %19, ptr %6, align 4, !tbaa !5
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = call noundef i32 @_ZN3PST5buildEii(i32 noundef %20, i32 noundef %21)
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4lsonE, i64 0, i64 %24
  store i32 %22, ptr %25, align 4, !tbaa !5
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = call noundef i32 @_ZN3PST5buildEii(i32 noundef %27, i32 noundef %28)
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4rsonE, i64 0, i64 %31
  store i32 %29, ptr %32, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %33

33:                                               ; preds = %15, %2
  %34 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %34
}

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


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

@_ZN3PST3totE = external dso_local local_unnamed_addr global i32, align 4
@_ZN3PST4lsonE = external dso_local local_unnamed_addr global [4000200 x i32], align 16
@_ZN3PST4rsonE = external dso_local local_unnamed_addr global [4000200 x i32], align 16
@_ZN3PST1cE = external dso_local local_unnamed_addr global [4000200 x i32], align 16

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_ZN3PST5buildEii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @_ZN3PST3totE, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr @_ZN3PST3totE, align 4, !tbaa !5
  %5 = sext i32 %3 to i64
  %6 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST1cE, i64 0, i64 %5
  store i32 0, ptr %6, align 4, !tbaa !5
  %.not = icmp eq i32 %0, %1
  br i1 %.not, label %common.ret13, label %7

common.ret13:                                     ; preds = %2, %7
  ret i32 %3

7:                                                ; preds = %2
  %8 = add nsw i32 %1, %0
  %9 = ashr i32 %8, 1
  %10 = tail call noundef i32 @_ZN3PST5buildEii(i32 noundef %0, i32 noundef %9)
  %11 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4lsonE, i64 0, i64 %5
  store i32 %10, ptr %11, align 4, !tbaa !5
  %12 = add nsw i32 %9, 1
  %13 = tail call noundef i32 @_ZN3PST5buildEii(i32 noundef %12, i32 noundef %1)
  %14 = getelementptr inbounds [4000200 x i32], ptr @_ZN3PST4rsonE, i64 0, i64 %5
  store i32 %13, ptr %14, align 4, !tbaa !5
  br label %common.ret13
}

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


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