; LLVM IR from bartobri/data-structures-c :: symbol-table/trie (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 { ptr, ptr, ptr, i32 }

; Function Attrs: nounwind uwtable
define dso_local ptr @STselectR(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.STnode, ptr %6, i32 0, i32 3
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp slt i32 %8, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  br label %50

12:                                               ; preds = %2
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %24

15:                                               ; preds = %12
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.STnode, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %24

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

24:                                               ; preds = %15, %12
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.STnode, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = getelementptr inbounds %struct.STnode, ptr %27, i32 0, i32 3
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = icmp sge i32 %29, %30
  br i1 %31, label %32, label %38

32:                                               ; preds = %24
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.STnode, ptr %33, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = call ptr @STselectR(ptr noundef %35, i32 noundef %36)
  store ptr %37, ptr %3, align 8
  br label %50

38:                                               ; preds = %24
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.STnode, ptr %39, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !15
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.STnode, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = getelementptr inbounds %struct.STnode, ptr %45, i32 0, i32 3
  %47 = load i32, ptr %46, align 8, !tbaa !11
  %48 = sub nsw i32 %42, %47
  %49 = call ptr @STselectR(ptr noundef %41, i32 noundef %48)
  store ptr %49, ptr %3, align 8
  br label %50

50:                                               ; preds = %38, %32, %20, %11
  %51 = load ptr, ptr %3, align 8
  ret ptr %51
}

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

!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 24}
!12 = !{!"STnode", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !6, i64 16}


; 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: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @STselectR(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  br label %tailrecurse.outer

tailrecurse.outer:                                ; preds = %.split19.us, %2
  %.tr.ph = phi ptr [ %21, %.split19.us ], [ %0, %2 ]
  %.tr16.ph = phi i32 [ %22, %.split19.us ], [ %1, %2 ]
  %.tr16.ph.fr = freeze i32 %.tr16.ph
  %3 = icmp eq i32 %.tr16.ph.fr, 1
  %.phi.trans.insert27 = getelementptr inbounds i8, ptr %.tr.ph, i64 24
  %.pre28 = load i32, ptr %.phi.trans.insert27, align 8, !tbaa !5
  br i1 %3, label %tailrecurse.us, label %tailrecurse

tailrecurse.us:                                   ; preds = %tailrecurse.outer, %8
  %4 = phi i32 [ %12, %8 ], [ %.pre28, %tailrecurse.outer ]
  %.tr.us = phi ptr [ %10, %8 ], [ %.tr.ph, %tailrecurse.outer ]
  %5 = icmp slt i32 %4, 1
  br i1 %5, label %.split.us, label %6

6:                                                ; preds = %tailrecurse.us
  %7 = load ptr, ptr %.tr.us, align 8, !tbaa !11
  %.not.us = icmp eq ptr %7, null
  br i1 %.not.us, label %8, label %.split.us

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %.tr.us, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %10, i64 24
  %12 = load i32, ptr %11, align 8, !tbaa !5
  %.not15.us = icmp slt i32 %12, 1
  br i1 %.not15.us, label %.split19.us, label %tailrecurse.us

tailrecurse:                                      ; preds = %tailrecurse.outer, %15
  %13 = phi i32 [ %19, %15 ], [ %.pre28, %tailrecurse.outer ]
  %.tr = phi ptr [ %17, %15 ], [ %.tr.ph, %tailrecurse.outer ]
  %14 = icmp slt i32 %13, %.tr16.ph.fr
  br i1 %14, label %.split.us, label %15

15:                                               ; preds = %tailrecurse
  %16 = getelementptr inbounds i8, ptr %.tr, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %17, i64 24
  %19 = load i32, ptr %18, align 8, !tbaa !5
  %.not15 = icmp slt i32 %19, %.tr16.ph.fr
  br i1 %.not15, label %.split19.us, label %tailrecurse

.split19.us:                                      ; preds = %15, %8
  %.us-phi20 = phi i32 [ %12, %8 ], [ %19, %15 ]
  %.us-phi21 = phi ptr [ %.tr.us, %8 ], [ %.tr, %15 ]
  %20 = getelementptr inbounds i8, ptr %.us-phi21, i64 16
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = sub nsw i32 %.tr16.ph.fr, %.us-phi20
  br label %tailrecurse.outer

.split.us:                                        ; preds = %tailrecurse, %tailrecurse.us, %6
  %.us-phi = phi ptr [ null, %tailrecurse.us ], [ %7, %6 ], [ null, %tailrecurse ]
  ret ptr %.us-phi
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, 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" }

!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, !10, i64 24}
!6 = !{!"STnode", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !7, i64 16}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass