; LLVM IR from Slingshot-Physics/slingshot-community :: datamodel (helper_json_to_data)

; 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: 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
declare dso_local ptr @get_const_field_by_name(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @copy_optional_dynamic_object_array_field(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i32 noundef %6) #1 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i32 %2, ptr %11, align 4, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store i32 %6, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %21 = load ptr, ptr %9, align 8, !tbaa !5
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = call ptr @get_const_field_by_name(ptr noundef %21, ptr noundef %22)
  store ptr %23, ptr %16, align 8, !tbaa !5
  %24 = load ptr, ptr %16, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %32, label %26

26:                                               ; preds = %7
  %27 = load ptr, ptr %16, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.json_value_s, ptr %27, i32 0, i32 2
  %29 = getelementptr inbounds %struct.json_array_s, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !11
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %26, %7
  %33 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr null, ptr %33, align 8, !tbaa !5
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 0, ptr %34, align 4, !tbaa !9
  store i32 1, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %71

35:                                               ; preds = %26
  %36 = load ptr, ptr %16, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.json_value_s, ptr %36, i32 0, i32 2
  %38 = getelementptr inbounds %struct.json_array_s, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !11
  %40 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 %39, ptr %40, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %41 = load i32, ptr %15, align 4, !tbaa !9
  %42 = load ptr, ptr %12, align 8, !tbaa !5
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = mul i32 %41, %43
  store i32 %44, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  %45 = load i32, ptr %11, align 4, !tbaa !9
  %46 = load i32, ptr %15, align 4, !tbaa !9
  %47 = mul i32 %45, %46
  store i32 %47, ptr %19, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  %48 = load i32, ptr %18, align 4, !tbaa !9
  %49 = load i32, ptr %19, align 4, !tbaa !9
  %50 = icmp ult i32 %48, %49
  br i1 %50, label %51, label %53

51:                                               ; preds = %35
  %52 = load i32, ptr %18, align 4, !tbaa !9
  br label %55

53:                                               ; preds = %35
  %54 = load i32, ptr %19, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %53, %51
  %56 = phi i32 [ %52, %51 ], [ %54, %53 ]
  store i32 %56, ptr %20, align 4, !tbaa !9
  %57 = load i32, ptr %20, align 4, !tbaa !9
  %58 = zext i32 %57 to i64
  %59 = call noalias ptr @malloc(i64 noundef %58) #4
  %60 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %59, ptr %60, align 8, !tbaa !5
  %61 = load ptr, ptr %9, align 8, !tbaa !5
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = load i32, ptr %11, align 4, !tbaa !9
  %66 = load ptr, ptr %13, align 8, !tbaa !5
  %67 = load ptr, ptr %14, align 8, !tbaa !5
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = load i32, ptr %15, align 4, !tbaa !9
  %70 = call i32 @copy_filled_dynamic_object_array_field(ptr noundef %61, ptr noundef %62, i32 noundef %64, i32 noundef %65, ptr noundef %66, ptr noundef %68, i32 noundef %69)
  store i32 %70, ptr %8, align 4
  store i32 1, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  br label %71

71:                                               ; preds = %55, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  %72 = load i32, ptr %8, align 4
  ret i32 %72
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

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 = { nounwind allocsize(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 #3 = { nounwind }
attributes #4 = { nounwind allocsize(0) }

!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 = !{!7, !7, i64 0}


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

; Function Attrs: nounwind uwtable
declare dso_local ptr @get_const_field_by_name(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @copy_optional_dynamic_object_array_field(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr nocapture noundef writeonly %3, ptr noundef %4, ptr nocapture noundef writeonly %5, i32 noundef %6) local_unnamed_addr #0 {
  %8 = tail call ptr @get_const_field_by_name(ptr noundef %0, ptr noundef %1)
  %9 = icmp eq ptr %8, null
  br i1 %9, label %14, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %8, i64 16
  %12 = load i32, ptr %11, align 8, !tbaa !5
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %10, %7
  store ptr null, ptr %5, align 8, !tbaa !8
  store i32 0, ptr %3, align 4, !tbaa !10
  br label %22

15:                                               ; preds = %10
  store i32 %12, ptr %3, align 4, !tbaa !10
  %16 = mul i32 %12, %6
  %17 = mul i32 %6, %2
  %18 = tail call i32 @llvm.umin.i32(i32 %16, i32 %17)
  %19 = zext i32 %18 to i64
  %20 = tail call noalias ptr @malloc(i64 noundef %19) #3
  store ptr %20, ptr %5, align 8, !tbaa !8
  %21 = tail call i32 @copy_filled_dynamic_object_array_field(ptr noundef %0, ptr noundef %1, i32 noundef %12, i32 noundef %2, ptr noundef %4, ptr noundef %20, i32 noundef %6)
  br label %22

22:                                               ; preds = %15, %14
  %.0 = phi i32 [ 1, %14 ], [ %21, %15 ]
  ret i32 %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @copy_filled_dynamic_object_array_field(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #2

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 speculatable willreturn memory(none) }
attributes #3 = { nounwind allocsize(0) }

!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, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass