; LLVM IR from jingweizhanghuai/Morn :: src/util (morn_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.JSONNode = type { %union.anon.0, i8, ptr }
%union.anon.0 = type { double }
%struct.ListNode = type <{ %union.JsonData, i8, i32, [3 x i8], ptr }>
%union.JsonData = type { double }
%struct.ArrayNode = type <{ %union.JsonData, i8, i32, [3 x 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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 @JSONListRead(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare ptr @JSONSubNode(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local ptr @JSONArrayRead(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @m_JSONRead(ptr noundef %0, i64 noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.JSONNode, ptr %10, i32 0, i32 1
  %12 = load i8, ptr %11, align 8, !tbaa !11
  %13 = zext i8 %12 to i32
  %14 = icmp slt i32 %13, 10
  br i1 %14, label %15, label %16

15:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  br label %73

16:                                               ; preds = %3
  %17 = load i64, ptr %6, align 8, !tbaa !9
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.JSONNode, ptr %18, i32 0, i32 0
  %20 = load i16, ptr %19, align 8, !tbaa !13
  %21 = zext i16 %20 to i64
  %22 = icmp eq i64 %17, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %16
  store ptr null, ptr %4, align 8
  br label %73

24:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %25 = load i64, ptr %6, align 8, !tbaa !9
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.JSONNode, ptr %26, i32 0, i32 0
  %28 = load i16, ptr %27, align 8, !tbaa !13
  %29 = zext i16 %28 to i64
  %30 = icmp slt i64 %25, %29
  br i1 %30, label %31, label %48

31:                                               ; preds = %24
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.JSONNode, ptr %32, i32 0, i32 1
  %34 = load i8, ptr %33, align 8, !tbaa !11
  %35 = zext i8 %34 to i32
  %36 = icmp slt i32 %35, 12
  br i1 %36, label %37, label %42

37:                                               ; preds = %31
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = call ptr @JSONSubNode(ptr noundef %38)
  %40 = load i64, ptr %6, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.ListNode, ptr %39, i64 %40
  store ptr %41, ptr %8, align 8, !tbaa !5
  br label %47

42:                                               ; preds = %31
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = call ptr @JSONSubNode(ptr noundef %43)
  %45 = load i64, ptr %6, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.ArrayNode, ptr %44, i64 %45
  store ptr %46, ptr %8, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %42, %37
  br label %65

48:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = inttoptr i64 %49 to ptr
  store ptr %50, ptr %9, align 8, !tbaa !5
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 0
  %53 = load i8, ptr %52, align 1, !tbaa !13
  %54 = sext i8 %53 to i32
  %55 = icmp eq i32 %54, 91
  br i1 %55, label %56, label %60

56:                                               ; preds = %48
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = call ptr @JSONArrayRead(ptr noundef %57, ptr noundef %58)
  store ptr %59, ptr %8, align 8, !tbaa !5
  br label %64

60:                                               ; preds = %48
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = call ptr @JSONListRead(ptr noundef %61, ptr noundef %62)
  store ptr %63, ptr %8, align 8, !tbaa !5
  br label %64

64:                                               ; preds = %60, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %65

65:                                               ; preds = %64, %47
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = icmp ne ptr %66, null
  br i1 %67, label %68, label %71

68:                                               ; preds = %65
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %69, ptr align 8 %70, i64 24, i1 false), !tbaa.struct !14
  br label %71

71:                                               ; preds = %68, %65
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %72, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %73

73:                                               ; preds = %71, %23, %15
  %74 = load ptr, ptr %4, align 8
  ret ptr %74
}

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


; 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.ListNode = type <{ %union.JsonData, i8, i32, [3 x i8], ptr }>
%union.JsonData = type { double }
%struct.ArrayNode = type <{ %union.JsonData, i8, i32, [3 x i8] }>

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

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

; Function Attrs: inlinehint nounwind uwtable
declare ptr @JSONSubNode(ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local ptr @m_JSONRead(ptr noundef %0, i64 noundef %1, ptr noundef writeonly %2) local_unnamed_addr #1 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i8, ptr %4, align 8, !tbaa !5
  %6 = icmp ult i8 %5, 10
  br i1 %6, label %30, label %7

7:                                                ; preds = %3
  %8 = load i16, ptr %0, align 8, !tbaa !10
  %9 = zext i16 %8 to i64
  %10 = icmp eq i64 %9, %1
  br i1 %10, label %30, label %11

11:                                               ; preds = %7
  %12 = icmp sgt i64 %9, %1
  br i1 %12, label %13, label %20

13:                                               ; preds = %11
  %14 = icmp ult i8 %5, 12
  %15 = tail call ptr @JSONSubNode(ptr noundef nonnull %0)
  br i1 %14, label %16, label %18

16:                                               ; preds = %13
  %17 = getelementptr inbounds %struct.ListNode, ptr %15, i64 %1
  br label %28

18:                                               ; preds = %13
  %19 = getelementptr inbounds %struct.ArrayNode, ptr %15, i64 %1
  br label %28

20:                                               ; preds = %11
  %21 = inttoptr i64 %1 to ptr
  %22 = load i8, ptr %21, align 1, !tbaa !10
  %23 = icmp eq i8 %22, 91
  br i1 %23, label %24, label %26

24:                                               ; preds = %20
  %25 = tail call ptr @JSONArrayRead(ptr noundef nonnull %0, ptr noundef nonnull %21)
  br label %28

26:                                               ; preds = %20
  %27 = tail call ptr @JSONListRead(ptr noundef nonnull %0, ptr noundef nonnull %21)
  br label %28

28:                                               ; preds = %24, %26, %16, %18
  %.1 = phi ptr [ %17, %16 ], [ %19, %18 ], [ %25, %24 ], [ %27, %26 ]
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %30, label %29

29:                                               ; preds = %28
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %2, ptr noundef nonnull align 8 dereferenceable(24) %.1, i64 24, i1 false), !tbaa.struct !11
  br label %30

30:                                               ; preds = %28, %29, %7, %3
  %.0 = phi ptr [ null, %3 ], [ null, %7 ], [ %.1, %29 ], [ %.1, %28 ]
  ret ptr %.0
}

attributes #0 = { mustprogress nocallback nofree 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 = { 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" }

!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 8}
!6 = !{!"JSONNode", !7, i64 0, !7, i64 8, !9, i64 16}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!7, !7, i64 0}
!11 = !{i64 0, i64 8, !10, i64 8, i64 1, !10, i64 16, i64 8, !12}
!12 = !{!9, !9, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass