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

; 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.polygon50 = type { i32, [50 x %struct.vector3] }
%struct.vector3 = type { [3 x float] }
%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 }

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @polygon50_to_json(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  br label %75

12:                                               ; preds = %2
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  store i32 0, ptr %3, align 4
  br label %75

16:                                               ; preds = %12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call i32 @add_typename(ptr noundef %17, ptr noundef @.str)
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 0, ptr %3, align 4
  br label %75

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.polygon50, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = call i32 @add_uint_field(ptr noundef %22, ptr noundef @.str.1, i32 noundef %25)
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %29, label %28

28:                                               ; preds = %21
  store i32 0, ptr %3, align 4
  br label %75

29:                                               ; preds = %21
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.polygon50, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = call i32 @add_dynamic_object_array_field(ptr noundef %30, ptr noundef @.str.2, i32 noundef %33, i32 noundef 50)
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %37, label %36

36:                                               ; preds = %29
  store i32 0, ptr %3, align 4
  br label %75

37:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = call ptr @get_field_by_name(ptr noundef %38, ptr noundef @.str.2)
  store ptr %39, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %42, label %43

42:                                               ; preds = %37
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %74

43:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !12
  br label %44

44:                                               ; preds = %68, %43
  %45 = load i32, ptr %8, align 4, !tbaa !12
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.polygon50, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = icmp ult i32 %45, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %44
  store i32 2, ptr %7, align 4
  br label %71

51:                                               ; preds = %44
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.json_value_s, ptr %52, i32 0, i32 2
  %54 = getelementptr inbounds %struct.json_array_s, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !13
  %56 = load i32, ptr %8, align 4, !tbaa !12
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds %struct.json_value_s, ptr %55, i64 %57
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.polygon50, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %8, align 4, !tbaa !12
  %62 = zext i32 %61 to i64
  %63 = getelementptr inbounds [50 x %struct.vector3], ptr %60, i64 0, i64 %62
  %64 = call i32 @anon_vector3_to_json(ptr noundef %58, ptr noundef %63)
  %65 = icmp ne i32 %64, 0
  br i1 %65, label %67, label %66

66:                                               ; preds = %51
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %71

67:                                               ; preds = %51
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %8, align 4, !tbaa !12
  %70 = add i32 %69, 1
  store i32 %70, ptr %8, align 4, !tbaa !12
  br label %44, !llvm.loop !14

71:                                               ; preds = %66, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %72 = load i32, ptr %7, align 4
  switch i32 %72, label %74 [
    i32 2, label %73
  ]

73:                                               ; preds = %71
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %74

74:                                               ; preds = %73, %71, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %75

75:                                               ; preds = %74, %36, %28, %20, %15, %11
  %76 = load i32, ptr %3, align 4
  ret i32 %76
}

declare i32 @add_typename(ptr noundef, ptr noundef) #1

declare i32 @add_uint_field(ptr noundef, ptr noundef, i32 noundef) #1

declare i32 @add_dynamic_object_array_field(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #1

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

declare ptr @get_field_by_name(ptr noundef, ptr noundef) #1

declare i32 @anon_vector3_to_json(ptr noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { "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, !11, i64 0}
!10 = !{!"polygon50", !11, i64 0, !7, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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_value_s = type { i32, ptr, %union.anon }
%union.anon = type { %struct.json_object_s }
%struct.json_object_s = type { i32, i32, ptr, ptr }
%struct.vector3 = type { [3 x float] }

@.str = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @polygon50_to_json(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %._crit_edge, label %5

5:                                                ; preds = %2
  %6 = tail call i32 @add_typename(ptr noundef nonnull %0, ptr noundef nonnull @.str) #2
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %._crit_edge, label %7

7:                                                ; preds = %5
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = tail call i32 @add_uint_field(ptr noundef nonnull %0, ptr noundef nonnull @.str.1, i32 noundef %8) #2
  %.not22 = icmp eq i32 %9, 0
  br i1 %.not22, label %._crit_edge, label %10

10:                                               ; preds = %7
  %11 = load i32, ptr %1, align 4, !tbaa !5
  %12 = tail call i32 @add_dynamic_object_array_field(ptr noundef nonnull %0, ptr noundef nonnull @.str.2, i32 noundef %11, i32 noundef 50) #2
  %.not23 = icmp eq i32 %12, 0
  br i1 %.not23, label %._crit_edge, label %13

13:                                               ; preds = %10
  %14 = tail call ptr @get_field_by_name(ptr noundef nonnull %0, ptr noundef nonnull @.str.2) #2
  %15 = icmp eq ptr %14, null
  br i1 %15, label %._crit_edge, label %.preheader

.preheader:                                       ; preds = %13
  %16 = getelementptr inbounds i8, ptr %14, i64 24
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %.not2526 = icmp eq i32 %17, 0
  br i1 %.not2526, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %18 = getelementptr inbounds i8, ptr %1, i64 4
  br label %22

19:                                               ; preds = %22
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = load i32, ptr %1, align 4, !tbaa !5
  %21 = zext i32 %20 to i64
  %.not25.not = icmp ult i64 %indvars.iv.next, %21
  br i1 %.not25.not, label %22, label %._crit_edge.loopexit, !llvm.loop !10

22:                                               ; preds = %.lr.ph, %19
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %19 ]
  %23 = load ptr, ptr %16, align 8, !tbaa !12
  %24 = getelementptr inbounds %struct.json_value_s, ptr %23, i64 %indvars.iv
  %25 = getelementptr inbounds [50 x %struct.vector3], ptr %18, i64 0, i64 %indvars.iv
  %26 = tail call i32 @anon_vector3_to_json(ptr noundef %24, ptr noundef nonnull %25) #2
  %.not24 = icmp ne i32 %26, 0
  br i1 %.not24, label %19, label %._crit_edge.loopexit

._crit_edge.loopexit:                             ; preds = %22, %19
  %27 = zext i1 %.not24 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %.preheader, %._crit_edge.loopexit, %13, %10, %7, %5, %2
  %.2 = phi i32 [ 0, %2 ], [ 0, %5 ], [ 0, %7 ], [ 0, %10 ], [ 0, %13 ], [ 1, %.preheader ], [ %27, %._crit_edge.loopexit ]
  ret i32 %.2
}

declare i32 @add_typename(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @add_uint_field(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare i32 @add_dynamic_object_array_field(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare ptr @get_field_by_name(ptr noundef, ptr noundef) local_unnamed_addr #1

declare i32 @anon_vector3_to_json(ptr noundef, 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 = !{!"polygon50", !7, i64 0, !8, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!8, !8, i64 0}


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