; LLVM IR from FOSS-UCSC/FOSSALGO :: data-structures/ds-btree/c (binary_search_tree)

; 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 { i32, ptr, ptr }

@ptr1 = external dso_local global ptr, align 8
@ptr2 = external dso_local global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [15 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

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

; Function Attrs: nounwind uwtable
declare dso_local void @largest(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @deleteele(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  br label %7

7:                                                ; preds = %28, %2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.node, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = load i32, ptr %4, align 4, !tbaa !9
  %12 = icmp ne i32 %10, %11
  br i1 %12, label %13, label %29

13:                                               ; preds = %7
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %14, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.node, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = icmp sgt i32 %17, %18
  br i1 %19, label %20, label %24

20:                                               ; preds = %13
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.node, ptr %21, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  store ptr %23, ptr %3, align 8, !tbaa !5
  br label %28

24:                                               ; preds = %13
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.node, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  store ptr %27, ptr %3, align 8, !tbaa !5
  br label %28

28:                                               ; preds = %24, %20
  br label %7, !llvm.loop !15

29:                                               ; preds = %7
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.node, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 8, !tbaa !11
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %32)
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.node, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !11
  %37 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %36)
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.node, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %61

42:                                               ; preds = %29
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.node, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = icmp eq ptr %45, null
  br i1 %46, label %47, label %61

47:                                               ; preds = %42
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.node, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = icmp eq ptr %50, %51
  br i1 %52, label %53, label %56

53:                                               ; preds = %47
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.node, ptr %54, i32 0, i32 2
  store ptr null, ptr %55, align 8, !tbaa !13
  br label %59

56:                                               ; preds = %47
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.node, ptr %57, i32 0, i32 1
  store ptr null, ptr %58, align 8, !tbaa !14
  br label %59

59:                                               ; preds = %56, %53
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %60) #4
  br label %162

61:                                               ; preds = %42, %29
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.node, ptr %62, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8, !tbaa !13
  %65 = icmp eq ptr %64, null
  br i1 %65, label %66, label %71

66:                                               ; preds = %61
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.node, ptr %67, i32 0, i32 1
  %69 = load ptr, ptr %68, align 8, !tbaa !14
  %70 = icmp ne ptr %69, null
  br i1 %70, label %81, label %71

71:                                               ; preds = %66, %61
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.node, ptr %72, i32 0, i32 2
  %74 = load ptr, ptr %73, align 8, !tbaa !13
  %75 = icmp ne ptr %74, null
  br i1 %75, label %76, label %143

76:                                               ; preds = %71
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.node, ptr %77, i32 0, i32 1
  %79 = load ptr, ptr %78, align 8, !tbaa !14
  %80 = icmp eq ptr %79, null
  br i1 %80, label %81, label %143

81:                                               ; preds = %76, %66
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.node, ptr %82, i32 0, i32 2
  %84 = load ptr, ptr %83, align 8, !tbaa !13
  %85 = icmp ne ptr %84, null
  br i1 %85, label %86, label %111

86:                                               ; preds = %81
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.node, ptr %88, i32 0, i32 2
  %90 = load ptr, ptr %89, align 8, !tbaa !13
  %91 = icmp eq ptr %87, %90
  br i1 %91, label %92, label %101

92:                                               ; preds = %86
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.node, ptr %93, i32 0, i32 2
  %95 = load ptr, ptr %94, align 8, !tbaa !13
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.node, ptr %96, i32 0, i32 2
  store ptr %95, ptr %97, align 8, !tbaa !13
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.node, ptr %98, i32 0, i32 2
  store ptr null, ptr %99, align 8, !tbaa !13
  %100 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %100) #4
  br label %110

101:                                              ; preds = %86
  %102 = load ptr, ptr %3, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.node, ptr %102, i32 0, i32 2
  %104 = load ptr, ptr %103, align 8, !tbaa !13
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.node, ptr %105, i32 0, i32 1
  store ptr %104, ptr %106, align 8, !tbaa !14
  %107 = load ptr, ptr %3, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.node, ptr %107, i32 0, i32 2
  store ptr null, ptr %108, align 8, !tbaa !13
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %109) #4
  br label %110

110:                                              ; preds = %101, %92
  br label %142

111:                                              ; preds = %81
  %112 = load ptr, ptr %3, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.node, ptr %112, i32 0, i32 1
  %114 = load ptr, ptr %113, align 8, !tbaa !14
  %115 = icmp ne ptr %114, null
  br i1 %115, label %116, label %141

116:                                              ; preds = %111
  %117 = load ptr, ptr %3, align 8, !tbaa !5
  %118 = load ptr, ptr %5, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.node, ptr %118, i32 0, i32 2
  %120 = load ptr, ptr %119, align 8, !tbaa !13
  %121 = icmp eq ptr %117, %120
  br i1 %121, label %122, label %131

122:                                              ; preds = %116
  %123 = load ptr, ptr %3, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.node, ptr %123, i32 0, i32 1
  %125 = load ptr, ptr %124, align 8, !tbaa !14
  %126 = load ptr, ptr %5, align 8, !tbaa !5
  %127 = getelementptr inbounds %struct.node, ptr %126, i32 0, i32 2
  store ptr %125, ptr %127, align 8, !tbaa !13
  %128 = load ptr, ptr %3, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.node, ptr %128, i32 0, i32 1
  store ptr null, ptr %129, align 8, !tbaa !14
  %130 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %130) #4
  br label %140

131:                                              ; preds = %116
  %132 = load ptr, ptr %3, align 8, !tbaa !5
  %133 = getelementptr inbounds %struct.node, ptr %132, i32 0, i32 1
  %134 = load ptr, ptr %133, align 8, !tbaa !14
  %135 = load ptr, ptr %5, align 8, !tbaa !5
  %136 = getelementptr inbounds %struct.node, ptr %135, i32 0, i32 1
  store ptr %134, ptr %136, align 8, !tbaa !14
  %137 = load ptr, ptr %3, align 8, !tbaa !5
  %138 = getelementptr inbounds %struct.node, ptr %137, i32 0, i32 1
  store ptr null, ptr %138, align 8, !tbaa !14
  %139 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %139) #4
  br label %140

140:                                              ; preds = %131, %122
  br label %141

141:                                              ; preds = %140, %111
  br label %142

142:                                              ; preds = %141, %110
  br label %161

143:                                              ; preds = %76, %71
  %144 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %144, ptr %6, align 8, !tbaa !5
  %145 = load ptr, ptr %3, align 8, !tbaa !5
  %146 = getelementptr inbounds %struct.node, ptr %145, i32 0, i32 2
  %147 = load ptr, ptr %146, align 8, !tbaa !13
  call void @largest(ptr noundef %147)
  %148 = load ptr, ptr @ptr1, align 8, !tbaa !5
  %149 = getelementptr inbounds %struct.node, ptr %148, i32 0, i32 0
  %150 = load i32, ptr %149, align 8, !tbaa !11
  %151 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, i32 noundef %150)
  %152 = load ptr, ptr @ptr1, align 8, !tbaa !5
  %153 = getelementptr inbounds %struct.node, ptr %152, i32 0, i32 0
  %154 = load i32, ptr %153, align 8, !tbaa !11
  %155 = load ptr, ptr %6, align 8, !tbaa !5
  %156 = getelementptr inbounds %struct.node, ptr %155, i32 0, i32 0
  store i32 %154, ptr %156, align 8, !tbaa !11
  %157 = load ptr, ptr @ptr2, align 8, !tbaa !5
  %158 = load ptr, ptr @ptr1, align 8, !tbaa !5
  %159 = getelementptr inbounds %struct.node, ptr %158, i32 0, i32 0
  %160 = load i32, ptr %159, align 8, !tbaa !11
  call void @deleteele(ptr noundef %157, i32 noundef %160)
  br label %161

161:                                              ; preds = %143, %142
  br label %162

