; LLVM IR from bartobri/data-structures-c :: symbol-table/B-tree (st)

; 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.STnode = type { [6 x %struct.entry], i32 }
%struct.entry = type { i32, %union.anon }
%union.anon = type { ptr }

; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

11:                                               ; preds = %3
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %56, %11
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.STnode, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = icmp slt i32 %13, %16
  br i1 %17, label %18, label %59

18:                                               ; preds = %12
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.STnode, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [6 x %struct.entry], ptr %21, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.entry, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !13
  %27 = icmp eq i32 %19, %26
  br i1 %27, label %28, label %55

28:                                               ; preds = %18
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.STnode, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !11
  %32 = sub nsw i32 %31, 1
  store i32 %32, ptr %30, align 8, !tbaa !11
  br label %33

33:                                               ; preds = %51, %28
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.STnode, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 8, !tbaa !11
  %38 = icmp slt i32 %34, %37
  br i1 %38, label %39, label %54

39:                                               ; preds = %33
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.STnode, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [6 x %struct.entry], ptr %41, i64 0, i64 %43
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.STnode, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [6 x %struct.entry], ptr %46, i64 0, i64 %49
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %44, ptr align 8 %50, i64 16, i1 false), !tbaa.struct !15
  br label %51

51:                                               ; preds = %39
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %7, align 4, !tbaa !9
  br label %33, !llvm.loop !17

54:                                               ; preds = %33
  store i32 1, ptr %8, align 4
  br label %105

55:                                               ; preds = %18
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %7, align 4, !tbaa !9
  br label %12, !llvm.loop !19

59:                                               ; preds = %12
  br label %60

60:                                               ; preds = %59, %3
  %61 = load i32, ptr %6, align 4, !tbaa !9
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %104

63:                                               ; preds = %60
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %100, %63
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.STnode, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %67, align 8, !tbaa !11
  %69 = icmp slt i32 %65, %68
  br i1 %69, label %70, label %103

70:                                               ; preds = %64
  %71 = load i32, ptr %7, align 4, !tbaa !9
  %72 = add nsw i32 %71, 1
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.STnode, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 8, !tbaa !11
  %76 = icmp eq i32 %72, %75
  br i1 %76, label %88, label %77

77:                                               ; preds = %70
  %78 = load i32, ptr %5, align 4, !tbaa !9
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.STnode, ptr %79, i32 0, i32 0
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = add nsw i32 %81, 1
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [6 x %struct.entry], ptr %80, i64 0, i64 %83
  %85 = getelementptr inbounds %struct.entry, ptr %84, i32 0, i32 0
  %86 = load i32, ptr %85, align 8, !tbaa !13
  %87 = icmp slt i32 %78, %86
  br i1 %87, label %88, label %99

88:                                               ; preds = %77, %70
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.STnode, ptr %89, i32 0, i32 0
  %91 = load i32, ptr %7, align 4, !tbaa !9
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [6 x %struct.entry], ptr %90, i64 0, i64 %92
  %94 = getelementptr inbounds %struct.entry, ptr %93, i32 0, i32 1
  %95 = load ptr, ptr %94, align 8, !tbaa !16
  %96 = load i32, ptr %5, align 4, !tbaa !9
  %97 = load i32, ptr %6, align 4, !tbaa !9
  %98 = sub nsw i32 %97, 1
  call void @STdeleteR(ptr noundef %95, i32 noundef %96, i32 noundef %98)
  store i32 1, ptr %8, align 4
  br label %105

99:                                               ; preds = %77
  br label %100

100:                                              ; preds = %99
  %101 = load i32, ptr %7, align 4, !tbaa !9
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %7, align 4, !tbaa !9
  br label %64, !llvm.loop !20

103:                                              ; preds = %64
  br label %104

104:                                              ; preds = %103, %60
  store i32 1, ptr %8, align 4
  br label %105

105:                                              ; preds = %104, %88, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }

!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 96}
!12 = !{!"STnode", !7, i64 0, !10, i64 96}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !7, i64 8}
!15 = !{i64 0, i64 4, !9, i64 8, i64 8, !16}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = distinct !{!20, !18}


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

%struct.entry = type { i32, %union.anon }
%union.anon = type { ptr }

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @STdeleteR(ptr nocapture noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %cond72 = icmp eq i32 %2, 0
  br i1 %cond72, label %.preheader, label %.lr.ph75

.preheader:                                       ; preds = %.split.loop.exit64, %3
  %.tr.lcssa = phi ptr [ %0, %3 ], [ %35, %.split.loop.exit64 ]
  %4 = getelementptr inbounds i8, ptr %.tr.lcssa, i64 96
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %5 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %19
  %indvars.iv52 = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next53, %19 ]
  %7 = getelementptr inbounds [6 x %struct.entry], ptr %.tr.lcssa, i64 0, i64 %indvars.iv52
  %8 = load i32, ptr %7, align 8, !tbaa !10
  %9 = icmp eq i32 %8, %1
  br i1 %9, label %10, label %19

10:                                               ; preds = %.lr.ph
  %11 = trunc nuw nsw i64 %indvars.iv52 to i32
  %12 = add nsw i32 %5, -1
  store i32 %12, ptr %4, align 8, !tbaa !5
  %13 = icmp sgt i32 %12, %11
  br i1 %13, label %.lr.ph45, label %.loopexit

.lr.ph45:                                         ; preds = %10, %.lr.ph45
  %indvars.iv57 = phi i64 [ %indvars.iv.next58, %.lr.ph45 ], [ %indvars.iv52, %10 ]
  %14 = getelementptr inbounds [6 x %struct.entry], ptr %.tr.lcssa, i64 0, i64 %indvars.iv57
  %indvars.iv.next58 = add nuw nsw i64 %indvars.iv57, 1
  %15 = getelementptr inbounds [6 x %struct.entry], ptr %.tr.lcssa, i64 0, i64 %indvars.iv.next58
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %14, ptr noundef nonnull align 8 dereferenceable(16) %15, i64 16, i1 false), !tbaa.struct !12
  %16 = load i32, ptr %4, align 8, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = icmp slt i64 %indvars.iv.next58, %17
  br i1 %18, label %.lr.ph45, label %.loopexit, !llvm.loop !15

19:                                               ; preds = %.lr.ph
  %indvars.iv.next53 = add nuw nsw i64 %indvars.iv52, 1
  %exitcond55.not = icmp eq i64 %indvars.iv.next53, %wide.trip.count
  br i1 %exitcond55.not, label %.loopexit, label %.lr.ph, !llvm.loop !17

.lr.ph75:                                         ; preds = %3, %.split.loop.exit64
  %.tr3274 = phi i32 [ %36, %.split.loop.exit64 ], [ %2, %3 ]
  %.tr73 = phi ptr [ %35, %.split.loop.exit64 ], [ %0, %3 ]
  %20 = getelementptr inbounds i8, ptr %.tr73, i64 96
  %21 = load i32, ptr %20, align 8, !tbaa !5
  %22 = zext i32 %21 to i64
  %23 = add i32 %21, -1
  %24 = tail call i32 @llvm.smax.i32(i32 %21, i32 0)
  %smax = zext nneg i32 %24 to i64
  br label %25

25:                                               ; preds = %28, %.lr.ph75
  %indvars.iv = phi i64 [ %indvars.iv.next, %28 ], [ 0, %.lr.ph75 ]
  %exitcond.not = icmp eq i64 %indvars.iv, %smax
  br i1 %exitcond.not, label %.loopexit, label %26

26:                                               ; preds = %25
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %27 = icmp eq i64 %indvars.iv.next, %22
  br i1 %27, label %.split.loop.exit64, label %28

28:                                               ; preds = %26
  %29 = getelementptr inbounds [6 x %struct.entry], ptr %.tr73, i64 0, i64 %indvars.iv.next
  %30 = load i32, ptr %29, align 8, !tbaa !10
  %31 = icmp sgt i32 %30, %1
  br i1 %31, label %.split.loop.exit, label %25, !llvm.loop !18

.split.loop.exit:                                 ; preds = %28
  %32 = trunc nuw nsw i64 %indvars.iv to i32
  br label %.split.loop.exit64

.split.loop.exit64:                               ; preds = %26, %.split.loop.exit
  %.2.lcssa49 = phi i32 [ %32, %.split.loop.exit ], [ %23, %26 ]
  %33 = zext nneg i32 %.2.lcssa49 to i64
  %34 = getelementptr inbounds [6 x %struct.entry], ptr %.tr73, i64 0, i64 %33, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = add nsw i32 %.tr3274, -1
  %cond = icmp eq i32 %36, 0
  br i1 %cond, label %.preheader, label %.lr.ph75

.loopexit:                                        ; preds = %25, %19, %.lr.ph45, %.preheader, %10
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !9, i64 96}
!6 = !{!"STnode", !7, i64 0, !9, i64 96}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!11, !9, i64 0}
!11 = !{!"", !9, i64 0, !7, i64 8}
!12 = !{i64 0, i64 4, !13, i64 8, i64 8, !14}
!13 = !{!9, !9, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


; Effective O3 passes: ConstraintEliminationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass