; LLVM IR from fmela/libdict :: src (tree_common)

; 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.tree = type { ptr, i64, ptr, i64 }
%struct.tree_node = type { ptr, ptr, 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 @tree_search_le_node(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %11, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.tree, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store ptr null, ptr %8, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %46, %2
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %47

18:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.tree, ptr %19, i32 0, i32 2
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.tree_node, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = call i32 %21(ptr noundef %22, ptr noundef %25)
  store i32 %26, ptr %9, align 4, !tbaa !15
  %27 = load i32, ptr %9, align 4, !tbaa !15
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %18
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %30, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %44

31:                                               ; preds = %18
  %32 = load i32, ptr %9, align 4, !tbaa !15
  %33 = icmp slt i32 %32, 0
  br i1 %33, label %34, label %38

34:                                               ; preds = %31
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.tree_node, ptr %35, i32 0, i32 3
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  store ptr %37, ptr %7, align 8, !tbaa !5
  br label %43

38:                                               ; preds = %31
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %39, ptr %8, align 8, !tbaa !5
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.tree_node, ptr %40, i32 0, i32 4
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  store ptr %42, ptr %7, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %38, %34
  store i32 0, ptr %10, align 4
  br label %44

44:                                               ; preds = %43, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  %45 = load i32, ptr %10, align 4
  switch i32 %45, label %49 [
    i32 0, label %46
  ]

46:                                               ; preds = %44
  br label %15, !llvm.loop !19

47:                                               ; preds = %15
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %48, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %49

49:                                               ; preds = %47, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %50 = load ptr, ptr %3, align 8
  ret ptr %50
}

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, !6, i64 0}
!10 = !{!"", !6, i64 0, !11, i64 8, !6, i64 16, !11, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!14, !6, i64 0}
!14 = !{!"tree_node", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = !{!14, !6, i64 24}
!18 = !{!14, !6, i64 32}
!19 = distinct !{!19, !20}
!20 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local ptr @tree_search_le_node(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %.01826 = load ptr, ptr %0, align 8, !tbaa !5
  %.not27 = icmp eq ptr %.01826, null
  br i1 %.not27, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %2, %7
  %.01829 = phi ptr [ %.018, %7 ], [ %.01826, %2 ]
  %.01528 = phi ptr [ %.116, %7 ], [ null, %2 ]
  %4 = load ptr, ptr %3, align 8, !tbaa !9
  %5 = load ptr, ptr %.01829, align 8, !tbaa !12
  %6 = tail call i32 %4(ptr noundef %1, ptr noundef %5) #1
  %.not22 = icmp eq i32 %6, 0
  br i1 %.not22, label %.thread, label %7

7:                                                ; preds = %.lr.ph
  %8 = icmp slt i32 %6, 0
  %.119.in.v = select i1 %8, i64 24, i64 32
  %.119.in = getelementptr inbounds i8, ptr %.01829, i64 %.119.in.v
  %.116 = select i1 %8, ptr %.01528, ptr %.01829
  %.018 = load ptr, ptr %.119.in, align 8, !tbaa !5
  %.not = icmp eq ptr %.018, null
  br i1 %.not, label %.thread, label %.lr.ph, !llvm.loop !14

.thread:                                          ; preds = %7, %.lr.ph, %2
  %.2 = phi ptr [ null, %2 ], [ %.01829, %.lr.ph ], [ %.116, %7 ]
  ret ptr %.2
}

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 = { 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, !6, i64 16}
!10 = !{!"", !6, i64 0, !11, i64 8, !6, i64 16, !11, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"tree_node", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass