; 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
declare dso_local ptr @NEW(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @STsplit(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  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 8, ptr %8) #2
  %9 = load ptr, ptr @z, align 8, !tbaa !5
  %10 = load ptr, ptr @z, align 8, !tbaa !5
  %11 = call ptr @NEW(ptr noundef null, ptr noundef %9, ptr noundef %10, i32 noundef 2)
  store ptr %11, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.STnode, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds %struct.anon, ptr %14, i32 0, i32 0
  %16 = load i8, ptr %15, align 4, !tbaa !13
  %17 = zext i8 %16 to i32
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  %20 = mul nsw i32 %19, 1
  %21 = sub nsw i32 8, %20
  %22 = ashr i32 %17, %21
  %23 = and i32 %22, 1
  %24 = mul nsw i32 %23, 2
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.STnode, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.anon, ptr %27, i32 0, i32 0
  %29 = load i8, ptr %28, align 4, !tbaa !13
  %30 = zext i8 %29 to i32
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = add nsw i32 %31, 1
  %33 = mul nsw i32 %32, 1
  %34 = sub nsw i32 8, %33
  %35 = ashr i32 %30, %34
  %36 = and i32 %35, 1
  %37 = add nsw i32 %24, %36
  switch i32 %37, label %68 [
    i32 0, label %38
    i32 1, label %46
    i32 2, label %53
    i32 3, label %60
  ]

38:                                               ; preds = %3
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  %43 = call ptr @STsplit(ptr noundef %39, ptr noundef %40, i32 noundef %42)
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.STnode, ptr %44, i32 0, i32 1
  store ptr %43, ptr %45, align 8, !tbaa !15
  br label %68

46:                                               ; preds = %3
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.STnode, ptr %48, i32 0, i32 1
  store ptr %47, ptr %49, align 8, !tbaa !15
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.STnode, ptr %51, i32 0, i32 2
  store ptr %50, ptr %52, align 8, !tbaa !16
  br label %68

53:                                               ; preds = %3
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.STnode, ptr %55, i32 0, i32 2
  store ptr %54, ptr %56, align 8, !tbaa !16
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.STnode, ptr %58, i32 0, i32 1
  store ptr %57, ptr %59, align 8, !tbaa !15
  br label %68

60:                                               ; preds = %3
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load i32, ptr %7, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  %65 = call ptr @STsplit(ptr noundef %61, ptr noundef %62, i32 noundef %64)
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.STnode, ptr %66, i32 0, i32 2
  store ptr %65, ptr %67, align 8, !tbaa !16
  br label %68

68:                                               ; preds = %60, %53, %46, %38, %3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %69 = load ptr, ptr %4, align 8
  ret ptr %69
}

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

@z = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local ptr @NEW(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noalias ptr @STsplit(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %tailrecurse.backedge, %3
  %.tr21 = phi i32 [ %2, %3 ], [ %19, %tailrecurse.backedge ]
  %4 = load ptr, ptr @z, align 8, !tbaa !5
  %5 = tail call ptr @NEW(ptr noundef null, ptr noundef %4, ptr noundef %4, i32 noundef 2)
  %6 = load ptr, ptr %0, align 8, !tbaa !9
  %7 = load i8, ptr %6, align 4, !tbaa !12
  %8 = zext i8 %7 to i32
  %9 = sub nsw i32 7, %.tr21
  %10 = lshr i32 %8, %9
  %11 = shl nuw nsw i32 %10, 1
  %12 = and i32 %11, 2
  %13 = load ptr, ptr %1, align 8, !tbaa !9
  %14 = load i8, ptr %13, align 4, !tbaa !12
  %15 = zext i8 %14 to i32
  %16 = lshr i32 %15, %9
  %17 = and i32 %16, 1
  %18 = or disjoint i32 %17, %12
  switch i32 %18, label %default.unreachable34 [
    i32 0, label %tailrecurse.backedge
    i32 1, label %.loopexit
    i32 2, label %20
    i32 3, label %tailrecurse.backedge
  ]

tailrecurse.backedge:                             ; preds = %tailrecurse, %tailrecurse
  %19 = add nsw i32 %.tr21, 1
  br label %tailrecurse

default.unreachable34:                            ; preds = %tailrecurse
  unreachable

.loopexit:                                        ; preds = %tailrecurse
  br label %20

20:                                               ; preds = %tailrecurse, %.loopexit
  %.sink40 = phi i64 [ 8, %.loopexit ], [ 16, %tailrecurse ]
  %.sink39 = phi i64 [ 16, %.loopexit ], [ 8, %tailrecurse ]
  %21 = getelementptr inbounds i8, ptr %5, i64 %.sink40
  store ptr %0, ptr %21, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %5, i64 %.sink39
  store ptr %1, ptr %22, align 8, !tbaa !5
  ret ptr undef
}

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


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