; LLVM IR from bartobri/data-structures-c :: symbol-table/patricia-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 @STsearchR(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.STnode, ptr %8, i32 0, i32 3
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %13, label %17

13:                                               ; preds = %3
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.STnode, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  store ptr %16, ptr %4, align 8
  br label %46

17:                                               ; preds = %3
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.STnode, ptr %19, i32 0, i32 3
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = add nsw i32 %21, 1
  %23 = mul nsw i32 %22, 1
  %24 = sub nsw i32 32, %23
  %25 = ashr i32 %18, %24
  %26 = and i32 %25, 1
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %37

28:                                               ; preds = %17
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.STnode, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.STnode, ptr %33, i32 0, i32 3
  %35 = load i32, ptr %34, align 8, !tbaa !11
  %36 = call ptr @STsearchR(ptr noundef %31, i32 noundef %32, i32 noundef %35)
  store ptr %36, ptr %4, align 8
  br label %46

37:                                               ; preds = %17
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.STnode, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.STnode, ptr %42, i32 0, i32 3
  %44 = load i32, ptr %43, align 8, !tbaa !11
  %45 = call ptr @STsearchR(ptr noundef %40, i32 noundef %41, i32 noundef %44)
  store ptr %45, ptr %4, align 8
  br label %46

46:                                               ; preds = %37, %28, %13
  %47 = load ptr, ptr %4, align 8
  ret ptr %47
}

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 @STsearchR(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 24
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not14 = icmp sgt i32 %5, %2
  br i1 %.not14, label %.lr.ph, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %.lr.ph, %3
  %.tr.lcssa = phi ptr [ %0, %3 ], [ %.tr.be, %.lr.ph ]
  %6 = load ptr, ptr %.tr.lcssa, align 8, !tbaa !11
  ret ptr %6

.lr.ph:                                           ; preds = %3, %.lr.ph
  %7 = phi i32 [ %13, %.lr.ph ], [ %5, %3 ]
  %.tr15 = phi ptr [ %.tr.be, %.lr.ph ], [ %0, %3 ]
  %8 = lshr exact i32 -2147483648, %7
  %9 = and i32 %8, %1
  %10 = icmp eq i32 %9, 0
  %spec.select = select i1 %10, i64 8, i64 16
  %11 = getelementptr inbounds i8, ptr %.tr15, i64 %spec.select
  %.tr.be = load ptr, ptr %11, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %.tr.be, i64 24
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %.not = icmp sgt i32 %13, %7
  br i1 %.not, label %.lr.ph, label %tailrecurse._crit_edge
}

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 = !{!7, !7, i64 0}


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