; LLVM IR from xtaci/algorithms :: src (btree_demo)

; 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.alg::BTree" = type { i32 }
%"struct.alg::BTree::Res" = type { i32, i32 }

@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca %"class.alg::BTree", align 4
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %"struct.alg::BTree::Res", align 4
  %7 = alloca %"struct.alg::BTree::Res", align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @_ZN3alg5BTreeC2EPKc(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef @.str)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %36, %0
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp slt i32 %9, 1000
  br i1 %10, label %11, label %39

11:                                               ; preds = %8
  %12 = load i32, ptr %3, align 4, !tbaa !5
  invoke void @_ZN3alg5BTree6InsertEi(ptr noundef nonnull align 4 dereferenceable(4) %2, i32 noundef %12)
          to label %13 unwind label %27

13:                                               ; preds = %11
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = invoke i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %14)
          to label %16 unwind label %27

16:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = invoke i64 @_ZN3alg5BTree6SearchEi(ptr noundef nonnull align 4 dereferenceable(4) %2, i32 noundef %17)
          to label %19 unwind label %31

19:                                               ; preds = %16
  store i64 %18, ptr %6, align 4
  %20 = getelementptr inbounds %"struct.alg::BTree::Res", ptr %6, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !9
  %22 = icmp eq i32 %21, -1
  br i1 %22, label %23, label %35

23:                                               ; preds = %19
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = invoke i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %24)
          to label %26 unwind label %31

26:                                               ; preds = %23
  br label %35

27:                                               ; preds = %43, %13, %11
  %28 = landingpad { ptr, i32 }
          cleanup
  %29 = extractvalue { ptr, i32 } %28, 0
  store ptr %29, ptr %4, align 8
  %30 = extractvalue { ptr, i32 } %28, 1
  store i32 %30, ptr %5, align 4
  br label %66

31:                                               ; preds = %23, %16
  %32 = landingpad { ptr, i32 }
          cleanup
  %33 = extractvalue { ptr, i32 } %32, 0
  store ptr %33, ptr %4, align 8
  %34 = extractvalue { ptr, i32 } %32, 1
  store i32 %34, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %66

35:                                               ; preds = %26, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %3, align 4, !tbaa !5
  br label %8, !llvm.loop !11

39:                                               ; preds = %8
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %61, %39
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = icmp slt i32 %41, 1000
  br i1 %42, label %43, label %64

43:                                               ; preds = %40
  %44 = load i32, ptr %3, align 4, !tbaa !5
  invoke void @_ZN3alg5BTree9DeleteKeyEi(ptr noundef nonnull align 4 dereferenceable(4) %2, i32 noundef %44)
          to label %45 unwind label %27

45:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = invoke i64 @_ZN3alg5BTree6SearchEi(ptr noundef nonnull align 4 dereferenceable(4) %2, i32 noundef %46)
          to label %48 unwind label %56

48:                                               ; preds = %45
  store i64 %47, ptr %7, align 4
  %49 = getelementptr inbounds %"struct.alg::BTree::Res", ptr %7, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = icmp eq i32 %50, -1
  br i1 %51, label %52, label %60

52:                                               ; preds = %48
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = invoke i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %53)
          to label %55 unwind label %56

55:                                               ; preds = %52
  br label %60

56:                                               ; preds = %52, %45
  %57 = landingpad { ptr, i32 }
          cleanup
  %58 = extractvalue { ptr, i32 } %57, 0
  store ptr %58, ptr %4, align 8
  %59 = extractvalue { ptr, i32 } %57, 1
  store i32 %59, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %66

60:                                               ; preds = %55, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %3, align 4, !tbaa !5
  br label %40, !llvm.loop !13

64:                                               ; preds = %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @_ZN3alg5BTreeD2Ev(ptr noundef nonnull align 4 dereferenceable(4) %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  %65 = load i32, ptr %1, align 4
  ret i32 %65

66:                                               ; preds = %56, %31, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @_ZN3alg5BTreeD2Ev(ptr noundef nonnull align 4 dereferenceable(4) %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %67

67:                                               ; preds = %66
  %68 = load ptr, ptr %4, align 8
  %69 = load i32, ptr %5, align 4
  %70 = insertvalue { ptr, i32 } poison, ptr %68, 0
  %71 = insertvalue { ptr, i32 } %70, i32 %69, 1
  resume { ptr, i32 } %71
}

; 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 void @_ZN3alg5BTreeC2EPKc(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3alg5BTree6InsertEi(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #2 align 2

declare i32 @__gxx_personality_v0(...)

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZN3alg5BTree6SearchEi(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #2 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3alg5BTree9DeleteKeyEi(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3alg5BTreeD2Ev(ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #4 align 2

attributes #0 = { mustprogress norecurse 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 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 = { "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 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 #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 4}
!10 = !{!"_ZTSN3alg5BTree3ResE", !6, i64 0, !6, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !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.alg::BTree" = type { i32 }

@.str = external hidden unnamed_addr constant [12 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [23 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca %"class.alg::BTree", align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  call void @_ZN3alg5BTreeC2EPKc(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull @.str)
  br label %2

2:                                                ; preds = %0, %12
  %.018 = phi i32 [ 0, %0 ], [ %13, %12 ]
  invoke void @_ZN3alg5BTree6InsertEi(ptr noundef nonnull align 4 dereferenceable(4) %1, i32 noundef %.018)
          to label %3 unwind label %.loopexit.split-lp

3:                                                ; preds = %2
  %4 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.018)
  %5 = invoke i64 @_ZN3alg5BTree6SearchEi(ptr noundef nonnull align 4 dereferenceable(4) %1, i32 noundef %.018)
          to label %6 unwind label %10

6:                                                ; preds = %3
  %7 = icmp ugt i64 %5, -4294967297
  br i1 %7, label %8, label %12

8:                                                ; preds = %6
  %9 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.018)
  br label %12

.loopexit:                                        ; preds = %.preheader
  %lpad.loopexit = landingpad { ptr, i32 }
          cleanup
  br label %25

.loopexit.split-lp:                               ; preds = %2
  %lpad.loopexit.split-lp = landingpad { ptr, i32 }
          cleanup
  br label %25

10:                                               ; preds = %3
  %11 = landingpad { ptr, i32 }
          cleanup
  br label %25

12:                                               ; preds = %8, %6
  %13 = add nuw nsw i32 %.018, 1
  %exitcond.not = icmp eq i32 %13, 1000
  br i1 %exitcond.not, label %.preheader, label %2, !llvm.loop !5

.preheader:                                       ; preds = %12, %22
  %.119 = phi i32 [ %23, %22 ], [ 0, %12 ]
  invoke void @_ZN3alg5BTree9DeleteKeyEi(ptr noundef nonnull align 4 dereferenceable(4) %1, i32 noundef %.119)
          to label %14 unwind label %.loopexit

14:                                               ; preds = %.preheader
  %15 = invoke i64 @_ZN3alg5BTree6SearchEi(ptr noundef nonnull align 4 dereferenceable(4) %1, i32 noundef %.119)
          to label %16 unwind label %20

16:                                               ; preds = %14
  %17 = icmp ugt i64 %15, -4294967297
  br i1 %17, label %18, label %22

18:                                               ; preds = %16
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %.119)
  br label %22

20:                                               ; preds = %14
  %21 = landingpad { ptr, i32 }
          cleanup
  br label %25

22:                                               ; preds = %18, %16
  %23 = add nuw nsw i32 %.119, 1
  %exitcond20.not = icmp eq i32 %23, 1000
  br i1 %exitcond20.not, label %24, label %.preheader, !llvm.loop !7

24:                                               ; preds = %22
  call void @_ZN3alg5BTreeD2Ev(ptr noundef nonnull align 4 dereferenceable(4) %1) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 0

25:                                               ; preds = %.loopexit, %.loopexit.split-lp, %20, %10
  %.pn = phi { ptr, i32 } [ %11, %10 ], [ %21, %20 ], [ %lpad.loopexit, %.loopexit ], [ %lpad.loopexit.split-lp, %.loopexit.split-lp ]
  call void @_ZN3alg5BTreeD2Ev(ptr noundef nonnull align 4 dereferenceable(4) %1) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  resume { ptr, i32 } %.pn
}

; Function Attrs: mustprogress 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 void @_ZN3alg5BTreeC2EPKc(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef) unnamed_addr #2 align 2

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3alg5BTreeD2Ev(ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #4 align 2

attributes #0 = { mustprogress norecurse 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass