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

; 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 i32 @get_left_index(ptr noundef, ptr noundef) #1

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

18:                                               ; preds = %4
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = load i16, ptr %8, align 2, !tbaa !9
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = call ptr @insert_into_new_root(ptr noundef %19, i16 noundef zeroext %20, ptr noundef %21)
  store ptr %22, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %48

23:                                               ; preds = %4
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = call i32 @get_left_index(ptr noundef %24, ptr noundef %25)
  store i32 %26, ptr %10, align 4, !tbaa !14
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.node, ptr %27, i32 0, i32 4
  %29 = load i16, ptr %28, align 2, !tbaa !16
  %30 = zext i16 %29 to i32
  %31 = load i32, ptr @order, align 4, !tbaa !14
  %32 = sub nsw i32 %31, 1
  %33 = icmp slt i32 %30, %32
  br i1 %33, label %34, label %41

34:                                               ; preds = %23
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = load i32, ptr %10, align 4, !tbaa !14
  %38 = load i16, ptr %8, align 2, !tbaa !9
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = call ptr @insert_into_node(ptr noundef %35, ptr noundef %36, i32 noundef %37, i16 noundef zeroext %38, ptr noundef %39)
  store ptr %40, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %48

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

48:                                               ; preds = %41, %34, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  %49 = load ptr, ptr %5, align 8
  ret ptr %49
}

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

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

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

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, !6, i64 16}
!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}
!16 = !{!12, !10, i64 26}


; 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 i32 @get_left_index(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @insert_into_parent(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %10

8:                                                ; preds = %4
  %9 = tail call ptr @insert_into_new_root(ptr noundef nonnull %1, i16 noundef zeroext %2, ptr noundef %3)
  br label %22

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

18:                                               ; preds = %10
  %19 = tail call ptr @insert_into_node(ptr noundef %0, ptr noundef nonnull %6, i32 noundef %11, i16 noundef zeroext %2, ptr noundef %3)
  br label %22

20:                                               ; preds = %10
  %21 = tail call ptr @insert_into_node_after_splitting(ptr noundef %0, ptr noundef nonnull %6, i32 noundef %11, i16 noundef zeroext %2, ptr noundef %3)
  br label %22

22:                                               ; preds = %20, %18, %8
  %.0 = phi ptr [ %9, %8 ], [ %19, %18 ], [ %21, %20 ]
  ret ptr %.0
}

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @insert_into_new_root(ptr noundef, i16 noundef zeroext, ptr noundef) local_unnamed_addr #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, !7, i64 16}
!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 = !{!6, !11, i64 26}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !8, i64 0}


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