; LLVM IR from Slingshot-Physics/slingshot-community :: common/json/src (json_deserialize)

; 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.json_parse_state_s = type { ptr, ptr, %struct.json_string_s }
%struct.json_string_s = type { i32, i32, ptr }
%struct.json_value_s = type { i32, ptr, %union.anon }
%union.anon = type { %struct.json_object_s }
%struct.json_object_s = type { i32, i32, ptr, ptr }

declare i32 @json_character_type(i32 noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @json_parse_array(ptr noundef %0, i8 noundef signext %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i8 %1, ptr %4, align 1, !tbaa !9
  %5 = load i8, ptr %4, align 1, !tbaa !9
  %6 = sext i8 %5 to i32
  %7 = call i32 @json_character_type(i32 noundef %6)
  switch i32 %7, label %23 [
    i32 5, label %8
    i32 9, label %15
  ]

8:                                                ; preds = %2
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.json_parse_state_s, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !10
  %12 = call ptr @json_value_append_new_blank_value_to_array(ptr noundef %11)
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.json_parse_state_s, ptr %13, i32 0, i32 0
  store ptr %12, ptr %14, align 8, !tbaa !10
  br label %24

15:                                               ; preds = %2
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.json_parse_state_s, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !10
  %19 = getelementptr inbounds %struct.json_value_s, ptr %18, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !14
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.json_parse_state_s, ptr %21, i32 0, i32 0
  store ptr %20, ptr %22, align 8, !tbaa !10
  br label %24

23:                                               ; preds = %2
  br label %24

24:                                               ; preds = %23, %15, %8
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.json_parse_state_s, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !10
  %28 = call ptr @json_assign_parser(ptr noundef %27)
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.json_parse_state_s, ptr %29, i32 0, i32 1
  store ptr %28, ptr %30, align 8, !tbaa !16
  ret void
}

declare ptr @json_value_append_new_blank_value_to_array(ptr noundef) #0

attributes #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 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !6, i64 0}
!11 = !{!"json_parse_state_s", !6, i64 0, !6, i64 8, !12, i64 16}
!12 = !{!"json_string_s", !13, i64 0, !13, i64 4, !6, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 8}
!15 = !{!"json_value_s", !13, i64 0, !6, i64 8, !7, i64 16}
!16 = !{!11, !6, i64 8}


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

declare i32 @json_character_type(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @json_parse_array(ptr nocapture noundef %0, i8 noundef signext %1) local_unnamed_addr #1 {
  %3 = sext i8 %1 to i32
  %4 = tail call i32 @json_character_type(i32 noundef %3) #2
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  switch i32 %4, label %._crit_edge [
    i32 5, label %5
    i32 9, label %7
  ]

5:                                                ; preds = %2
  %6 = tail call ptr @json_value_append_new_blank_value_to_array(ptr noundef %.pre) #2
  br label %._crit_edge.sink.split

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %.pre, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  br label %._crit_edge.sink.split

._crit_edge.sink.split:                           ; preds = %5, %7
  %.sink = phi ptr [ %9, %7 ], [ %6, %5 ]
  store ptr %.sink, ptr %0, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.sink.split, %2
  %10 = phi ptr [ %.pre, %2 ], [ %.sink, %._crit_edge.sink.split ]
  %11 = tail call ptr @json_assign_parser(ptr noundef %10)
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %11, ptr %12, align 8, !tbaa !14
  ret void
}

declare ptr @json_value_append_new_blank_value_to_array(ptr noundef) local_unnamed_addr #0

attributes #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 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, !7, i64 0}
!6 = !{!"json_parse_state_s", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"json_string_s", !11, i64 0, !11, i64 4, !7, i64 8}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !7, i64 8}
!13 = !{!"json_value_s", !11, i64 0, !7, i64 8, !8, i64 16}
!14 = !{!6, !7, i64 8}


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