; LLVM IR from div-bargali/Data-Structures-and-Algorithms :: C++/Data-Structures/Tree/Construct_Tree_from_given_Inorder_and_Preorder_traversals_0c81c1fe (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"

%class.node = type { i8, ptr, ptr }

@_ZZ9buildTreePcS_iiE8preIndex = external hidden global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z9buildTreePcS_ii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %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 ptr, align 8
  %11 = alloca i32, align 4
  %12 = 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
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = load i32, ptr %9, align 4, !tbaa !9
  %15 = icmp sgt i32 %13, %14
  br i1 %15, label %16, label %17

16:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  br label %56

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = load i32, ptr @_ZZ9buildTreePcS_iiE8preIndex, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr @_ZZ9buildTreePcS_iiE8preIndex, align 4, !tbaa !9
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds i8, ptr %18, i64 %21
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = call noundef ptr @_Z7newNodec(i8 noundef signext %23)
  store ptr %24, ptr %10, align 8, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = icmp eq i32 %25, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %17
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %29, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %55

30:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = load ptr, ptr %10, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.node, ptr %34, i32 0, i32 0
  %36 = load i8, ptr %35, align 8, !tbaa !12
  %37 = call noundef i32 @_Z6searchPciic(ptr noundef %31, i32 noundef %32, i32 noundef %33, i8 noundef signext %36)
  store i32 %37, ptr %12, align 4, !tbaa !9
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = load i32, ptr %12, align 4, !tbaa !9
  %42 = sub nsw i32 %41, 1
  %43 = call noundef ptr @_Z9buildTreePcS_ii(ptr noundef %38, ptr noundef %39, i32 noundef %40, i32 noundef %42)
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds %class.node, ptr %44, i32 0, i32 1
  store ptr %43, ptr %45, align 8, !tbaa !14
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load i32, ptr %12, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = call noundef ptr @_Z9buildTreePcS_ii(ptr noundef %46, ptr noundef %47, i32 noundef %49, i32 noundef %50)
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = getelementptr inbounds %class.node, ptr %52, i32 0, i32 2
  store ptr %51, ptr %53, align 8, !tbaa !15
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %54, ptr %5, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %55

55:                                               ; preds = %30, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %56

56:                                               ; preds = %55, %16
  %57 = load ptr, ptr %5, align 8
  ret ptr %57
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z7newNodec(i8 noundef signext) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z6searchPciic(ptr noundef, i32 noundef, i32 noundef, i8 noundef signext) #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 = { 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 = !{!"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 = !{!7, !7, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"_ZTS4node", !7, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!13, !6, i64 8}
!15 = !{!13, !6, i64 16}


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

@_ZZ9buildTreePcS_iiE8preIndex = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z9buildTreePcS_ii(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp sgt i32 %2, %3
  br i1 %5, label %common.ret22, label %6

6:                                                ; preds = %4
  %7 = load i32, ptr @_ZZ9buildTreePcS_iiE8preIndex, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @_ZZ9buildTreePcS_iiE8preIndex, align 4, !tbaa !5
  %9 = sext i32 %7 to i64
  %10 = getelementptr inbounds i8, ptr %1, i64 %9
  %11 = load i8, ptr %10, align 1, !tbaa !9
  %12 = tail call noundef ptr @_Z7newNodec(i8 noundef signext %11)
  %13 = icmp eq i32 %2, %3
  br i1 %13, label %common.ret22, label %14

common.ret22:                                     ; preds = %6, %4, %14
  %common.ret22.op = phi ptr [ %12, %14 ], [ null, %4 ], [ %12, %6 ]
  ret ptr %common.ret22.op

14:                                               ; preds = %6
  %15 = load i8, ptr %12, align 8, !tbaa !10
  %16 = tail call noundef i32 @_Z6searchPciic(ptr noundef %0, i32 noundef %2, i32 noundef %3, i8 noundef signext %15)
  %17 = add nsw i32 %16, -1
  %18 = tail call noundef ptr @_Z9buildTreePcS_ii(ptr noundef %0, ptr noundef nonnull %1, i32 noundef %2, i32 noundef %17)
  %19 = getelementptr inbounds i8, ptr %12, i64 8
  store ptr %18, ptr %19, align 8, !tbaa !13
  %20 = add nsw i32 %16, 1
  %21 = tail call noundef ptr @_Z9buildTreePcS_ii(ptr noundef %0, ptr noundef nonnull %1, i32 noundef %20, i32 noundef %3)
  %22 = getelementptr inbounds i8, ptr %12, i64 16
  store ptr %21, ptr %22, align 8, !tbaa !14
  br label %common.ret22
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z7newNodec(i8 noundef signext) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z6searchPciic(ptr noundef, i32 noundef, i32 noundef, i8 noundef signext) local_unnamed_addr #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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 0}
!11 = !{!"_ZTS4node", !7, i64 0, !12, i64 8, !12, i64 16}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!11, !12, i64 8}
!14 = !{!11, !12, i64 16}


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