; LLVM IR from MostafaTwfiq/C-DataStructures-And-Algorithms :: DataStructure/Trees/Sources (BinaryHeap)

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @binaryHeapGetFChildIndex(i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @binaryHeapGetSChildIndex(i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @binaryHeapGetR(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = load i32, ptr %9, align 4, !tbaa !9
  %16 = icmp sge i32 %14, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %5
  store ptr null, ptr %6, align 8
  br label %69

18:                                               ; preds = %5
  %19 = load ptr, ptr %11, align 8, !tbaa !5
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds ptr, ptr %21, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  %26 = call i32 %19(ptr noundef %20, ptr noundef %25)
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %34

28:                                               ; preds = %18
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds ptr, ptr %29, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  store ptr %33, ptr %6, align 8
  br label %69

34:                                               ; preds = %18
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds ptr, ptr %37, i64 %39
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = call i32 %35(ptr noundef %36, ptr noundef %41)
  %43 = icmp sgt i32 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %34
  store ptr null, ptr %6, align 8
  br label %69

45:                                               ; preds = %34
  br label %46

46:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = call i32 @binaryHeapGetFChildIndex(i32 noundef %48)
  %50 = load i32, ptr %9, align 4, !tbaa !9
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = call ptr @binaryHeapGetR(ptr noundef %47, i32 noundef %49, i32 noundef %50, ptr noundef %51, ptr noundef %52)
  store ptr %53, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #2
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !9
  %56 = call i32 @binaryHeapGetSChildIndex(i32 noundef %55)
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = call ptr @binaryHeapGetR(ptr noundef %54, i32 noundef %56, i32 noundef %57, ptr noundef %58, ptr noundef %59)
  store ptr %60, ptr %13, align 8, !tbaa !5
  %61 = load ptr, ptr %12, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %65

63:                                               ; preds = %46
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  br label %67

65:                                               ; preds = %46
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  br label %67

67:                                               ; preds = %65, %63
  %68 = phi ptr [ %64, %63 ], [ %66, %65 ]
  store ptr %68, ptr %6, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %69

69:                                               ; preds = %67, %44, %28, %17
  %70 = load ptr, ptr %6, align 8
  ret ptr %70
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local i32 @binaryHeapGetFChildIndex(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @binaryHeapGetSChildIndex(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @binaryHeapGetR(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %.not = icmp slt i32 %1, %2
  br i1 %.not, label %6, label %common.ret28

6:                                                ; preds = %5
  %7 = sext i32 %1 to i64
  %8 = getelementptr inbounds ptr, ptr %0, i64 %7
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = tail call i32 %4(ptr noundef %3, ptr noundef %9) #1
  %11 = icmp eq i32 %10, 0
  %12 = load ptr, ptr %8, align 8, !tbaa !5
  br i1 %11, label %common.ret28, label %13

13:                                               ; preds = %6
  %14 = tail call i32 %4(ptr noundef %3, ptr noundef %12) #1
  %15 = icmp sgt i32 %14, 0
  br i1 %15, label %common.ret28, label %16

common.ret28:                                     ; preds = %13, %5, %6, %16
  %common.ret28.op = phi ptr [ %21, %16 ], [ null, %5 ], [ null, %13 ], [ %12, %6 ]
  ret ptr %common.ret28.op

16:                                               ; preds = %13
  %17 = tail call i32 @binaryHeapGetFChildIndex(i32 noundef %1)
  %18 = tail call ptr @binaryHeapGetR(ptr noundef nonnull %0, i32 noundef %17, i32 noundef %2, ptr noundef %3, ptr noundef %4)
  %19 = tail call i32 @binaryHeapGetSChildIndex(i32 noundef %1)
  %20 = tail call ptr @binaryHeapGetR(ptr noundef nonnull %0, i32 noundef %19, i32 noundef %2, ptr noundef %3, ptr noundef %4)
  %.not27 = icmp eq ptr %18, null
  %21 = select i1 %.not27, ptr %20, ptr %18
  br label %common.ret28
}

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


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