; LLVM IR from artagnon/phoenixfs :: btree (insert)

; 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 { ptr, ptr, ptr, i8, i16, ptr }

@order = external dso_local global i32, align 4

; 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: nounwind uwtable
declare dso_local ptr @find_leaf(ptr noundef, i16 noundef zeroext, i1 noundef zeroext) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @find(ptr noundef, i16 noundef zeroext, i1 noundef zeroext) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @insert_into_leaf(ptr noundef, i16 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @insert_into_leaf_after_splitting(ptr noundef, ptr noundef, i16 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @start_new_tree(i16 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @insert(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i16 %1, ptr %6, align 2, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load i16, ptr %6, align 2, !tbaa !9
  %13 = call ptr @find(ptr noundef %11, i16 noundef zeroext %12, i1 noundef zeroext false)
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %17

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %16, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %48

17:                                               ; preds = %3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %18, ptr %8, align 8, !tbaa !5
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %25

21:                                               ; preds = %17
  %22 = load i16, ptr %6, align 2, !tbaa !9
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = call ptr @start_new_tree(i16 noundef zeroext %22, ptr noundef %23)
  store ptr %24, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %48

25:                                               ; preds = %17
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = load i16, ptr %6, align 2, !tbaa !9
  %28 = call ptr @find_leaf(ptr noundef %26, i16 noundef zeroext %27, i1 noundef zeroext false)
  store ptr %28, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.node, ptr %29, i32 0, i32 4
  %31 = load i16, ptr %30, align 2, !tbaa !11
  %32 = zext i16 %31 to i32
  %33 = load i32, ptr @order, align 4, !tbaa !14
  %34 = sub nsw i32 %33, 1
  %35 = icmp slt i32 %32, %34
  br i1 %35, label %36, label %42

36:                                               ; preds = %25
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = load i16, ptr %6, align 2, !tbaa !9
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = call ptr @insert_into_leaf(ptr noundef %37, i16 noundef zeroext %38, ptr noundef %39)
  store ptr %40, ptr %9, align 8, !tbaa !5
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %41, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %48

42:                                               ; preds = %25
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = load i16, ptr %6, align 2, !tbaa !9
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = call ptr @insert_into_leaf_after_splitting(ptr noundef %43, ptr noundef %44, i16 noundef zeroext %45, ptr noundef %46)
  store ptr %47, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %48

48:                                               ; preds = %42, %36, %21, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %49 = load ptr, ptr %4, align 8
  ret ptr %49
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !10, i64 26}
!12 = !{!"node", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !10, i64 26, !6, i64 32}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}


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

@order = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
declare dso_local ptr @find_leaf(ptr noundef, i16 noundef zeroext, i1 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @find(ptr noundef, i16 noundef zeroext, i1 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @insert_into_leaf(ptr noundef, i16 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @insert_into_leaf_after_splitting(ptr noundef, ptr noundef, i16 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @start_new_tree(i16 noundef zeroext, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @insert(ptr noundef %0, i16 noundef zeroext %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr @find(ptr noundef %0, i16 noundef zeroext %1, i1 noundef zeroext false)
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %5, label %21

5:                                                ; preds = %3
  %6 = icmp eq ptr %0, null
  br i1 %6, label %7, label %9

7:                                                ; preds = %5
  %8 = tail call ptr @start_new_tree(i16 noundef zeroext %1, ptr noundef %2)
  br label %21

9:                                                ; preds = %5
  %10 = tail call ptr @find_leaf(ptr noundef nonnull %0, i16 noundef zeroext %1, i1 noundef zeroext false)
  %11 = getelementptr inbounds i8, ptr %10, i64 26
  %12 = load i16, ptr %11, align 2, !tbaa !5
  %13 = zext i16 %12 to i32
  %14 = load i32, ptr @order, align 4, !tbaa !12
  %15 = add nsw i32 %14, -1
  %16 = icmp sgt i32 %15, %13
  br i1 %16, label %17, label %19

17:                                               ; preds = %9
  %18 = tail call ptr @insert_into_leaf(ptr noundef nonnull %10, i16 noundef zeroext %1, ptr noundef %2)
  br label %21

19:                                               ; preds = %9
  %20 = tail call ptr @insert_into_leaf_after_splitting(ptr noundef nonnull %0, ptr noundef nonnull %10, i16 noundef zeroext %1, ptr noundef %2)
  br label %21

21:                                               ; preds = %3, %19, %17, %7
  %.0 = phi ptr [ %8, %7 ], [ %0, %17 ], [ %20, %19 ], [ %0, %3 ]
  ret ptr %.0
}

attributes #0 = { 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, !11, i64 26}
!6 = !{!"node", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !11, i64 26, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_Bool", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !8, i64 0}


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