; 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_string(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 %25 [
    i32 1, label %8
  ]

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
  call void @json_string_append(ptr noundef %10, i8 noundef signext 0)
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.json_parse_state_s, ptr %11, i32 0, i32 2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.json_parse_state_s, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !10
  call void @json_merge_buffer_to_value(ptr noundef %12, ptr noundef %15)
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.json_parse_state_s, ptr %16, i32 0, i32 2
  call void @json_string_clear(ptr noundef %17)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.json_parse_state_s, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %19, align 8, !tbaa !10
  %21 = getelementptr inbounds %struct.json_value_s, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.json_parse_state_s, ptr %23, i32 0, i32 0
  store ptr %22, ptr %24, align 8, !tbaa !10
  br label %29

25:                                               ; preds = %2
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.json_parse_state_s, ptr %26, i32 0, i32 2
  %28 = load i8, ptr %4, align 1, !tbaa !9
  call void @json_string_append(ptr noundef %27, i8 noundef signext %28)
  br label %29

29:                                               ; preds = %25, %8
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.json_parse_state_s, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !10
  %33 = call ptr @json_assign_parser(ptr noundef %32)
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.json_parse_state_s, ptr %34, i32 0, i32 1
  store ptr %33, ptr %35, align 8, !tbaa !16
  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, !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

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_string(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
  %cond = icmp eq i32 %4, 1
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  br i1 %cond, label %6, label %11

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

11:                                               ; preds = %2
  tail call void @json_string_append(ptr noundef nonnull %5, i8 noundef signext %1) #2
  %.pre = load ptr, ptr %0, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %11, %6
  %13 = phi ptr [ %.pre, %11 ], [ %10, %6 ]
  %14 = tail call ptr @json_assign_parser(ptr noundef %13)
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %14, ptr %15, align 8, !tbaa !14
  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, !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,SROAPass,SimplifyCFGPass,TailCallElimPass