; 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 }
%struct.anon = type { i8, i32 }

@z = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @STsearchR(ptr noundef %0, i8 noundef zeroext %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i8 %1, ptr %6, align 1, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !10
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr @z, align 8, !tbaa !5
  %10 = icmp eq ptr %8, %9
  br i1 %10, label %11, label %12

11:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  br label %65

12:                                               ; preds = %3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.STnode, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = load ptr, ptr @z, align 8, !tbaa !5
  %17 = icmp eq ptr %15, %16
  br i1 %17, label %18, label %39

18:                                               ; preds = %12
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.STnode, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = load ptr, ptr @z, align 8, !tbaa !5
  %23 = icmp eq ptr %21, %22
  br i1 %23, label %24, label %39

24:                                               ; preds = %18
  %25 = load i8, ptr %6, align 1, !tbaa !9
  %26 = zext i8 %25 to i32
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.STnode, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = getelementptr inbounds %struct.anon, ptr %29, i32 0, i32 0
  %31 = load i8, ptr %30, align 4, !tbaa !16
  %32 = zext i8 %31 to i32
  %33 = icmp eq i32 %26, %32
  br i1 %33, label %34, label %38

34:                                               ; preds = %24
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.STnode, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  store ptr %37, ptr %4, align 8
  br label %65

38:                                               ; preds = %24
  store ptr null, ptr %4, align 8
  br label %65

39:                                               ; preds = %18, %12
  %40 = load i8, ptr %6, align 1, !tbaa !9
  %41 = zext i8 %40 to i32
  %42 = load i32, ptr %7, align 4, !tbaa !10
  %43 = add nsw i32 %42, 1
  %44 = mul nsw i32 %43, 1
  %45 = sub nsw i32 8, %44
  %46 = ashr i32 %41, %45
  %47 = and i32 %46, 1
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %57

49:                                               ; preds = %39
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.STnode, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !12
  %53 = load i8, ptr %6, align 1, !tbaa !9
  %54 = load i32, ptr %7, align 4, !tbaa !10
  %55 = add nsw i32 %54, 1
  %56 = call ptr @STsearchR(ptr noundef %52, i8 noundef zeroext %53, i32 noundef %55)
  store ptr %56, ptr %4, align 8
  br label %65

57:                                               ; preds = %39
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.STnode, ptr %58, i32 0, i32 2
  %60 = load ptr, ptr %59, align 8, !tbaa !14
  %61 = load i8, ptr %6, align 1, !tbaa !9
  %62 = load i32, ptr %7, align 4, !tbaa !10
  %63 = add nsw i32 %62, 1
  %64 = call ptr @STsearchR(ptr noundef %60, i8 noundef zeroext %61, i32 noundef %63)
  store ptr %64, ptr %4, align 8
  br label %65

65:                                               ; preds = %57, %49, %38, %34, %11
  %66 = load ptr, ptr %4, align 8
  ret ptr %66
}

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

@z = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @STsearchR(ptr noundef readonly %0, i8 noundef zeroext %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr @z, align 8, !tbaa !5
  %5 = icmp eq ptr %4, %0
  br i1 %5, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %6 = zext i8 %1 to i32
  br label %7

7:                                                ; preds = %.lr.ph, %tailrecurse.backedge
  %.tr1720 = phi i32 [ %2, %.lr.ph ], [ %20, %tailrecurse.backedge ]
  %.tr19 = phi ptr [ %0, %.lr.ph ], [ %.tr.be, %tailrecurse.backedge ]
  %8 = getelementptr inbounds i8, ptr %.tr19, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp eq ptr %9, %4
  br i1 %10, label %11, label %19

11:                                               ; preds = %7
  %12 = getelementptr inbounds i8, ptr %.tr19, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = icmp eq ptr %13, %4
  br i1 %14, label %15, label %19

15:                                               ; preds = %11
  %16 = load ptr, ptr %.tr19, align 8, !tbaa !13
  %17 = load i8, ptr %16, align 4, !tbaa !14
  %18 = icmp eq i8 %17, %1
  %. = select i1 %18, ptr %16, ptr null
  br label %.loopexit

19:                                               ; preds = %11, %7
  %20 = add nsw i32 %.tr1720, 1
  %21 = sub nsw i32 7, %.tr1720
  %22 = shl nuw i32 1, %21
  %23 = and i32 %22, %6
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %tailrecurse.backedge, label %25

25:                                               ; preds = %19
  %26 = getelementptr inbounds i8, ptr %.tr19, i64 16
  %27 = load ptr, ptr %26, align 8, !tbaa !12
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %25, %19
  %.tr.be = phi ptr [ %27, %25 ], [ %9, %19 ]
  %28 = icmp eq ptr %4, %.tr.be
  br i1 %28, label %.loopexit, label %7

.loopexit:                                        ; preds = %tailrecurse.backedge, %3, %15
  %.0 = phi ptr [ %., %15 ], [ null, %3 ], [ null, %tailrecurse.backedge ]
  ret ptr %.0
}

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


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