; LLVM IR from MakeContributions/DSA :: algorithms/CPlusPlus/Trees/build-binary-tree.ll (Z15buildTreePostInPiS_ii)

; 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.Node = type { i32, ptr, ptr }

@_ZZ15buildTreePostInPiS_iiE3idx = external hidden global i32, align 4
@_ZGVZ15buildTreePostInPiS_iiE3idx = external hidden global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z6searchPiiii(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #0

; 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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z15buildTreePostInPiS_ii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #4 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %16 = load atomic i8, ptr @_ZGVZ15buildTreePostInPiS_iiE3idx acquire, align 8
  %17 = icmp eq i8 %16, 0
  br i1 %17, label %18, label %23, !prof !11

18:                                               ; preds = %4
  %19 = call i32 @__cxa_guard_acquire(ptr @_ZGVZ15buildTreePostInPiS_iiE3idx) #5
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %23

21:                                               ; preds = %18
  %22 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %22, ptr @_ZZ15buildTreePostInPiS_iiE3idx, align 4, !tbaa !9
  call void @__cxa_guard_release(ptr @_ZGVZ15buildTreePostInPiS_iiE3idx) #5
  br label %23

23:                                               ; preds = %21, %18, %4
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = icmp sgt i32 %24, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  store ptr null, ptr %5, align 8
  br label %72

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i32, ptr @_ZZ15buildTreePostInPiS_iiE3idx, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i32, ptr %29, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !9
  store i32 %33, ptr %10, align 4, !tbaa !9
  %34 = load i32, ptr @_ZZ15buildTreePostInPiS_iiE3idx, align 4, !tbaa !9
  %35 = add nsw i32 %34, -1
  store i32 %35, ptr @_ZZ15buildTreePostInPiS_iiE3idx, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %36 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #6
  %37 = load i32, ptr %10, align 4, !tbaa !9
  invoke void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(24) %36, i32 noundef %37)
          to label %38 unwind label %44

38:                                               ; preds = %28
  store ptr %36, ptr %11, align 8, !tbaa !5
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = load i32, ptr %9, align 4, !tbaa !9
  %41 = icmp eq i32 %39, %40
  br i1 %41, label %42, label %48

42:                                               ; preds = %38
  %43 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %43, ptr %5, align 8
  store i32 1, ptr %14, align 4
  br label %71

44:                                               ; preds = %28
  %45 = landingpad { ptr, i32 }
          cleanup
  %46 = extractvalue { ptr, i32 } %45, 0
  store ptr %46, ptr %12, align 8
  %47 = extractvalue { ptr, i32 } %45, 1
  store i32 %47, ptr %13, align 4
  call void @_ZdlPvm(ptr noundef %36, i64 noundef 24) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %74

48:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = call noundef i32 @_Z6searchPiiii(ptr noundef %49, i32 noundef %50, i32 noundef %51, i32 noundef %52)
  store i32 %53, ptr %15, align 4, !tbaa !9
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load i32, ptr %15, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = call noundef ptr @_Z15buildTreePostInPiS_ii(ptr noundef %54, ptr noundef %55, i32 noundef %57, i32 noundef %58)
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Node, ptr %60, i32 0, i32 2
  store ptr %59, ptr %61, align 8, !tbaa !12
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = load i32, ptr %15, align 4, !tbaa !9
  %66 = sub nsw i32 %65, 1
  %67 = call noundef ptr @_Z15buildTreePostInPiS_ii(ptr noundef %62, ptr noundef %63, i32 noundef %64, i32 noundef %66)
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.Node, ptr %68, i32 0, i32 1
  store ptr %67, ptr %69, align 8, !tbaa !14
  %70 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %70, ptr %5, align 8
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  br label %71

71:                                               ; preds = %48, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %72

72:                                               ; preds = %71, %27
  %73 = load ptr, ptr %5, align 8
  ret ptr %73

74:                                               ; preds = %44
  %75 = load ptr, ptr %12, align 8
  %76 = load i32, ptr %13, align 4
  %77 = insertvalue { ptr, i32 } poison, ptr %75, 0
  %78 = insertvalue { ptr, i32 } %77, i32 %76, 1
  resume { ptr, i32 } %78
}

; Function Attrs: nounwind
declare i32 @__cxa_guard_acquire(ptr) #5

; Function Attrs: nounwind
declare void @__cxa_guard_release(ptr) #5

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nobuiltin allocsize(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 = { nobuiltin nounwind "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 = { 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 }
attributes #6 = { builtin allocsize(0) }
attributes #7 = { builtin 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!"branch_weights", i32 1, i32 1048575}
!12 = !{!13, !6, i64 16}
!13 = !{!"_ZTS4Node", !10, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!13, !6, i64 8}


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

@_ZZ15buildTreePostInPiS_iiE3idx = external hidden local_unnamed_addr global i32, align 4
@_ZGVZ15buildTreePostInPiS_iiE3idx = external hidden global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z6searchPiiii(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(24), i32 noundef) unnamed_addr #0 align 2

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z15buildTreePostInPiS_ii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #2 personality ptr @__gxx_personality_v0 {
  %5 = load atomic i8, ptr @_ZGVZ15buildTreePostInPiS_iiE3idx acquire, align 8
  %6 = icmp eq i8 %5, 0
  br i1 %6, label %7, label %10, !prof !5

7:                                                ; preds = %4
  %8 = tail call i32 @__cxa_guard_acquire(ptr nonnull @_ZGVZ15buildTreePostInPiS_iiE3idx) #4
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %10, label %9

9:                                                ; preds = %7
  store i32 %3, ptr @_ZZ15buildTreePostInPiS_iiE3idx, align 4, !tbaa !6
  tail call void @__cxa_guard_release(ptr nonnull @_ZGVZ15buildTreePostInPiS_iiE3idx) #4
  br label %10

10:                                               ; preds = %9, %7, %4
  %11 = icmp sgt i32 %2, %3
  br i1 %11, label %common.ret24, label %12

12:                                               ; preds = %10
  %13 = load i32, ptr @_ZZ15buildTreePostInPiS_iiE3idx, align 4, !tbaa !6
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr %0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !6
  %17 = add nsw i32 %13, -1
  store i32 %17, ptr @_ZZ15buildTreePostInPiS_iiE3idx, align 4, !tbaa !6
  %18 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #5
  tail call void @_ZN4NodeC2Ei(ptr noundef nonnull align 8 dereferenceable(24) %18, i32 noundef %16)
  %19 = icmp eq i32 %2, %3
  br i1 %19, label %common.ret24, label %20

common.ret24:                                     ; preds = %12, %10, %20
  %common.ret24.op = phi ptr [ %18, %20 ], [ null, %10 ], [ %18, %12 ]
  ret ptr %common.ret24.op

20:                                               ; preds = %12
  %21 = tail call noundef i32 @_Z6searchPiiii(ptr noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %16)
  %22 = add nsw i32 %21, 1
  %23 = tail call noundef ptr @_Z15buildTreePostInPiS_ii(ptr noundef nonnull %0, ptr noundef %1, i32 noundef %22, i32 noundef %3)
  %24 = getelementptr inbounds i8, ptr %18, i64 16
  store ptr %23, ptr %24, align 8, !tbaa !10
  %25 = add nsw i32 %21, -1
  %26 = tail call noundef ptr @_Z15buildTreePostInPiS_ii(ptr noundef nonnull %0, ptr noundef %1, i32 noundef %2, i32 noundef %25)
  %27 = getelementptr inbounds i8, ptr %18, i64 8
  store ptr %26, ptr %27, align 8, !tbaa !13
  br label %common.ret24
}

; Function Attrs: nofree nounwind
declare i32 @__cxa_guard_acquire(ptr) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare void @__cxa_guard_release(ptr) local_unnamed_addr #3

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 = { nobuiltin allocsize(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 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 = { nofree nounwind }
attributes #4 = { nounwind }
attributes #5 = { builtin allocsize(0) }

!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 = !{!"branch_weights", i32 1, i32 1048575}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !12, i64 16}
!11 = !{!"_ZTS4Node", !7, i64 0, !12, i64 8, !12, i64 16}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!11, !12, i64 8}


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