; 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

declare void @json_string_clear(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @json_parse_exponent(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 %60 [
    i32 5, label %8
    i32 7, label %36
    i32 9, label %36
  ]

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
  %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
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.json_parse_state_s, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load i8, ptr %4, align 1, !tbaa !9
  call void %33(ptr noundef %34, i8 noundef signext %35)
  br label %64

36:                                               ; preds = %2, %2
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.json_parse_state_s, ptr %37, i32 0, i32 2
  call void @json_string_append(ptr noundef %38, i8 noundef signext 0)
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.json_parse_state_s, ptr %39, i32 0, i32 2
  %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
  call void @json_merge_buffer_to_value(ptr noundef %40, ptr noundef %43)
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.json_parse_state_s, ptr %44, i32 0, i32 2
  call void @json_string_clear(ptr noundef %45)
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.json_parse_state_s, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !10
  %49 = getelementptr inbounds %struct.json_value_s, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !14
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.json_parse_state_s, ptr %51, i32 0, i32 0
  store ptr %50, ptr %52, align 8, !tbaa !10
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.json_parse_state_s, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !10
  %56 = getelementptr inbounds %struct.json_value_s, ptr %55, i32 0, i32 1
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.json_parse_state_s, ptr %58, i32 0, i32 0
  store ptr %57, ptr %59, align 8, !tbaa !10
  br label %64

60:                                               ; preds = %2
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.json_parse_state_s, ptr %61, i32 0, i32 2
  %63 = load i8, ptr %4, align 1, !tbaa !9
  call void @json_string_append(ptr noundef %62, i8 noundef signext %63)
  br label %64

64:                                               ; preds = %60, %36, %8
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.json_parse_state_s, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !10
  %68 = call ptr @json_assign_parser(ptr noundef %67)
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.json_parse_state_s, ptr %69, i32 0, i32 1
  store ptr %68, ptr %70, align 8, !tbaa !16
  ret void
}

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

declare void @json_string_clear(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @json_parse_exponent(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 %21 [
    i32 5, label %5
    i32 7, label %13
    i32 9, label %13
  ]

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @json_string_append(ptr noundef nonnull %6, 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 %6, ptr noundef %7)
  tail call void @json_string_clear(ptr noundef nonnull %6) #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
  %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
  tail call void %11(ptr noundef nonnull %0, i8 noundef signext %1) #2
  br label %23

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

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

23:                                               ; preds = %21, %13, %5
  %24 = load ptr, ptr %0, align 8, !tbaa !5
  %25 = tail call ptr @json_assign_parser(ptr noundef %24)
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %25, ptr %26, align 8, !tbaa !14
  ret void
}

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: DSEPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,SROAPass,TailCallElimPass