; 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] }

@.str = external hidden unnamed_addr constant [30 x i8], align 1

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

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

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

14:                                               ; preds = %4
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !9
  store i32 %15, ptr %16, align 4, !tbaa !5
  %17 = load ptr, ptr %9, align 8, !tbaa !9
  store ptr null, ptr %17, align 8, !tbaa !9
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %95

18:                                               ; preds = %4
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = load ptr, ptr %8, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.BTreeNode, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds [4 x i32], ptr %21, i64 0, i64 1
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = icmp slt i32 %19, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %18
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %60

26:                                               ; preds = %18
  %27 = load ptr, ptr %8, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.BTreeNode, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !11
  store i32 %29, ptr %10, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %45, %26
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = load ptr, ptr %8, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.BTreeNode, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %10, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [4 x i32], ptr %33, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = icmp slt i32 %31, %37
  br i1 %38, label %39, label %42

39:                                               ; preds = %30
  %40 = load i32, ptr %10, align 4, !tbaa !5
  %41 = icmp sgt i32 %40, 1
  br label %42

42:                                               ; preds = %39, %30
  %43 = phi i1 [ false, %30 ], [ %41, %39 ]
  br i1 %43, label %44, label %48

44:                                               ; preds = %42
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %10, align 4, !tbaa !5
  %47 = add nsw i32 %46, -1
  store i32 %47, ptr %10, align 4, !tbaa !5
  br label %30, !llvm.loop !13

48:                                               ; preds = %42
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = load ptr, ptr %8, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.BTreeNode, ptr %50, i32 0, i32 0
  %52 = load i32, ptr %10, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [4 x i32], ptr %51, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = icmp eq i32 %49, %55
  br i1 %56, label %57, label %59

57:                                               ; preds = %48
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %95

59:                                               ; preds = %48
  br label %60

60:                                               ; preds = %59, %25
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = load ptr, ptr %7, align 8, !tbaa !9
  %63 = load ptr, ptr %8, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.BTreeNode, ptr %63, i32 0, i32 2
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [4 x ptr], ptr %64, i64 0, i64 %66
  %68 = load ptr, ptr %67, align 8, !tbaa !9
  %69 = load ptr, ptr %9, align 8, !tbaa !9
  %70 = call i32 @setValue(i32 noundef %61, ptr noundef %62, ptr noundef %68, ptr noundef %69)
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %72, label %94

72:                                               ; preds = %60
  %73 = load ptr, ptr %8, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.BTreeNode, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 8, !tbaa !11
  %76 = icmp slt i32 %75, 3
  br i1 %76, label %77, label %84

77:                                               ; preds = %72
  %78 = load ptr, ptr %7, align 8, !tbaa !9
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = load i32, ptr %10, align 4, !tbaa !5
  %81 = load ptr, ptr %8, align 8, !tbaa !9
  %82 = load ptr, ptr %9, align 8, !tbaa !9
  %83 = load ptr, ptr %82, align 8, !tbaa !9
  call void @insertNode(i32 noundef %79, i32 noundef %80, ptr noundef %81, ptr noundef %83)
  br label %93

84:                                               ; preds = %72
  %85 = load ptr, ptr %7, align 8, !tbaa !9
  %86 = load i32, ptr %85, align 4, !tbaa !5
  %87 = load ptr, ptr %7, align 8, !tbaa !9
  %88 = load i32, ptr %10, align 4, !tbaa !5
  %89 = load ptr, ptr %8, align 8, !tbaa !9
  %90 = load ptr, ptr %9, align 8, !tbaa !9
  %91 = load ptr, ptr %90, align 8, !tbaa !9
  %92 = load ptr, ptr %9, align 8, !tbaa !9
  call void @splitNode(i32 noundef %86, ptr noundef %87, i32 noundef %88, ptr noundef %89, ptr noundef %91, ptr noundef %92)
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %95

93:                                               ; preds = %77
  br label %94

94:                                               ; preds = %93, %60
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %95

95:                                               ; preds = %94, %84, %57, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %96 = load i32, ptr %5, align 4
  ret i32 %96
}

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

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 = { "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 = !{!"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 = !{!12, !6, i64 16}
!12 = !{!"BTreeNode", !7, i64 0, !6, i64 16, !7, i64 24}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

@.str = external hidden unnamed_addr constant [30 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @setValue(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %5, label %6

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

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %2, i64 4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, %0
  br i1 %9, label %25, label %10

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %2, i64 16
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = sext i32 %12 to i64
  br label %14

14:                                               ; preds = %14, %10
  %indvars.iv = phi i64 [ %indvars.iv.next, %14 ], [ %13, %10 ]
  %15 = getelementptr inbounds [4 x i32], ptr %2, i64 0, i64 %indvars.iv
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = icmp sgt i32 %16, %0
  %18 = icmp sgt i64 %indvars.iv, 1
  %19 = and i1 %18, %17
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  br i1 %19, label %14, label %20, !llvm.loop !13

20:                                               ; preds = %14
  %21 = trunc nsw i64 %indvars.iv to i32
  %22 = icmp eq i32 %16, %0
  br i1 %22, label %23, label %25

23:                                               ; preds = %20
  %24 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %39

25:                                               ; preds = %6, %20
  %.1 = phi i32 [ %21, %20 ], [ 0, %6 ]
  %26 = getelementptr inbounds i8, ptr %2, i64 24
  %27 = sext i32 %.1 to i64
  %28 = getelementptr inbounds [4 x ptr], ptr %26, i64 0, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = tail call i32 @setValue(i32 noundef %0, ptr noundef %1, ptr noundef %29, ptr noundef %3)
  %.not34 = icmp eq i32 %30, 0
  br i1 %.not34, label %39, label %31

31:                                               ; preds = %25
  %32 = getelementptr inbounds i8, ptr %2, i64 16
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = icmp slt i32 %33, 3
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = load ptr, ptr %3, align 8, !tbaa !9
  br i1 %34, label %37, label %38

37:                                               ; preds = %31
  tail call void @insertNode(i32 noundef %35, i32 noundef %.1, ptr noundef nonnull %2, ptr noundef %36)
  br label %39

38:                                               ; preds = %31
  tail call void @splitNode(i32 noundef %35, ptr noundef nonnull %1, i32 noundef %.1, ptr noundef nonnull %2, ptr noundef %36, ptr noundef nonnull %3)
  br label %39

39:                                               ; preds = %25, %37, %38, %23, %5
  %.031 = phi i32 [ 1, %38 ], [ 0, %23 ], [ 1, %5 ], [ 0, %37 ], [ 0, %25 ]
  ret i32 %.031
}

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

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" }
attributes #1 = { 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" }

!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 = !{!12, !6, i64 16}
!12 = !{!"BTreeNode", !7, i64 0, !6, i64 16, !7, i64 24}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass