; 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

declare void @json_string_append(ptr noundef, i8 noundef signext) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @json_parse_number(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 %76 [
    i32 11, label %8
    i32 12, label %16
    i32 5, label %24
    i32 7, label %52
    i32 9, label %52
  ]

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 2
  %11 = load i8, ptr %4, align 1, !tbaa !9
  call void @json_string_append(ptr noundef %10, i8 noundef signext %11)
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.json_parse_state_s, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !10
  %15 = getelementptr inbounds %struct.json_value_s, ptr %14, i32 0, i32 0
  store i32 3, ptr %15, align 8, !tbaa !14
  br label %80

16:                                               ; preds = %2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.json_parse_state_s, ptr %17, i32 0, i32 2
  %19 = load i8, ptr %4, align 1, !tbaa !9
  call void @json_string_append(ptr noundef %18, i8 noundef signext %19)
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.json_parse_state_s, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !10
  %23 = getelementptr inbounds %struct.json_value_s, ptr %22, i32 0, i32 0
  store i32 3, ptr %23, align 8, !tbaa !14
  br label %80

24:                                               ; preds = %2
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.json_parse_state_s, ptr %25, i32 0, i32 2
  call void @json_string_append(ptr noundef %26, i8 noundef signext 0)
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.json_parse_state_s, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.json_parse_state_s, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !10
  call void @json_merge_buffer_to_value(ptr noundef %28, ptr noundef %31)
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.json_parse_state_s, ptr %32, i32 0, i32 2
  call void @json_string_clear(ptr noundef %33)
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.json_parse_state_s, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !10
  %37 = getelementptr inbounds %struct.json_value_s, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !16
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.json_parse_state_s, ptr %39, i32 0, i32 0
  store ptr %38, ptr %40, align 8, !tbaa !10
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.json_parse_state_s, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !10
  %44 = call ptr @json_assign_parser(ptr noundef %43)
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.json_parse_state_s, ptr %45, i32 0, i32 1
  store ptr %44, ptr %46, align 8, !tbaa !17
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.json_parse_state_s, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = load i8, ptr %4, align 1, !tbaa !9
  call void %49(ptr noundef %50, i8 noundef signext %51)
  br label %80

52:                                               ; preds = %2, %2
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.json_parse_state_s, ptr %53, i32 0, i32 2
  call void @json_string_append(ptr noundef %54, i8 noundef signext 0)
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.json_parse_state_s, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.json_parse_state_s, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !10
  call void @json_merge_buffer_to_value(ptr noundef %56, ptr noundef %59)
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.json_parse_state_s, ptr %60, i32 0, i32 2
  call void @json_string_clear(ptr noundef %61)
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.json_parse_state_s, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !10
  %65 = getelementptr inbounds %struct.json_value_s, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !16
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.json_parse_state_s, ptr %67, i32 0, i32 0
  store ptr %66, ptr %68, align 8, !tbaa !10
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.json_parse_state_s, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !10
  %72 = getelementptr inbounds %struct.json_value_s, ptr %71, i32 0, i32 1
  %73 = load ptr, ptr %72, align 8, !tbaa !16
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.json_parse_state_s, ptr %74, i32 0, i32 0
  store ptr %73, ptr %75, align 8, !tbaa !10
  br label %80

76:                                               ; preds = %2
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.json_parse_state_s, ptr %77, i32 0, i32 2
  %79 = load i8, ptr %4, align 1, !tbaa !9
  call void @json_string_append(ptr noundef %78, i8 noundef signext %79)
  br label %80

80:                                               ; preds = %76, %52, %24, %16, %8
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.json_parse_state_s, ptr %81, i32 0, i32 0
  %83 = load ptr, ptr %82, align 8, !tbaa !10
  %84 = call ptr @json_assign_parser(ptr noundef %83)
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.json_parse_state_s, ptr %85, i32 0, i32 1
  store ptr %84, ptr %86, align 8, !tbaa !17
  ret void
}

declare void @json_string_clear(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, !13, i64 0}
!15 = !{!"json_value_s", !13, i64 0, !6, i64 8, !7, i64 16}
!16 = !{!15, !6, i64 8}
!17 = !{!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

declare void @json_string_append(ptr noundef, i8 noundef signext) local_unnamed_addr #0

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

; 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_number(ptr 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
  switch i32 %4, label %27 [
    i32 11, label %5
    i32 12, label %8
    i32 5, label %11
    i32 7, label %19
    i32 9, label %19
  ]

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @json_string_append(ptr noundef nonnull %6, i8 noundef signext %1) #2
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  store i32 3, ptr %7, align 8, !tbaa !12
  br label %29

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @json_string_append(ptr noundef nonnull %9, i8 noundef signext %1) #2
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  store i32 3, ptr %10, align 8, !tbaa !12
  br label %29

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @json_string_append(ptr noundef nonnull %12, i8 noundef signext 0) #2
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @json_merge_buffer_to_value(ptr noundef nonnull %12, ptr noundef %13)
  tail call void @json_string_clear(ptr noundef nonnull %12) #2
  %14 = load ptr, ptr %0, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  store ptr %16, ptr %0, align 8, !tbaa !5
  %17 = tail call ptr @json_assign_parser(ptr noundef %16)
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %17, ptr %18, align 8, !tbaa !15
  tail call void %17(ptr noundef nonnull %0, i8 noundef signext %1) #2
  br label %29

19:                                               ; preds = %2, %2
  %20 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @json_string_append(ptr noundef nonnull %20, i8 noundef signext 0) #2
  %21 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @json_merge_buffer_to_value(ptr noundef nonnull %20, ptr noundef %21)
  tail call void @json_string_clear(ptr noundef nonnull %20) #2
  %22 = load ptr, ptr %0, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %24, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  store ptr %26, ptr %0, align 8, !tbaa !5
  br label %29

27:                                               ; preds = %2
  %28 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @json_string_append(ptr noundef nonnull %28, i8 noundef signext %1) #2
  br label %29

29:                                               ; preds = %27, %19, %11, %8, %5
  %30 = load ptr, ptr %0, align 8, !tbaa !5
  %31 = tail call ptr @json_assign_parser(ptr noundef %30)
  %32 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %31, ptr %32, align 8, !tbaa !15
  ret void
}

declare void @json_string_clear(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, !11, i64 0}
!13 = !{!"json_value_s", !11, i64 0, !7, i64 8, !8, i64 16}
!14 = !{!13, !7, i64 8}
!15 = !{!6, !7, i64 8}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,TailCallElimPass