162:                                              ; preds = %161, %59
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 "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 #4 = { 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 = !{!"node", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 16}
!14 = !{!12, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@ptr1 = external dso_local local_unnamed_addr global ptr, align 8
@ptr2 = external dso_local local_unnamed_addr global ptr, align 8
@.str.5 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [15 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @deleteele(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %.thread53, %2
  %.tr = phi ptr [ %0, %2 ], [ %41, %.thread53 ]
  %.tr55 = phi i32 [ %1, %2 ], [ %40, %.thread53 ]
  %3 = load i32, ptr %.tr, align 8, !tbaa !5
  %.not65 = icmp ne i32 %3, %.tr55
  tail call void @llvm.assume(i1 %.not65)
  br label %.lr.ph

.lr.ph:                                           ; preds = %tailrecurse, %.lr.ph
  %4 = phi i32 [ %6, %.lr.ph ], [ %3, %tailrecurse ]
  %.066 = phi ptr [ %.1, %.lr.ph ], [ %.tr, %tailrecurse ]
  %5 = icmp sgt i32 %4, %.tr55
  %.1.in.v = select i1 %5, i64 16, i64 8
  %.1.in = getelementptr inbounds i8, ptr %.066, i64 %.1.in.v
  %.1 = load ptr, ptr %.1.in, align 8, !tbaa !11
  %6 = load i32, ptr %.1, align 8, !tbaa !5
  %.not = icmp eq i32 %6, %.tr55
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph
  %7 = load i32, ptr %.066, align 8, !tbaa !5
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %7)
  %9 = load i32, ptr %.1, align 8, !tbaa !5
  %10 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %9)
  %11 = getelementptr inbounds i8, ptr %.1, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = icmp eq ptr %12, null
  %14 = getelementptr inbounds i8, ptr %.1, i64 8
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = icmp eq ptr %15, null
  br i1 %13, label %17, label %23

17:                                               ; preds = %._crit_edge
  %18 = getelementptr inbounds i8, ptr %.066, i64 16
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  br i1 %16, label %20, label %31

20:                                               ; preds = %17
  %21 = icmp eq ptr %19, %.1
  %22 = getelementptr inbounds i8, ptr %.066, i64 8
  %.sink = select i1 %21, ptr %18, ptr %22
  store ptr null, ptr %.sink, align 8, !tbaa !11
  br label %42

23:                                               ; preds = %._crit_edge
  br i1 %16, label %24, label %.thread53

24:                                               ; preds = %23
  %25 = getelementptr inbounds i8, ptr %.066, i64 16
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = icmp eq ptr %.1, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  store ptr %12, ptr %25, align 8, !tbaa !14
  br label %42

29:                                               ; preds = %24
  %30 = getelementptr inbounds i8, ptr %.066, i64 8
  store ptr %12, ptr %30, align 8, !tbaa !15
  br label %42

31:                                               ; preds = %17
  %32 = icmp eq ptr %.1, %19
  br i1 %32, label %33, label %34

33:                                               ; preds = %31
  store ptr %15, ptr %18, align 8, !tbaa !14
  br label %42

34:                                               ; preds = %31
  %35 = getelementptr inbounds i8, ptr %.066, i64 8
  store ptr %15, ptr %35, align 8, !tbaa !15
  br label %42

.thread53:                                        ; preds = %23
  tail call void @largest(ptr noundef nonnull %12)
  %36 = load ptr, ptr @ptr1, align 8, !tbaa !11
  %37 = load i32, ptr %36, align 8, !tbaa !5
  %38 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, i32 noundef %37)
  %39 = load ptr, ptr @ptr1, align 8, !tbaa !11
  %40 = load i32, ptr %39, align 8, !tbaa !5
  store i32 %40, ptr %.1, align 8, !tbaa !5
  %41 = load ptr, ptr @ptr2, align 8, !tbaa !11
  br label %tailrecurse

42:                                               ; preds = %34, %33, %28, %29, %20
  tail call void @free(ptr noundef nonnull %.1) #4
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)
declare void @llvm.assume(i1 noundef) #3

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


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass