; LLVM IR from mahendramahara/DSA-in-C-Programing :: TREE (B-Tree-Implementation)

; 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.BTreeNode = type { [4 x i32], i32, [4 x ptr] }

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; 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 void @insertNode(i32 noundef, i32 noundef, ptr noundef, ptr noundef) #2

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

17:                                               ; preds = %6
  store i32 3, ptr %13, align 4, !tbaa !5
  br label %19

18:                                               ; preds = %6
  store i32 2, ptr %13, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %18, %17
  %20 = call noalias ptr @malloc(i64 noundef 56) #4
  %21 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %20, ptr %21, align 8, !tbaa !9
  %22 = load i32, ptr %13, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %14, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %27, %19
  %25 = load i32, ptr %14, align 4, !tbaa !5
  %26 = icmp sle i32 %25, 3
  br i1 %26, label %27, label %58

27:                                               ; preds = %24
  %28 = load ptr, ptr %10, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.BTreeNode, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %14, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [4 x i32], ptr %29, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = load ptr, ptr %12, align 8, !tbaa !9
  %35 = load ptr, ptr %34, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.BTreeNode, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %14, align 4, !tbaa !5
  %38 = load i32, ptr %13, align 4, !tbaa !5
  %39 = sub nsw i32 %37, %38
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [4 x i32], ptr %36, i64 0, i64 %40
  store i32 %33, ptr %41, align 4, !tbaa !5
  %42 = load ptr, ptr %10, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.BTreeNode, ptr %42, i32 0, i32 2
  %44 = load i32, ptr %14, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [4 x ptr], ptr %43, i64 0, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  %48 = load ptr, ptr %12, align 8, !tbaa !9
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  %50 = getelementptr inbounds %struct.BTreeNode, ptr %49, i32 0, i32 2
  %51 = load i32, ptr %14, align 4, !tbaa !5
  %52 = load i32, ptr %13, align 4, !tbaa !5
  %53 = sub nsw i32 %51, %52
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [4 x ptr], ptr %50, i64 0, i64 %54
  store ptr %47, ptr %55, align 8, !tbaa !9
  %56 = load i32, ptr %14, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %14, align 4, !tbaa !5
  br label %24, !llvm.loop !11

58:                                               ; preds = %24
  %59 = load i32, ptr %13, align 4, !tbaa !5
  %60 = load ptr, ptr %10, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.BTreeNode, ptr %60, i32 0, i32 1
  store i32 %59, ptr %61, align 8, !tbaa !13
  %62 = load i32, ptr %13, align 4, !tbaa !5
  %63 = sub nsw i32 3, %62
  %64 = load ptr, ptr %12, align 8, !tbaa !9
  %65 = load ptr, ptr %64, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.BTreeNode, ptr %65, i32 0, i32 1
  store i32 %63, ptr %66, align 8, !tbaa !13
  %67 = load i32, ptr %9, align 4, !tbaa !5
  %68 = icmp sle i32 %67, 2
  br i1 %68, label %69, label %74

69:                                               ; preds = %58
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = load i32, ptr %9, align 4, !tbaa !5
  %72 = load ptr, ptr %10, align 8, !tbaa !9
  %73 = load ptr, ptr %11, align 8, !tbaa !9
  call void @insertNode(i32 noundef %70, i32 noundef %71, ptr noundef %72, ptr noundef %73)
  br label %82

74:                                               ; preds = %58
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = load i32, ptr %9, align 4, !tbaa !5
  %77 = load i32, ptr %13, align 4, !tbaa !5
  %78 = sub nsw i32 %76, %77
  %79 = load ptr, ptr %12, align 8, !tbaa !9
  %80 = load ptr, ptr %79, align 8, !tbaa !9
  %81 = load ptr, ptr %11, align 8, !tbaa !9
  call void @insertNode(i32 noundef %75, i32 noundef %78, ptr noundef %80, ptr noundef %81)
  br label %82

82:                                               ; preds = %74, %69
  %83 = load ptr, ptr %10, align 8, !tbaa !9
  %84 = getelementptr inbounds %struct.BTreeNode, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %10, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.BTreeNode, ptr %85, i32 0, i32 1
  %87 = load i32, ptr %86, align 8, !tbaa !13
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [4 x i32], ptr %84, i64 0, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !5
  %91 = load ptr, ptr %8, align 8, !tbaa !9
  store i32 %90, ptr %91, align 4, !tbaa !5
  %92 = load ptr, ptr %10, align 8, !tbaa !9
  %93 = getelementptr inbounds %struct.BTreeNode, ptr %92, i32 0, i32 2
  %94 = load ptr, ptr %10, align 8, !tbaa !9
  %95 = getelementptr inbounds %struct.BTreeNode, ptr %94, i32 0, i32 1
  %96 = load i32, ptr %95, align 8, !tbaa !13
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [4 x ptr], ptr %93, i64 0, i64 %97
  %99 = load ptr, ptr %98, align 8, !tbaa !9
  %100 = load ptr, ptr %12, align 8, !tbaa !9
  %101 = load ptr, ptr %100, align 8, !tbaa !9
  %102 = getelementptr inbounds %struct.BTreeNode, ptr %101, i32 0, i32 2
  %103 = getelementptr inbounds [4 x ptr], ptr %102, i64 0, i64 0
  store ptr %99, ptr %103, align 8, !tbaa !9
  %104 = load ptr, ptr %10, align 8, !tbaa !9
  %105 = getelementptr inbounds %struct.BTreeNode, ptr %104, i32 0, i32 1
  %106 = load i32, ptr %105, align 8, !tbaa !13
  %107 = add nsw i32 %106, -1
  store i32 %107, ptr %105, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind 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 = { 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 }
attributes #4 = { nounwind 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 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !6, i64 16}
!14 = !{!"BTreeNode", !7, i64 0, !6, i64 16, !7, i64 24}


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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @insertNode(i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @splitNode(i32 noundef %0, ptr nocapture noundef writeonly %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, ptr nocapture noundef %5) local_unnamed_addr #1 {
  %7 = icmp slt i32 %2, 3
  %8 = tail call noalias dereferenceable_or_null(56) ptr @malloc(i64 noundef 56) #2
  store ptr %8, ptr %5, align 8, !tbaa !5
  br i1 %7, label %9, label %18

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %3, i64 12
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %8, i64 4
  store i32 %11, ptr %12, align 4, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %3, i64 48
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %8, i64 32
  store ptr %14, ptr %15, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %3, i64 16
  store i32 2, ptr %16, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %8, i64 16
  store i32 1, ptr %17, align 8, !tbaa !11
  tail call void @insertNode(i32 noundef %0, i32 noundef %2, ptr noundef %3, ptr noundef %4)
  br label %22

18:                                               ; preds = %6
  %19 = getelementptr inbounds i8, ptr %3, i64 16
  store i32 3, ptr %19, align 8, !tbaa !11
  %20 = getelementptr inbounds i8, ptr %8, i64 16
  store i32 0, ptr %20, align 8, !tbaa !11
  %21 = add nsw i32 %2, -3
  tail call void @insertNode(i32 noundef %0, i32 noundef %21, ptr noundef %8, ptr noundef %4)
  br label %22

22:                                               ; preds = %18, %9
  %23 = phi ptr [ %19, %18 ], [ %16, %9 ]
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [4 x i32], ptr %3, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !9
  store i32 %27, ptr %1, align 4, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %3, i64 24
  %29 = load i32, ptr %23, align 8, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [4 x ptr], ptr %28, i64 0, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 24
  store ptr %32, ptr %34, align 8, !tbaa !5
  %35 = add nsw i32 %29, -1
  store i32 %35, ptr %23, align 8, !tbaa !11
  ret void
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 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 = !{!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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"BTreeNode", !7, i64 0, !10, i64 16, !7, i64 24}


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