; 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: 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: inlinehint nounwind uwtable
declare hidden i32 @mln_json_kv_cmp(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @mln_json_obj_remove(ptr noundef nonnull %0, ptr noundef nonnull %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.mln_json_kv_t, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %15 = load ptr, ptr %3, 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
  br label %109

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 88, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %21 = getelementptr inbounds %struct.mln_json_kv_t, ptr %5, i32 0, i32 0
  store ptr %21, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %7, 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 %4, align 8, !tbaa !5
  %25 = load ptr, ptr %7, 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 %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %28 = load ptr, ptr %3, 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 %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %31 = load ptr, ptr %9, 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 %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  br label %34

34:                                               ; preds = %58, %20
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = load ptr, ptr %9, 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 %10, 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 %5, ptr noundef %42)
  store i32 %43, ptr %11, 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 %11, align 4, !tbaa !18
  %49 = icmp slt i32 %48, 0
  br i1 %49, label %50, label %54

50:                                               ; preds = %47
  %51 = load ptr, ptr %10, 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 %10, align 8, !tbaa !5
  br label %58

54:                                               ; preds = %47
  %55 = load ptr, ptr %10, 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 %10, align 8, !tbaa !5
  br label %58

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

59:                                               ; preds = %45
  %60 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %60, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  %61 = load ptr, ptr %12, 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 %3, 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 i32 1, ptr %13, align 4
  br label %107

69:                                               ; preds = %59
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.mln_json_s, ptr %70, i32 0, i32 1
  %72 = load ptr, ptr %71, align 8, !tbaa !12
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  call void @mln_rbtree_delete(ptr noundef %72, ptr noundef %73)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.mln_rbtree_node_s, ptr %74, i32 0, i32 6
  %76 = load i32, ptr %75, align 8
  %77 = and i32 %76, 1
  store i32 %77, ptr %14, align 4, !tbaa !18
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.mln_rbtree_node_s, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !17
  %81 = icmp ne ptr %80, null
  br i1 %81, label %82, label %86

82:                                               ; preds = %69
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.mln_rbtree_node_s, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !17
  call void @mln_json_kv_free(ptr noundef %85)
  br label %86

86:                                               ; preds = %82, %69
  %87 = load i32, ptr %14, align 4, !tbaa !18
  %88 = icmp ne i32 %87, 0
  br i1 %88, label %106, label %89

89:                                               ; preds = %86
  %90 = load ptr, ptr %3, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.mln_json_s, ptr %90, i32 0, i32 1
  %92 = load ptr, ptr %91, align 8, !tbaa !12
  %93 = getelementptr inbounds %struct.rbtree_s, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !23
  %95 = icmp ne ptr %94, null
  br i1 %95, label %96, label %103

96:                                               ; preds = %89
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.mln_json_s, ptr %97, i32 0, i32 1
  %99 = load ptr, ptr %98, align 8, !tbaa !12
  %100 = getelementptr inbounds %struct.rbtree_s, ptr %99, i32 0, i32 2
  %101 = load ptr, ptr %100, align 8, !tbaa !24
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  call void %101(ptr noundef %102)
  br label %105

103:                                              ; preds = %89
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %104) #5
  br label %105

105:                                              ; preds = %103, %96
  br label %106

106:                                              ; preds = %105, %86
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  store i32 0, ptr %13, align 4
  br label %107

107:                                              ; preds = %106, %68
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 88, ptr %5) #5
  %108 = load i32, ptr %13, align 4
  switch i32 %108, label %110 [
    i32 0, label %109
    i32 1, label %109
  ]

109:                                              ; preds = %107, %107, %19
  ret void

110:                                              ; preds = %107
  unreachable
}

declare void @mln_rbtree_delete(ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mln_json_kv_free(ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { "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 #4 = { nounwind "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 #5 = { 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"}
!23 = !{!14, !6, i64 0}
!24 = !{!14, !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"

%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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @mln_json_kv_cmp(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @mln_json_obj_remove(ptr nocapture noundef nonnull readonly %0, ptr noundef nonnull %1) local_unnamed_addr #2 {
  %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 %34

6:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 88, ptr nonnull %3) #5
  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
  %.032 = load ptr, ptr %10, align 8, !tbaa !11
  %.not33 = icmp eq ptr %.032, %11
  br i1 %.not33, label %.critedge, label %.lr.ph

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

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

.critedge.loopexit:                               ; preds = %14, %.lr.ph
  %.0.lcssa.ph = phi ptr [ %.034, %.lr.ph ], [ %.0, %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 ]
  %.0.lcssa = phi ptr [ %.032, %6 ], [ %.0.lcssa.ph, %.critedge.loopexit ]
  %17 = getelementptr inbounds i8, ptr %16, i64 40
  %18 = icmp eq ptr %.0.lcssa, %17
  br i1 %18, label %33, label %19

19:                                               ; preds = %.critedge
  call void @mln_rbtree_delete(ptr noundef %16, ptr noundef %.0.lcssa) #5
  %20 = getelementptr inbounds i8, ptr %.0.lcssa, i64 48
  %21 = load i32, ptr %20, align 8
  %22 = and i32 %21, 1
  %23 = load ptr, ptr %.0.lcssa, align 8, !tbaa !13
  %.not29 = icmp eq ptr %23, null
  br i1 %.not29, label %25, label %24

24:                                               ; preds = %19
  call void @mln_json_kv_free(ptr noundef nonnull %23)
  br label %25

25:                                               ; preds = %24, %19
  %.not30 = icmp eq i32 %22, 0
  br i1 %.not30, label %26, label %33

26:                                               ; preds = %25
  %27 = load ptr, ptr %8, align 8, !tbaa !10
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  %.not31 = icmp eq ptr %28, null
  br i1 %.not31, label %32, label %29

29:                                               ; preds = %26
  %30 = getelementptr inbounds i8, ptr %27, i64 16
  %31 = load ptr, ptr %30, align 8, !tbaa !20
  call void %31(ptr noundef nonnull %.0.lcssa) #5
  br label %33

32:                                               ; preds = %26
  call void @free(ptr noundef nonnull %.0.lcssa) #5
  br label %33

33:                                               ; preds = %25, %32, %29, %.critedge
  call void @llvm.lifetime.end.p0(i64 88, ptr nonnull %3) #5
  br label %34

34:                                               ; preds = %2, %33
  ret void
}

declare void @mln_rbtree_delete(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @mln_json_kv_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = { "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 #4 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #5 = { 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"}
!17 = !{!18, !12, i64 0}
!18 = !{!"rbtree_s", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !14, i64 40, !12, i64 96, !12, i64 104, !12, i64 112, !12, i64 120, !12, i64 128, !19, i64 136, !7, i64 144}
!19 = !{!"long", !8, i64 0}
!20 = !{!18, !12, i64 16}


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