; LLVM IR from Water-Melon/Melon :: src (mln_json)

; 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.mln_json_kv_t = type { %struct.mln_json_s, %struct.mln_json_s, %struct.mln_rbtree_node_s }
%struct.mln_json_s = type { i32, %union.anon }
%union.anon = type { ptr }
%struct.mln_rbtree_node_s = type { ptr, ptr, ptr, ptr, ptr, ptr, i32 }
%struct.rbtree_s = type { ptr, ptr, ptr, ptr, ptr, %struct.mln_rbtree_node_s, ptr, ptr, ptr, ptr, ptr, i64, i8 }

; Function Attrs: nounwind uwtable
define dso_local ptr @mln_json_obj_search(ptr noundef nonnull %0, ptr noundef nonnull %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.mln_json_kv_t, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.mln_json_s, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !9
  %18 = icmp eq i32 %17, 1
  br i1 %18, label %20, label %19

19:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  br label %75

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 88, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %21 = getelementptr inbounds %struct.mln_json_kv_t, ptr %7, i32 0, i32 0
  store ptr %21, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.mln_json_s, ptr %22, i32 0, i32 0
  store i32 3, ptr %23, align 8, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mln_json_s, ptr %25, i32 0, i32 1
  store ptr %24, ptr %26, align 8, !tbaa !12
  store ptr %24, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.mln_json_s, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  store ptr %30, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.rbtree_s, ptr %31, i32 0, i32 6
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  store ptr %33, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  br label %34

34:                                               ; preds = %58, %20
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.rbtree_s, ptr %36, i32 0, i32 5
  %38 = icmp ne ptr %35, %37
  br i1 %38, label %39, label %45

39:                                               ; preds = %34
  %40 = load ptr, ptr %11, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mln_rbtree_node_s, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  %43 = call i32 @mln_json_kv_cmp(ptr noundef %7, ptr noundef %42)
  store i32 %43, ptr %12, align 4, !tbaa !18
  %44 = icmp ne i32 %43, 0
  br label %45

45:                                               ; preds = %39, %34
  %46 = phi i1 [ false, %34 ], [ %44, %39 ]
  br i1 %46, label %47, label %59

47:                                               ; preds = %45
  %48 = load i32, ptr %12, align 4, !tbaa !18
  %49 = icmp slt i32 %48, 0
  br i1 %49, label %50, label %54

50:                                               ; preds = %47
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.mln_rbtree_node_s, ptr %51, i32 0, i32 4
  %53 = load ptr, ptr %52, align 8, !tbaa !19
  store ptr %53, ptr %11, align 8, !tbaa !5
  br label %58

54:                                               ; preds = %47
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.mln_rbtree_node_s, ptr %55, i32 0, i32 5
  %57 = load ptr, ptr %56, align 8, !tbaa !20
  store ptr %57, ptr %11, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %54, %50
  br label %34, !llvm.loop !21

59:                                               ; preds = %45
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %60, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %61 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %61, ptr %6, align 8, !tbaa !5
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.mln_json_s, ptr %63, i32 0, i32 1
  %65 = load ptr, ptr %64, align 8, !tbaa !12
  %66 = getelementptr inbounds %struct.rbtree_s, ptr %65, i32 0, i32 5
  %67 = icmp eq ptr %62, %66
  br i1 %67, label %68, label %69

68:                                               ; preds = %59
  store ptr null, ptr %3, align 8
  store i32 1, ptr %14, align 4
  br label %74

69:                                               ; preds = %59
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.mln_rbtree_node_s, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !17
  %73 = getelementptr inbounds %struct.mln_json_kv_t, ptr %72, i32 0, i32 1
  store ptr %73, ptr %3, align 8
  store i32 1, ptr %14, align 4
  br label %74

74:                                               ; preds = %69, %68
  call void @llvm.lifetime.end.p0(i64 88, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %75

75:                                               ; preds = %74, %19
  %76 = load ptr, ptr %3, align 8
  ret ptr %76
}

; 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: inlinehint nounwind uwtable
declare hidden i32 @mln_json_kv_cmp(ptr noundef, ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { 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 = !{!"mln_json_s", !11, i64 0, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !6, i64 96}
!14 = !{!"rbtree_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !15, i64 40, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !16, i64 136, !11, i64 144}
!15 = !{!"mln_rbtree_node_s", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !11, i64 48, !11, i64 48}
!16 = !{!"long", !7, i64 0}
!17 = !{!15, !6, i64 0}
!18 = !{!11, !11, i64 0}
!19 = !{!15, !6, i64 32}
!20 = !{!15, !6, i64 40}
!21 = distinct !{!21, !22}
!22 = !{!"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"

%struct.mln_json_kv_t = type { %struct.mln_json_s, %struct.mln_json_s, %struct.mln_rbtree_node_s }
%struct.mln_json_s = type { i32, %union.anon }
%union.anon = type { ptr }
%struct.mln_rbtree_node_s = type { ptr, ptr, ptr, ptr, ptr, ptr, i32 }

; Function Attrs: nounwind uwtable
define dso_local ptr @mln_json_obj_search(ptr nocapture noundef nonnull readonly %0, ptr noundef nonnull %1) local_unnamed_addr #0 {
  %3 = alloca %struct.mln_json_kv_t, align 8
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = icmp eq i32 %4, 1
  br i1 %5, label %6, label %23

6:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 88, ptr nonnull %3) #3
  store i32 3, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %1, ptr %7, align 8, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !10
  %10 = getelementptr inbounds i8, ptr %9, i64 96
  %11 = getelementptr inbounds i8, ptr %9, i64 40
  %.01822 = load ptr, ptr %10, align 8, !tbaa !11
  %.not23 = icmp eq ptr %.01822, %11
  br i1 %.not23, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %6, %14
  %.01824 = phi ptr [ %.018, %14 ], [ %.01822, %6 ]
  %12 = load ptr, ptr %.01824, align 8, !tbaa !13
  %13 = call i32 @mln_json_kv_cmp(ptr noundef nonnull %3, ptr noundef %12)
  %.not21 = icmp eq i32 %13, 0
  br i1 %.not21, label %.critedge.loopexit, label %14

14:                                               ; preds = %.lr.ph
  %15 = icmp slt i32 %13, 0
  %.119.in.v = select i1 %15, i64 32, i64 40
  %.119.in = getelementptr inbounds i8, ptr %.01824, i64 %.119.in.v
  %.018 = load ptr, ptr %.119.in, align 8, !tbaa !11
  %.not = icmp eq ptr %.018, %11
  br i1 %.not, label %.critedge.loopexit, label %.lr.ph, !llvm.loop !15

.critedge.loopexit:                               ; preds = %14, %.lr.ph
  %.018.lcssa.ph = phi ptr [ %.01824, %.lr.ph ], [ %.018, %14 ]
  %.pre = load ptr, ptr %8, align 8, !tbaa !10
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %6
  %16 = phi ptr [ %9, %6 ], [ %.pre, %.critedge.loopexit ]
  %.018.lcssa = phi ptr [ %.01822, %6 ], [ %.018.lcssa.ph, %.critedge.loopexit ]
  %17 = getelementptr inbounds i8, ptr %16, i64 40
  %18 = icmp eq ptr %.018.lcssa, %17
  br i1 %18, label %22, label %19

19:                                               ; preds = %.critedge
  %20 = load ptr, ptr %.018.lcssa, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  br label %22

22:                                               ; preds = %.critedge, %19
  %.0 = phi ptr [ %21, %19 ], [ null, %.critedge ]
  call void @llvm.lifetime.end.p0(i64 88, ptr nonnull %3) #3
  br label %23

23:                                               ; preds = %2, %22
  %.1 = phi ptr [ %.0, %22 ], [ null, %2 ]
  ret ptr %.1
}

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @mln_json_kv_cmp(ptr noundef, ptr noundef) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { 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, !7, i64 0}
!6 = !{!"mln_json_s", !7, i64 0, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"mln_rbtree_node_s", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !7, i64 48, !7, i64 48}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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