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

; 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_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 }

; 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
define dso_local void @json_pointer_tokenize(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.json_string_s, align 8
  %6 = alloca %struct.json_string_s, align 8
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  %9 = alloca %struct.json_value_s, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  call void @json_array_initialize(ptr noundef %10)
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  call void @json_array_allocate(ptr noundef %11)
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %20, label %14

14:                                               ; preds = %2
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 0
  %17 = load i8, ptr %16, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %14, %2
  br label %68

21:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #3
  call void @json_string_initialize(ptr noundef %5)
  call void @json_string_allocate(ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #3
  call void @json_string_initialize(ptr noundef %6)
  call void @json_string_allocate(ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !10
  br label %22

22:                                               ; preds = %65, %21
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i32, ptr %8, align 4, !tbaa !10
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %23, i64 %25
  %27 = load i8, ptr %26, align 1, !tbaa !9
  store i8 %27, ptr %7, align 1, !tbaa !9
  %28 = load i8, ptr %7, align 1, !tbaa !9
  %29 = sext i8 %28 to i32
  %30 = icmp ne i32 %29, 47
  br i1 %30, label %31, label %37

31:                                               ; preds = %22
  %32 = load i8, ptr %7, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %37

35:                                               ; preds = %31
  %36 = load i8, ptr %7, align 1, !tbaa !9
  call void @json_string_append(ptr noundef %6, i8 noundef signext %36)
  br label %37

37:                                               ; preds = %35, %31, %22
  %38 = getelementptr inbounds %struct.json_string_s, ptr %6, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !12
  %40 = icmp ugt i32 %39, 0
  br i1 %40, label %41, label %55

41:                                               ; preds = %37
  %42 = load i8, ptr %7, align 1, !tbaa !9
  %43 = sext i8 %42 to i32
  %44 = icmp eq i32 %43, 47
  br i1 %44, label %49, label %45

45:                                               ; preds = %41
  %46 = load i8, ptr %7, align 1, !tbaa !9
  %47 = sext i8 %46 to i32
  %48 = icmp eq i32 %47, 0
  br i1 %48, label %49, label %55

49:                                               ; preds = %45, %41
  call void @json_string_append(ptr noundef %6, i8 noundef signext 0)
  call void @convert_buffer_to_token(ptr noundef %6, ptr noundef %5)
  call void @llvm.lifetime.start.p0(i64 40, ptr %9) #3
  %50 = getelementptr inbounds %struct.json_value_s, ptr %9, i32 0, i32 0
  store i32 2, ptr %50, align 8, !tbaa !14
  %51 = getelementptr inbounds %struct.json_value_s, ptr %9, i32 0, i32 2
  call void @json_string_initialize(ptr noundef %51)
  %52 = getelementptr inbounds %struct.json_value_s, ptr %9, i32 0, i32 2
  call void @json_string_allocate(ptr noundef %52)
  %53 = getelementptr inbounds %struct.json_value_s, ptr %9, i32 0, i32 2
  call void @json_string_assign(ptr noundef %53, ptr noundef %5)
  %54 = load ptr, ptr %4, align 8, !tbaa !5
  call void @json_array_append(ptr noundef %54, ptr noundef %9)
  call void @json_string_clear(ptr noundef %5)
  call void @json_string_clear(ptr noundef %6)
  call void @llvm.lifetime.end.p0(i64 40, ptr %9) #3
  br label %55

55:                                               ; preds = %49, %45, %37
  %56 = load i32, ptr %8, align 4, !tbaa !10
  %57 = add i32 %56, 1
  store i32 %57, ptr %8, align 4, !tbaa !10
  br label %58

58:                                               ; preds = %55
  %59 = load i8, ptr %7, align 1, !tbaa !9
  %60 = sext i8 %59 to i32
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %65

62:                                               ; preds = %58
  %63 = load i32, ptr %8, align 4, !tbaa !10
  %64 = icmp ult i32 %63, 65535
  br label %65

65:                                               ; preds = %62, %58
  %66 = phi i1 [ false, %58 ], [ %64, %62 ]
  br i1 %66, label %22, label %67, !llvm.loop !16

67:                                               ; preds = %65
  call void @json_string_delete(ptr noundef %5)
  call void @json_string_delete(ptr noundef %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #3
  br label %68

68:                                               ; preds = %67, %20
  ret void
}

declare void @json_array_initialize(ptr noundef) #2

declare void @json_array_allocate(ptr noundef) #2

declare void @json_string_initialize(ptr noundef) #2

declare void @json_string_allocate(ptr noundef) #2

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

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

declare void @json_string_assign(ptr noundef, ptr noundef) #2

declare void @json_array_append(ptr noundef, ptr noundef) #2

declare void @json_string_clear(ptr noundef) #2

declare void @json_string_delete(ptr noundef) #2

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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"json_string_s", !11, i64 0, !11, i64 4, !6, i64 8}
!14 = !{!15, !11, i64 0}
!15 = !{!"json_value_s", !11, i64 0, !6, i64 8, !7, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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

%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 }

; 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
define dso_local void @json_pointer_tokenize(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca %struct.json_string_s, align 8
  %4 = alloca %struct.json_string_s, align 8
  %5 = alloca %struct.json_value_s, align 8
  tail call void @json_array_initialize(ptr noundef %1) #3
  tail call void @json_array_allocate(ptr noundef %1) #3
  %6 = icmp eq ptr %0, null
  br i1 %6, label %27, label %7

7:                                                ; preds = %2
  %8 = load i8, ptr %0, align 1, !tbaa !5
  %9 = icmp eq i8 %8, 0
  br i1 %9, label %27, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  call void @json_string_initialize(ptr noundef nonnull %3) #3
  call void @json_string_allocate(ptr noundef nonnull %3) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #3
  call void @json_string_initialize(ptr noundef nonnull %4) #3
  call void @json_string_allocate(ptr noundef nonnull %4) #3
  %11 = getelementptr inbounds i8, ptr %5, i64 16
  br label %12

12:                                               ; preds = %22, %10
  %.0 = phi i32 [ 0, %10 ], [ %23, %22 ]
  %13 = zext nneg i32 %.0 to i64
  %14 = getelementptr inbounds i8, ptr %0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = icmp ne i8 %15, 0
  switch i8 %15, label %17 [
    i8 47, label %18
    i8 0, label %18
  ]

17:                                               ; preds = %12
  call void @json_string_append(ptr noundef nonnull %4, i8 noundef signext %15) #3
  br label %18

18:                                               ; preds = %12, %12, %17
  %19 = load i32, ptr %4, align 8, !tbaa !8
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %22, label %20

20:                                               ; preds = %18
  switch i8 %15, label %22 [
    i8 47, label %21
    i8 0, label %21
  ]

21:                                               ; preds = %20, %20
  call void @json_string_append(ptr noundef nonnull %4, i8 noundef signext 0) #3
  call void @convert_buffer_to_token(ptr noundef nonnull %4, ptr noundef nonnull %3)
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %5) #3
  store i32 2, ptr %5, align 8, !tbaa !12
  call void @json_string_initialize(ptr noundef nonnull %11) #3
  call void @json_string_allocate(ptr noundef nonnull %11) #3
  call void @json_string_assign(ptr noundef nonnull %11, ptr noundef nonnull %3) #3
  call void @json_array_append(ptr noundef %1, ptr noundef nonnull %5) #3
  call void @json_string_clear(ptr noundef nonnull %3) #3
  call void @json_string_clear(ptr noundef nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %5) #3
  br label %22

22:                                               ; preds = %20, %21, %18
  %23 = add nuw nsw i32 %.0, 1
  %24 = icmp ult i32 %.0, 65534
  %25 = and i1 %16, %24
  br i1 %25, label %12, label %26, !llvm.loop !14

26:                                               ; preds = %22
  call void @json_string_delete(ptr noundef nonnull %3) #3
  call void @json_string_delete(ptr noundef nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  br label %27

27:                                               ; preds = %2, %7, %26
  ret void
}

declare void @json_array_initialize(ptr noundef) local_unnamed_addr #2

declare void @json_array_allocate(ptr noundef) local_unnamed_addr #2

declare void @json_string_initialize(ptr noundef) local_unnamed_addr #2

declare void @json_string_allocate(ptr noundef) local_unnamed_addr #2

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

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

declare void @json_string_assign(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @json_array_append(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @json_string_clear(ptr noundef) local_unnamed_addr #2

declare void @json_string_delete(ptr noundef) local_unnamed_addr #2

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass