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

@head = external hidden global ptr, align 8

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @STinsertR(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @STinsert(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.anon, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %10, ptr %4, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %11 = load ptr, ptr @head, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.STnode, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = load i32, ptr %4, align 4, !tbaa !12
  %15 = call ptr @STsearchR(ptr noundef %13, i32 noundef %14, i32 noundef -1)
  store ptr %15, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %1
  br label %23

19:                                               ; preds = %1
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.anon, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %19, %18
  %24 = phi i32 [ 0, %18 ], [ %22, %19 ]
  store i32 %24, ptr %6, align 4, !tbaa !12
  %25 = load i32, ptr %4, align 4, !tbaa !12
  %26 = load i32, ptr %6, align 4, !tbaa !12
  %27 = icmp eq i32 %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  store i32 1, ptr %7, align 4
  br label %60

29:                                               ; preds = %23
  store i32 0, ptr %3, align 4, !tbaa !12
  br label %30

30:                                               ; preds = %47, %29
  %31 = load i32, ptr %4, align 4, !tbaa !12
  %32 = load i32, ptr %3, align 4, !tbaa !12
  %33 = add nsw i32 %32, 1
  %34 = mul nsw i32 %33, 1
  %35 = sub nsw i32 32, %34
  %36 = ashr i32 %31, %35
  %37 = and i32 %36, 1
  %38 = load i32, ptr %6, align 4, !tbaa !12
  %39 = load i32, ptr %3, align 4, !tbaa !12
  %40 = add nsw i32 %39, 1
  %41 = mul nsw i32 %40, 1
  %42 = sub nsw i32 32, %41
  %43 = ashr i32 %38, %42
  %44 = and i32 %43, 1
  %45 = icmp eq i32 %37, %44
  br i1 %45, label %46, label %50

46:                                               ; preds = %30
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %3, align 4, !tbaa !12
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %3, align 4, !tbaa !12
  br label %30, !llvm.loop !15

50:                                               ; preds = %30
  %51 = load ptr, ptr @head, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.STnode, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !13
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = load i32, ptr %3, align 4, !tbaa !12
  %56 = load ptr, ptr @head, align 8, !tbaa !5
  %57 = call ptr @STinsertR(ptr noundef %53, ptr noundef %54, i32 noundef %55, ptr noundef %56)
  %58 = load ptr, ptr @head, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.STnode, ptr %58, i32 0, i32 1
  store ptr %57, ptr %59, align 8, !tbaa !13
  store i32 0, ptr %7, align 4
  br label %60

60:                                               ; preds = %50, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  %61 = load i32, ptr %7, align 4
  switch i32 %61, label %63 [
    i32 0, label %62
    i32 1, label %62
  ]

62:                                               ; preds = %60, %60
  ret void

63:                                               ; preds = %60
  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, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"STnode", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

@head = external hidden local_unnamed_addr global ptr, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local void @STinsert(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr %0, align 4, !tbaa !5
  %3 = load ptr, ptr @head, align 8, !tbaa !10
  %4 = getelementptr inbounds i8, ptr %3, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !12
  %6 = tail call ptr @STsearchR(ptr noundef %5, i32 noundef %2, i32 noundef -1)
  %7 = icmp eq ptr %6, null
  br i1 %7, label %10, label %8

8:                                                ; preds = %1
  %9 = load i32, ptr %6, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %1, %8
  %11 = phi i32 [ %9, %8 ], [ 0, %1 ]
  %12 = icmp eq i32 %2, %11
  br i1 %12, label %26, label %.preheader

.preheader:                                       ; preds = %10
  %13 = xor i32 %11, %2
  br label %14

14:                                               ; preds = %14, %.preheader
  %.0 = phi i32 [ %18, %14 ], [ 0, %.preheader ]
  %15 = lshr exact i32 -2147483648, %.0
  %16 = and i32 %15, %13
  %17 = icmp eq i32 %16, 0
  %18 = add nuw nsw i32 %.0, 1
  br i1 %17, label %14, label %19, !llvm.loop !14

19:                                               ; preds = %14
  %20 = load ptr, ptr @head, align 8, !tbaa !10
  %21 = getelementptr inbounds i8, ptr %20, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !12
  %23 = tail call ptr @STinsertR(ptr noundef %22, ptr noundef nonnull %0, i32 noundef %.0, ptr noundef %20)
  %24 = load ptr, ptr @head, align 8, !tbaa !10
  %25 = getelementptr inbounds i8, ptr %24, i64 8
  store ptr %23, ptr %25, align 8, !tbaa !12
  br label %26

26:                                               ; preds = %10, %19
  ret void
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass