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

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

; Function Attrs: nounwind uwtable
define dso_local void @json_value_allocate_type(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.json_value_s, ptr %8, i32 0, i32 0
  store i32 %7, ptr %9, align 8, !tbaa !11
  %10 = load i32, ptr %4, align 4, !tbaa !9
  switch i32 %10, label %103 [
    i32 0, label %11
    i32 1, label %63
    i32 2, label %98
  ]

11:                                               ; preds = %2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.json_value_s, ptr %12, i32 0, i32 2
  call void @json_object_initialize(ptr noundef %13)
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.json_value_s, ptr %14, i32 0, i32 2
  call void @json_object_allocate(ptr noundef %15)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %59, %11
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.json_value_s, ptr %18, i32 0, i32 2
  %20 = getelementptr inbounds %struct.json_object_s, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !13
  %22 = icmp ult i32 %17, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %62

24:                                               ; preds = %16
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.json_value_s, ptr %25, i32 0, i32 2
  %27 = getelementptr inbounds %struct.json_object_s, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds %struct.json_value_s, ptr %28, i64 %30
  %32 = getelementptr inbounds %struct.json_value_s, ptr %31, i32 0, i32 0
  store i32 2, ptr %32, align 8, !tbaa !11
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.json_value_s, ptr %34, i32 0, i32 2
  %36 = getelementptr inbounds %struct.json_object_s, ptr %35, i32 0, i32 2
  %37 = load ptr, ptr %36, align 8, !tbaa !13
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds %struct.json_value_s, ptr %37, i64 %39
  %41 = getelementptr inbounds %struct.json_value_s, ptr %40, i32 0, i32 1
  store ptr %33, ptr %41, align 8, !tbaa !14
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.json_value_s, ptr %42, i32 0, i32 2
  %44 = getelementptr inbounds %struct.json_object_s, ptr %43, i32 0, i32 3
  %45 = load ptr, ptr %44, align 8, !tbaa !13
  %46 = load i32, ptr %5, align 4, !tbaa !9
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds %struct.json_value_s, ptr %45, i64 %47
  %49 = getelementptr inbounds %struct.json_value_s, ptr %48, i32 0, i32 0
  store i32 100, ptr %49, align 8, !tbaa !11
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.json_value_s, ptr %51, i32 0, i32 2
  %53 = getelementptr inbounds %struct.json_object_s, ptr %52, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !13
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds %struct.json_value_s, ptr %54, i64 %56
  %58 = getelementptr inbounds %struct.json_value_s, ptr %57, i32 0, i32 1
  store ptr %50, ptr %58, align 8, !tbaa !14
  br label %59

59:                                               ; preds = %24
  %60 = load i32, ptr %5, align 4, !tbaa !9
  %61 = add i32 %60, 1
  store i32 %61, ptr %5, align 4, !tbaa !9
  br label %16, !llvm.loop !15

62:                                               ; preds = %23
  br label %104

63:                                               ; preds = %2
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.json_value_s, ptr %64, i32 0, i32 2
  call void @json_array_initialize(ptr noundef %65)
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.json_value_s, ptr %66, i32 0, i32 2
  call void @json_array_allocate(ptr noundef %67)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %68

68:                                               ; preds = %94, %63
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.json_value_s, ptr %70, i32 0, i32 2
  %72 = getelementptr inbounds %struct.json_object_s, ptr %71, i32 0, i32 1
  %73 = load i32, ptr %72, align 4, !tbaa !13
  %74 = icmp ult i32 %69, %73
  br i1 %74, label %76, label %75

75:                                               ; preds = %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %97

76:                                               ; preds = %68
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.json_value_s, ptr %77, i32 0, i32 2
  %79 = getelementptr inbounds %struct.json_array_s, ptr %78, i32 0, i32 2
  %80 = load ptr, ptr %79, align 8, !tbaa !13
  %81 = load i32, ptr %6, align 4, !tbaa !9
  %82 = zext i32 %81 to i64
  %83 = getelementptr inbounds %struct.json_value_s, ptr %80, i64 %82
  %84 = getelementptr inbounds %struct.json_value_s, ptr %83, i32 0, i32 0
  store i32 100, ptr %84, align 8, !tbaa !11
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.json_value_s, ptr %86, i32 0, i32 2
  %88 = getelementptr inbounds %struct.json_array_s, ptr %87, i32 0, i32 2
  %89 = load ptr, ptr %88, align 8, !tbaa !13
  %90 = load i32, ptr %6, align 4, !tbaa !9
  %91 = zext i32 %90 to i64
  %92 = getelementptr inbounds %struct.json_value_s, ptr %89, i64 %91
  %93 = getelementptr inbounds %struct.json_value_s, ptr %92, i32 0, i32 1
  store ptr %85, ptr %93, align 8, !tbaa !14
  br label %94

94:                                               ; preds = %76
  %95 = load i32, ptr %6, align 4, !tbaa !9
  %96 = add i32 %95, 1
  store i32 %96, ptr %6, align 4, !tbaa !9
  br label %68, !llvm.loop !17

97:                                               ; preds = %75
  br label %104

98:                                               ; preds = %2
  %99 = load ptr, ptr %3, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.json_value_s, ptr %99, i32 0, i32 2
  call void @json_string_initialize(ptr noundef %100)
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.json_value_s, ptr %101, i32 0, i32 2
  call void @json_string_allocate(ptr noundef %102)
  br label %104

103:                                              ; preds = %2
  br label %104

104:                                              ; preds = %103, %98, %97, %62
  ret void
}

declare void @json_object_initialize(ptr noundef) #1

declare void @json_object_allocate(ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

declare void @json_array_initialize(ptr noundef) #1

declare void @json_array_allocate(ptr noundef) #1

declare void @json_string_initialize(ptr noundef) #1

declare void @json_string_allocate(ptr noundef) #1

attributes #0 = { 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 #1 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"json_value_s", !10, i64 0, !6, i64 8, !7, i64 16}
!13 = !{!7, !7, i64 0}
!14 = !{!12, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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_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: nounwind uwtable
define dso_local void @json_value_allocate_type(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  store i32 %1, ptr %0, align 8, !tbaa !5
  switch i32 %1, label %.loopexit [
    i32 0, label %3
    i32 1, label %21
    i32 2, label %34
  ]

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @json_object_initialize(ptr noundef nonnull %4) #2
  tail call void @json_object_allocate(ptr noundef nonnull %4) #2
  %5 = getelementptr inbounds i8, ptr %0, i64 20
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %.not34 = icmp eq i32 %6, 0
  br i1 %.not34, label %.loopexit, label %.lr.ph33

.lr.ph33:                                         ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  br label %9

9:                                                ; preds = %.lr.ph33, %9
  %indvars.iv37 = phi i64 [ 0, %.lr.ph33 ], [ %indvars.iv.next38, %9 ]
  %10 = load ptr, ptr %7, align 8, !tbaa !11
  %11 = getelementptr inbounds %struct.json_value_s, ptr %10, i64 %indvars.iv37
  store i32 2, ptr %11, align 8, !tbaa !5
  %12 = load ptr, ptr %7, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct.json_value_s, ptr %12, i64 %indvars.iv37, i32 1
  store ptr %0, ptr %13, align 8, !tbaa !12
  %14 = load ptr, ptr %8, align 8, !tbaa !11
  %15 = getelementptr inbounds %struct.json_value_s, ptr %14, i64 %indvars.iv37
  store i32 100, ptr %15, align 8, !tbaa !5
  %16 = load ptr, ptr %8, align 8, !tbaa !11
  %17 = getelementptr inbounds %struct.json_value_s, ptr %16, i64 %indvars.iv37, i32 1
  store ptr %0, ptr %17, align 8, !tbaa !12
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %18 = load i32, ptr %5, align 4, !tbaa !11
  %19 = zext i32 %18 to i64
  %20 = icmp ult i64 %indvars.iv.next38, %19
  br i1 %20, label %9, label %.loopexit, !llvm.loop !13

21:                                               ; preds = %2
  %22 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @json_array_initialize(ptr noundef nonnull %22) #2
  tail call void @json_array_allocate(ptr noundef nonnull %22) #2
  %23 = getelementptr inbounds i8, ptr %0, i64 20
  %24 = load i32, ptr %23, align 4, !tbaa !11
  %.not = icmp eq i32 %24, 0
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %21
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  br label %26

26:                                               ; preds = %.lr.ph, %26
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %26 ]
  %27 = load ptr, ptr %25, align 8, !tbaa !11
  %28 = getelementptr inbounds %struct.json_value_s, ptr %27, i64 %indvars.iv
  store i32 100, ptr %28, align 8, !tbaa !5
  %29 = load ptr, ptr %25, align 8, !tbaa !11
  %30 = getelementptr inbounds %struct.json_value_s, ptr %29, i64 %indvars.iv, i32 1
  store ptr %0, ptr %30, align 8, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = load i32, ptr %23, align 4, !tbaa !11
  %32 = zext i32 %31 to i64
  %33 = icmp ult i64 %indvars.iv.next, %32
  br i1 %33, label %26, label %.loopexit, !llvm.loop !15

34:                                               ; preds = %2
  %35 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @json_string_initialize(ptr noundef nonnull %35) #2
  tail call void @json_string_allocate(ptr noundef nonnull %35) #2
  br label %.loopexit

.loopexit:                                        ; preds = %26, %9, %21, %3, %2, %34
  ret void
}

declare void @json_object_initialize(ptr noundef) local_unnamed_addr #1

declare void @json_object_allocate(ptr noundef) local_unnamed_addr #1

declare void @json_array_initialize(ptr noundef) local_unnamed_addr #1

declare void @json_array_allocate(ptr noundef) local_unnamed_addr #1

declare void @json_string_initialize(ptr noundef) local_unnamed_addr #1

declare void @json_string_allocate(ptr noundef) local_unnamed_addr #1

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass