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

%union.JsonData = type { double }
%struct.JSONNode = type { %union.anon.0, i8, ptr }
%union.anon.0 = type { double }
%struct.ArrayNode = type <{ %union.JsonData, i8, i32, [3 x i8] }>

@.str = external hidden unnamed_addr constant [76 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [12 x i8], align 1
@__FUNCTION__.JSONArrayRead = external hidden unnamed_addr constant [14 x i8], align 1

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

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @JSONArrayRead(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca %union.JsonData, align 8
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.JSONNode, ptr %14, i32 0, i32 1
  %16 = load i8, ptr %15, align 8, !tbaa !9
  %17 = zext i8 %16 to i32
  %18 = icmp ne i32 %17, 12
  br i1 %18, label %19, label %25

19:                                               ; preds = %13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.JSONNode, ptr %20, i32 0, i32 1
  %22 = load i8, ptr %21, align 8, !tbaa !9
  %23 = zext i8 %22 to i32
  %24 = icmp ne i32 %23, 13
  br label %25

25:                                               ; preds = %19, %13
  %26 = phi i1 [ false, %13 ], [ %24, %19 ]
  %27 = zext i1 %26 to i32
  store i32 %27, ptr %6, align 4, !tbaa !11
  %28 = load i32, ptr %6, align 4, !tbaa !11
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %32

30:                                               ; preds = %25
  %31 = load i32, ptr %6, align 4, !tbaa !11
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %31, i32 noundef -1, ptr noundef @.str, i32 noundef 517, ptr noundef @__FUNCTION__.JSONArrayRead, ptr noundef @.str.8)
  br label %32

32:                                               ; preds = %30, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %33

33:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #4
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %34, i64 1
  %36 = call ptr @StringNumber(ptr noundef %35, ptr noundef %7, ptr noundef %8)
  %37 = getelementptr inbounds i8, ptr %36, i64 1
  store ptr %37, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %38 = load i32, ptr %7, align 8, !tbaa !13
  store i32 %38, ptr %9, align 4, !tbaa !11
  %39 = load i32, ptr %9, align 4, !tbaa !11
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.JSONNode, ptr %40, i32 0, i32 0
  %42 = load i16, ptr %41, align 8, !tbaa !13
  %43 = zext i16 %42 to i32
  %44 = icmp sge i32 %39, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %33
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %90

46:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = call ptr @JSONSubNode(ptr noundef %47)
  %49 = load i32, ptr %9, align 4, !tbaa !11
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %struct.ArrayNode, ptr %48, i64 %50
  store ptr %51, ptr %11, align 8, !tbaa !5
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 0
  %54 = load i8, ptr %53, align 1, !tbaa !13
  %55 = sext i8 %54 to i32
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %46
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %58, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %89

59:                                               ; preds = %46
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 0
  %62 = load i8, ptr %61, align 1, !tbaa !13
  %63 = sext i8 %62 to i32
  %64 = icmp eq i32 %63, 46
  br i1 %64, label %65, label %70

65:                                               ; preds = %59
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds i8, ptr %67, i64 1
  %69 = call ptr @JSONListRead(ptr noundef %66, ptr noundef %68)
  store ptr %69, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %89

70:                                               ; preds = %59
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 0
  %73 = load i8, ptr %72, align 1, !tbaa !13
  %74 = sext i8 %73 to i32
  %75 = icmp eq i32 %74, 91
  br i1 %75, label %76, label %80

76:                                               ; preds = %70
  %77 = load ptr, ptr %11, align 8, !tbaa !5
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = call ptr @JSONArrayRead(ptr noundef %77, ptr noundef %78)
  store ptr %79, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %89

80:                                               ; preds = %70
  br label %81

81:                                               ; preds = %80
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 1, ptr %12, align 4, !tbaa !11
  %82 = load i32, ptr %12, align 4, !tbaa !11
  %83 = icmp ne i32 %82, 0
  br i1 %83, label %84, label %86

84:                                               ; preds = %81
  %85 = load i32, ptr %12, align 4, !tbaa !11
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %85, i32 noundef -1, ptr noundef @.str, i32 noundef 525, ptr noundef @__FUNCTION__.JSONArrayRead, ptr noundef @.str.8)
  br label %86

86:                                               ; preds = %84, %81
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %87

87:                                               ; preds = %86
  br label %88

88:                                               ; preds = %87
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %89

89:                                               ; preds = %88, %76, %65, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %90

90:                                               ; preds = %89, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %91 = load ptr, ptr %3, align 8
  ret ptr %91
}

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 = { "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, !7, i64 8}
!10 = !{!"JSONNode", !7, i64 0, !7, i64 8, !6, i64 16}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}


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

%union.JsonData = type { double }
%struct.ArrayNode = type <{ %union.JsonData, i8, i32, [3 x i8] }>

@.str = external hidden unnamed_addr constant [76 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [12 x i8], align 1
@__FUNCTION__.JSONArrayRead = external hidden unnamed_addr constant [14 x i8], align 1

; 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: nounwind uwtable
declare dso_local ptr @StringNumber(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #2

; 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 #3

; Function Attrs: nounwind uwtable
define dso_local ptr @JSONArrayRead(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca %union.JsonData, align 8
  %4 = alloca i8, align 1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i8, ptr %5, align 8, !tbaa !5
  %7 = add i8 %6, -14
  %spec.select = icmp ult i8 %7, -2
  br i1 %spec.select, label %8, label %9

8:                                                ; preds = %2
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 517, ptr noundef nonnull @__FUNCTION__.JSONArrayRead, ptr noundef nonnull @.str.8) #4
  br label %9

9:                                                ; preds = %8, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %4) #4
  %10 = getelementptr inbounds i8, ptr %1, i64 1
  %11 = call ptr @StringNumber(ptr noundef nonnull %10, ptr noundef nonnull %3, ptr noundef nonnull %4)
  %12 = getelementptr inbounds i8, ptr %11, i64 1
  %13 = load i32, ptr %3, align 8, !tbaa !10
  %14 = load i16, ptr %0, align 8, !tbaa !10
  %15 = zext i16 %14 to i32
  %.not22 = icmp slt i32 %13, %15
  br i1 %.not22, label %16, label %27

16:                                               ; preds = %9
  %17 = call ptr @JSONSubNode(ptr noundef nonnull %0)
  %18 = sext i32 %13 to i64
  %19 = getelementptr inbounds %struct.ArrayNode, ptr %17, i64 %18
  %20 = load i8, ptr %12, align 1, !tbaa !10
  switch i8 %20, label %26 [
    i8 0, label %27
    i8 46, label %21
    i8 91, label %24
  ]

21:                                               ; preds = %16
  %22 = getelementptr inbounds i8, ptr %11, i64 2
  %23 = call ptr @JSONListRead(ptr noundef %19, ptr noundef nonnull %22)
  br label %27

24:                                               ; preds = %16
  %25 = call ptr @JSONArrayRead(ptr noundef %19, ptr noundef nonnull %12)
  br label %27

26:                                               ; preds = %16
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 525, ptr noundef nonnull @__FUNCTION__.JSONArrayRead, ptr noundef nonnull @.str.8) #4
  br label %27

27:                                               ; preds = %21, %24, %26, %16, %9
  %.1 = phi ptr [ null, %9 ], [ %23, %21 ], [ %25, %24 ], [ null, %26 ], [ %19, %16 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  ret ptr %.1
}

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


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