; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/evaluation/src/sglib_rbtree/rbtree.ll_sglib_ (rbtree_delete_recursive)

; 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.rbtree = type { i32, i8, ptr, ptr }

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

14:                                               ; preds = %2
  br label %137

15:                                               ; preds = %2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.rbtree, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !11
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.rbtree, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = sub nsw i32 %18, %21
  store i32 %22, ptr %7, align 4, !tbaa !9
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %32, label %25

25:                                               ; preds = %15
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %43

28:                                               ; preds = %25
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = icmp ult ptr %29, %30
  br i1 %31, label %32, label %43

32:                                               ; preds = %28, %15
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.rbtree, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = call i32 @sglib___rbtree_delete_recursive(ptr noundef %34, ptr noundef %35)
  store i32 %36, ptr %9, align 4, !tbaa !9
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %32
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = call i32 @sglib___rbtree_fix_left_deletion_discrepancy(ptr noundef %40)
  store i32 %41, ptr %8, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %39, %32
  br label %136

43:                                               ; preds = %28, %25
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = icmp sgt i32 %44, 0
  br i1 %45, label %53, label %46

46:                                               ; preds = %43
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %64

49:                                               ; preds = %46
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = icmp ugt ptr %50, %51
  br i1 %52, label %53, label %64

53:                                               ; preds = %49, %43
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.rbtree, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = call i32 @sglib___rbtree_delete_recursive(ptr noundef %55, ptr noundef %56)
  store i32 %57, ptr %9, align 4, !tbaa !9
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %63

60:                                               ; preds = %53
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = call i32 @sglib___rbtree_fix_right_deletion_discrepancy(ptr noundef %61)
  store i32 %62, ptr %8, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %60, %53
  br label %135

64:                                               ; preds = %49, %46
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.rbtree, ptr %65, i32 0, i32 2
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = icmp eq ptr %67, null
  br i1 %68, label %69, label %107

69:                                               ; preds = %64
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.rbtree, ptr %70, i32 0, i32 3
  %72 = load ptr, ptr %71, align 8, !tbaa !14
  %73 = icmp eq ptr %72, null
  br i1 %73, label %74, label %82

74:                                               ; preds = %69
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr null, ptr %75, align 8, !tbaa !5
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.rbtree, ptr %76, i32 0, i32 1
  %78 = load i8, ptr %77, align 4, !tbaa !15
  %79 = sext i8 %78 to i32
  %80 = icmp eq i32 %79, 0
  %81 = zext i1 %80 to i32
  store i32 %81, ptr %8, align 4, !tbaa !9
  br label %106

82:                                               ; preds = %69
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.rbtree, ptr %83, i32 0, i32 1
  %85 = load i8, ptr %84, align 4, !tbaa !15
  %86 = sext i8 %85 to i32
  %87 = icmp eq i32 %86, 0
  br i1 %87, label %88, label %97

88:                                               ; preds = %82
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.rbtree, ptr %89, i32 0, i32 3
  %91 = load ptr, ptr %90, align 8, !tbaa !14
  %92 = getelementptr inbounds %struct.rbtree, ptr %91, i32 0, i32 1
  %93 = load i8, ptr %92, align 4, !tbaa !15
  %94 = sext i8 %93 to i32
  %95 = icmp eq i32 %94, 0
  br i1 %95, label %96, label %97

96:                                               ; preds = %88
  store i32 1, ptr %8, align 4, !tbaa !9
  br label %97

97:                                               ; preds = %96, %88, %82
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.rbtree, ptr %98, i32 0, i32 3
  %100 = load ptr, ptr %99, align 8, !tbaa !14
  %101 = getelementptr inbounds %struct.rbtree, ptr %100, i32 0, i32 1
  store i8 0, ptr %101, align 4, !tbaa !15
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.rbtree, ptr %102, i32 0, i32 3
  %104 = load ptr, ptr %103, align 8, !tbaa !14
  %105 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %104, ptr %105, align 8, !tbaa !5
  br label %106

106:                                              ; preds = %97, %74
  br label %134

107:                                              ; preds = %64
  %108 = load ptr, ptr %5, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.rbtree, ptr %108, i32 0, i32 2
  %110 = call i32 @sglib___rbtree_delete_rightmost_leaf(ptr noundef %109, ptr noundef %6)
  store i32 %110, ptr %9, align 4, !tbaa !9
  %111 = load ptr, ptr %5, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.rbtree, ptr %111, i32 0, i32 2
  %113 = load ptr, ptr %112, align 8, !tbaa !13
  %114 = load ptr, ptr %6, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.rbtree, ptr %114, i32 0, i32 2
  store ptr %113, ptr %115, align 8, !tbaa !13
  %116 = load ptr, ptr %5, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.rbtree, ptr %116, i32 0, i32 3
  %118 = load ptr, ptr %117, align 8, !tbaa !14
  %119 = load ptr, ptr %6, align 8, !tbaa !5
  %120 = getelementptr inbounds %struct.rbtree, ptr %119, i32 0, i32 3
  store ptr %118, ptr %120, align 8, !tbaa !14
  %121 = load ptr, ptr %5, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.rbtree, ptr %121, i32 0, i32 1
  %123 = load i8, ptr %122, align 4, !tbaa !15
  %124 = load ptr, ptr %6, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.rbtree, ptr %124, i32 0, i32 1
  store i8 %123, ptr %125, align 4, !tbaa !15
  %126 = load ptr, ptr %6, align 8, !tbaa !5
  %127 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %126, ptr %127, align 8, !tbaa !5
  %128 = load i32, ptr %9, align 4, !tbaa !9
  %129 = icmp ne i32 %128, 0
  br i1 %129, label %130, label %133

130:                                              ; preds = %107
  %131 = load ptr, ptr %3, align 8, !tbaa !5
  %132 = call i32 @sglib___rbtree_fix_left_deletion_discrepancy(ptr noundef %131)
  store i32 %132, ptr %8, align 4, !tbaa !9
  br label %133

133:                                              ; preds = %130, %107
  br label %134

134:                                              ; preds = %133, %106
  br label %135

135:                                              ; preds = %134, %63
  br label %136

136:                                              ; preds = %135, %42
  br label %137

137:                                              ; preds = %136, %14
  %138 = load i32, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i32 %138
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @sglib___rbtree_fix_left_deletion_discrepancy(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @sglib___rbtree_fix_right_deletion_discrepancy(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @sglib___rbtree_delete_rightmost_leaf(ptr noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { 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}
!11 = !{!12, !10, i64 0}
!12 = !{!"rbtree", !10, i64 0, !7, i64 4, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !7, i64 4}


; 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
define dso_local i32 @sglib___rbtree_delete_recursive(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #2
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %58, label %6

6:                                                ; preds = %2
  %7 = load i32, ptr %1, align 8, !tbaa !9
  %8 = load i32, ptr %4, align 8, !tbaa !9
  %9 = icmp slt i32 %7, %8
  br i1 %9, label %13, label %10

10:                                               ; preds = %6
  %11 = icmp eq i32 %7, %8
  %12 = icmp ugt ptr %4, %1
  %or.cond = and i1 %12, %11
  br i1 %or.cond, label %13, label %18

13:                                               ; preds = %10, %6
  %14 = getelementptr inbounds i8, ptr %4, i64 8
  %15 = tail call i32 @sglib___rbtree_delete_recursive(ptr noundef nonnull %14, ptr noundef nonnull %1)
  %.not41 = icmp eq i32 %15, 0
  br i1 %.not41, label %58, label %16

16:                                               ; preds = %13
  %17 = tail call i32 @sglib___rbtree_fix_left_deletion_discrepancy(ptr noundef nonnull %0)
  br label %58

18:                                               ; preds = %10
  %.not = icmp ne i32 %7, %8
  %19 = icmp ult ptr %4, %1
  %or.cond42 = or i1 %19, %.not
  br i1 %or.cond42, label %20, label %25

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %4, i64 16
  %22 = tail call i32 @sglib___rbtree_delete_recursive(ptr noundef nonnull %21, ptr noundef nonnull %1)
  %.not40 = icmp eq i32 %22, 0
  br i1 %.not40, label %58, label %23

23:                                               ; preds = %20
  %24 = tail call i32 @sglib___rbtree_fix_right_deletion_discrepancy(ptr noundef nonnull %0)
  br label %58

25:                                               ; preds = %18
  %26 = getelementptr inbounds i8, ptr %4, i64 8
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %48

29:                                               ; preds = %25
  %30 = getelementptr inbounds i8, ptr %4, i64 16
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %38

33:                                               ; preds = %29
  store ptr null, ptr %0, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %4, i64 4
  %35 = load i8, ptr %34, align 4, !tbaa !14
  %36 = icmp eq i8 %35, 0
  %37 = zext i1 %36 to i32
  br label %58

38:                                               ; preds = %29
  %39 = getelementptr inbounds i8, ptr %4, i64 4
  %40 = load i8, ptr %39, align 4, !tbaa !14
  %41 = icmp eq i8 %40, 0
  br i1 %41, label %42, label %46

42:                                               ; preds = %38
  %43 = getelementptr inbounds i8, ptr %31, i64 4
  %44 = load i8, ptr %43, align 4, !tbaa !14
  %45 = icmp eq i8 %44, 0
  %spec.select = zext i1 %45 to i32
  br label %46

46:                                               ; preds = %42, %38
  %.0 = phi i32 [ 0, %38 ], [ %spec.select, %42 ]
  %47 = getelementptr inbounds i8, ptr %31, i64 4
  store i8 0, ptr %47, align 4, !tbaa !14
  store ptr %31, ptr %0, align 8, !tbaa !5
  br label %58

48:                                               ; preds = %25
  %49 = call i32 @sglib___rbtree_delete_rightmost_leaf(ptr noundef nonnull %26, ptr noundef nonnull %3)
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds i8, ptr %50, i64 8
  %52 = load <2 x ptr>, ptr %26, align 8, !tbaa !5
  store <2 x ptr> %52, ptr %51, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %4, i64 4
  %54 = load i8, ptr %53, align 4, !tbaa !14
  %55 = getelementptr inbounds i8, ptr %50, i64 4
  store i8 %54, ptr %55, align 4, !tbaa !14
  store ptr %50, ptr %0, align 8, !tbaa !5
  %.not39 = icmp eq i32 %49, 0
  br i1 %.not39, label %58, label %56

56:                                               ; preds = %48
  %57 = call i32 @sglib___rbtree_fix_left_deletion_discrepancy(ptr noundef nonnull %0)
  br label %58

58:                                               ; preds = %16, %13, %46, %33, %56, %48, %20, %23, %2
  %.1 = phi i32 [ 0, %2 ], [ %17, %16 ], [ 0, %13 ], [ %24, %23 ], [ 0, %20 ], [ %37, %33 ], [ %.0, %46 ], [ %57, %56 ], [ 0, %48 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #2
  ret i32 %.1
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @sglib___rbtree_fix_left_deletion_discrepancy(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @sglib___rbtree_fix_right_deletion_discrepancy(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @sglib___rbtree_delete_rightmost_leaf(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress 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, !11, i64 0}
!10 = !{!"rbtree", !11, i64 0, !7, i64 4, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !7, i64 4}


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