; LLVM IR from ADJA/algos :: DataStructures/SegmentTree(Assign-Sum).ll (Z5buildiiiPi)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<node, std::allocator<node>>::_Vector_impl" }
%"struct.std::_Vector_base<node, std::allocator<node>>::_Vector_impl" = type { %"struct.std::_Vector_base<node, std::allocator<node>>::_Vector_impl_data" }
%"struct.std::_Vector_base<node, std::allocator<node>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%struct.node = type { i64, i32, i32 }

@tree = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildiiiPi(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !9
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = load i32, ptr %7, align 4, !tbaa !5
  %12 = icmp eq i32 %10, %11
  br i1 %12, label %13, label %32

13:                                               ; preds = %4
  %14 = load ptr, ptr %8, align 8, !tbaa !9
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i32, ptr %14, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %20) #3
  %22 = getelementptr inbounds %struct.node, ptr %21, i32 0, i32 1
  store i32 %18, ptr %22, align 8, !tbaa !11
  %23 = sext i32 %18 to i64
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %25) #3
  %27 = getelementptr inbounds %struct.node, ptr %26, i32 0, i32 0
  store i64 %23, ptr %27, align 8, !tbaa !14
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %29) #3
  %31 = getelementptr inbounds %struct.node, ptr %30, i32 0, i32 2
  store i32 1, ptr %31, align 4, !tbaa !15
  br label %91

32:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = sub nsw i32 %34, %35
  %37 = sdiv i32 %36, 2
  %38 = add nsw i32 %33, %37
  store i32 %38, ptr %9, align 4, !tbaa !5
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = mul nsw i32 2, %39
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = load i32, ptr %9, align 4, !tbaa !5
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  call void @_Z5buildiiiPi(i32 noundef %40, i32 noundef %41, i32 noundef %42, ptr noundef %43)
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = mul nsw i32 2, %44
  %46 = add nsw i32 %45, 1
  %47 = load i32, ptr %9, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = load ptr, ptr %8, align 8, !tbaa !9
  call void @_Z5buildiiiPi(i32 noundef %46, i32 noundef %48, i32 noundef %49, ptr noundef %50)
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = mul nsw i32 2, %51
  %53 = sext i32 %52 to i64
  %54 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %53) #3
  %55 = getelementptr inbounds %struct.node, ptr %54, i32 0, i32 0
  %56 = load i64, ptr %55, align 8, !tbaa !14
  %57 = load i32, ptr %5, align 4, !tbaa !5
  %58 = mul nsw i32 2, %57
  %59 = add nsw i32 %58, 1
  %60 = sext i32 %59 to i64
  %61 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %60) #3
  %62 = getelementptr inbounds %struct.node, ptr %61, i32 0, i32 0
  %63 = load i64, ptr %62, align 8, !tbaa !14
  %64 = add nsw i64 %56, %63
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %66) #3
  %68 = getelementptr inbounds %struct.node, ptr %67, i32 0, i32 0
  store i64 %64, ptr %68, align 8, !tbaa !14
  %69 = load i32, ptr %5, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %70) #3
  %72 = getelementptr inbounds %struct.node, ptr %71, i32 0, i32 1
  store i32 -1, ptr %72, align 8, !tbaa !11
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = mul nsw i32 2, %73
  %75 = add nsw i32 %74, 1
  %76 = sext i32 %75 to i64
  %77 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %76) #3
  %78 = getelementptr inbounds %struct.node, ptr %77, i32 0, i32 2
  %79 = load i32, ptr %78, align 4, !tbaa !15
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = mul nsw i32 2, %80
  %82 = sext i32 %81 to i64
  %83 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %82) #3
  %84 = getelementptr inbounds %struct.node, ptr %83, i32 0, i32 2
  %85 = load i32, ptr %84, align 4, !tbaa !15
  %86 = add nsw i32 %79, %85
  %87 = load i32, ptr %5, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %88) #3
  %90 = getelementptr inbounds %struct.node, ptr %89, i32 0, i32 2
  store i32 %86, ptr %90, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %91

91:                                               ; preds = %32, %13
  ret void
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

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

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

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS4node", !13, i64 0, !6, i64 8, !6, i64 12}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !13, i64 0}
!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"

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<node, std::allocator<node>>::_Vector_impl" }
%"struct.std::_Vector_base<node, std::allocator<node>>::_Vector_impl" = type { %"struct.std::_Vector_base<node, std::allocator<node>>::_Vector_impl_data" }
%"struct.std::_Vector_base<node, std::allocator<node>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@tree = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5buildiiiPi(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq i32 %1, %2
  br i1 %5, label %6, label %17

6:                                                ; preds = %4
  %7 = sext i32 %1 to i64
  %8 = getelementptr inbounds i32, ptr %3, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = sext i32 %0 to i64
  %11 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %10) #1
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  store i32 %9, ptr %12, align 8, !tbaa !9
  %13 = sext i32 %9 to i64
  %14 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %10) #1
  store i64 %13, ptr %14, align 8, !tbaa !12
  br label %common.ret

common.ret:                                       ; preds = %6, %17
  %.sink27 = phi i64 [ %10, %6 ], [ %31, %17 ]
  %.sink = phi i32 [ 1, %6 ], [ %41, %17 ]
  %15 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %.sink27) #1
  %16 = getelementptr inbounds i8, ptr %15, i64 12
  store i32 %.sink, ptr %16, align 4, !tbaa !13
  ret void

17:                                               ; preds = %4
  %18 = sub nsw i32 %2, %1
  %19 = sdiv i32 %18, 2
  %20 = add nsw i32 %19, %1
  %21 = shl nsw i32 %0, 1
  tail call void @_Z5buildiiiPi(i32 noundef %21, i32 noundef %1, i32 noundef %20, ptr noundef %3)
  %22 = or disjoint i32 %21, 1
  %23 = add nsw i32 %20, 1
  tail call void @_Z5buildiiiPi(i32 noundef %22, i32 noundef %23, i32 noundef %2, ptr noundef %3)
  %24 = sext i32 %21 to i64
  %25 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %24) #1
  %26 = load i64, ptr %25, align 8, !tbaa !12
  %27 = sext i32 %22 to i64
  %28 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %27) #1
  %29 = load i64, ptr %28, align 8, !tbaa !12
  %30 = add nsw i64 %29, %26
  %31 = sext i32 %0 to i64
  %32 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %31) #1
  store i64 %30, ptr %32, align 8, !tbaa !12
  %33 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %31) #1
  %34 = getelementptr inbounds i8, ptr %33, i64 8
  store i32 -1, ptr %34, align 8, !tbaa !9
  %35 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %27) #1
  %36 = getelementptr inbounds i8, ptr %35, i64 12
  %37 = load i32, ptr %36, align 4, !tbaa !13
  %38 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @tree, i64 noundef %24) #1
  %39 = getelementptr inbounds i8, ptr %38, i64 12
  %40 = load i32, ptr %39, align 4, !tbaa !13
  %41 = add nsw i32 %40, %37
  br label %common.ret
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(16) ptr @_ZNSt6vectorI4nodeSaIS0_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

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 = { 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 8}
!10 = !{!"_ZTS4node", !11, i64 0, !6, i64 8, !6, i64 12}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!10, !6, i64 12}


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