; LLVM IR from bartobri/data-structures-c :: symbol-table/existence-TST (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 { i32, ptr, ptr, 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: nounwind uwtable
define dso_local ptr @STsearchR(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i8, ptr %10, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !11
  %15 = sext i8 %14 to i32
  store i32 %15, ptr %8, align 4, !tbaa !9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %65

19:                                               ; preds = %3
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %24

22:                                               ; preds = %19
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %23, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %65

24:                                               ; preds = %19
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.STnode, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !12
  %29 = icmp slt i32 %25, %28
  br i1 %29, label %30, label %37

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

37:                                               ; preds = %24
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.STnode, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !12
  %42 = icmp eq i32 %38, %41
  br i1 %42, label %43, label %51

43:                                               ; preds = %37
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.STnode, ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  %50 = call ptr @STsearchR(ptr noundef %46, ptr noundef %47, i32 noundef %49)
  store ptr %50, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %65

51:                                               ; preds = %37
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.STnode, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !12
  %56 = icmp sgt i32 %52, %55
  br i1 %56, label %57, label %64

57:                                               ; preds = %51
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.STnode, ptr %58, i32 0, i32 3
  %60 = load ptr, ptr %59, align 8, !tbaa !16
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = call ptr @STsearchR(ptr noundef %60, ptr noundef %61, i32 noundef %62)
  store ptr %63, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %65

64:                                               ; preds = %51
  store i32 0, ptr %9, align 4
  br label %65

65:                                               ; preds = %64, %57, %43, %30, %22, %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %66 = load i32, ptr %9, align 4
  switch i32 %66, label %69 [
    i32 0, label %67
    i32 1, label %67
  ]

67:                                               ; preds = %65, %65
  %68 = load ptr, ptr %4, align 8
  ret ptr %68

69:                                               ; preds = %65
  unreachable
}

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


; 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 noundef ptr @STsearchR(ptr noundef readonly %0, ptr noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %tailrecurse.outer._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %5 = sext i32 %2 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %tailrecurse.outer
  %indvars.iv = phi i64 [ %5, %.lr.ph.preheader ], [ %indvars.iv.next, %tailrecurse.outer ]
  %.tr.ph31 = phi ptr [ %0, %.lr.ph.preheader ], [ %16, %tailrecurse.outer ]
  %.in = getelementptr inbounds i8, ptr %1, i64 %indvars.iv
  %6 = load i8, ptr %.in, align 1, !tbaa !5
  %7 = sext i8 %6 to i32
  %8 = icmp eq i8 %6, 0
  br i1 %8, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

.lr.ph.split:                                     ; preds = %.lr.ph, %tailrecurse.backedge
  %.tr26 = phi ptr [ %.tr.be, %tailrecurse.backedge ], [ %.tr.ph31, %.lr.ph ]
  %9 = load i32, ptr %.tr26, align 8, !tbaa !8
  %10 = icmp sgt i32 %9, %7
  br i1 %10, label %tailrecurse.backedge, label %13

tailrecurse.backedge:                             ; preds = %.lr.ph.split, %18
  %.sink = phi i64 [ 24, %18 ], [ 8, %.lr.ph.split ]
  %11 = getelementptr inbounds i8, ptr %.tr26, i64 %.sink
  %.tr.be = load ptr, ptr %11, align 8, !tbaa !12
  %12 = icmp eq ptr %.tr.be, null
  br i1 %12, label %tailrecurse.outer._crit_edge, label %.lr.ph.split

13:                                               ; preds = %.lr.ph.split
  %14 = icmp eq i32 %9, %7
  br i1 %14, label %tailrecurse.outer, label %18

tailrecurse.outer:                                ; preds = %13
  %15 = getelementptr inbounds i8, ptr %.tr26, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %17 = icmp eq ptr %16, null
  br i1 %17, label %tailrecurse.outer._crit_edge, label %.lr.ph

18:                                               ; preds = %13
  %19 = icmp slt i32 %9, %7
  br i1 %19, label %tailrecurse.backedge, label %tailrecurse.outer._crit_edge

tailrecurse.outer._crit_edge:                     ; preds = %.lr.ph, %tailrecurse.outer, %tailrecurse.backedge, %18, %3
  %.0 = phi ptr [ null, %3 ], [ null, %18 ], [ null, %tailrecurse.backedge ], [ null, %tailrecurse.outer ], [ %1, %.lr.ph ]
  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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 0}
!9 = !{!"STnode", !10, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!10 = !{!"int", !6, i64 0}
!11 = !{!"any pointer", !6, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!9, !11, i64 16}


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