; LLVM IR from marcobambini/gravity :: src/shared (gravity_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 = type { ptr, i32, %union.anon.0, %union.anon.3 }
%union.anon.0 = type { %struct.anon }
%struct.anon = type { i32, ptr }
%union.anon.3 = type { ptr }
%struct.anon.1 = type { i32, ptr }
%struct._json_object_entry = type { ptr, i32, ptr }

@.str.95 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.96 = external hidden unnamed_addr constant [3 x i8], align 1

; 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

declare i32 @string_casencmp(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_range_deserialize(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct._json_value, ptr %14, i32 0, i32 2
  %16 = getelementptr inbounds %struct.anon.1, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !11
  store i32 %17, ptr %8, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 1, ptr %9, align 4, !tbaa !12
  br label %18

18:                                               ; preds = %77, %2
  %19 = load i32, ptr %9, align 4, !tbaa !12
  %20 = load i32, ptr %8, align 4, !tbaa !12
  %21 = icmp ult i32 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  store i32 2, ptr %10, align 4
  br label %80

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._json_value, ptr %24, i32 0, i32 2
  %26 = getelementptr inbounds %struct.anon.1, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = load i32, ptr %9, align 4, !tbaa !12
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds %struct._json_object_entry, ptr %27, i64 %29
  %31 = getelementptr inbounds %struct._json_object_entry, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  store ptr %32, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._json_value, ptr %33, i32 0, i32 2
  %35 = getelementptr inbounds %struct.anon.1, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = load i32, ptr %9, align 4, !tbaa !12
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds %struct._json_object_entry, ptr %36, i64 %38
  %40 = getelementptr inbounds %struct._json_object_entry, ptr %39, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !16
  store ptr %41, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  %43 = call i64 @strlen(ptr noundef %42) #5
  store i64 %43, ptr %13, align 8, !tbaa !9
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = load i64, ptr %13, align 8, !tbaa !9
  %46 = call i32 @string_casencmp(ptr noundef %44, ptr noundef @.str.95, i64 noundef %45)
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %58

48:                                               ; preds = %23
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._json_value, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 8, !tbaa !17
  %52 = icmp ne i32 %51, 3
  br i1 %52, label %53, label %54

53:                                               ; preds = %48
  store i32 5, ptr %10, align 4
  br label %74

54:                                               ; preds = %48
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._json_value, ptr %55, i32 0, i32 2
  %57 = load i64, ptr %56, align 8, !tbaa !11
  store i64 %57, ptr %6, align 8, !tbaa !9
  store i32 4, ptr %10, align 4
  br label %74

58:                                               ; preds = %23
  %59 = load ptr, ptr %11, align 8, !tbaa !5
  %60 = load i64, ptr %13, align 8, !tbaa !9
  %61 = call i32 @string_casencmp(ptr noundef %59, ptr noundef @.str.96, i64 noundef %60)
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %73

63:                                               ; preds = %58
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._json_value, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 8, !tbaa !17
  %67 = icmp ne i32 %66, 3
  br i1 %67, label %68, label %69

68:                                               ; preds = %63
  store i32 5, ptr %10, align 4
  br label %74

69:                                               ; preds = %63
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct._json_value, ptr %70, i32 0, i32 2
  %72 = load i64, ptr %71, align 8, !tbaa !11
  store i64 %72, ptr %7, align 8, !tbaa !9
  store i32 4, ptr %10, align 4
  br label %74

73:                                               ; preds = %58
  store i32 0, ptr %10, align 4
  br label %74

74:                                               ; preds = %73, %69, %68, %54, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  %75 = load i32, ptr %10, align 4
  switch i32 %75, label %80 [
    i32 0, label %76
    i32 4, label %77
  ]

76:                                               ; preds = %74
  br label %77

77:                                               ; preds = %76, %74
  %78 = load i32, ptr %9, align 4, !tbaa !12
  %79 = add i32 %78, 1
  store i32 %79, ptr %9, align 4, !tbaa !12
  br label %18, !llvm.loop !19

80:                                               ; preds = %74, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %81 = load i32, ptr %10, align 4
  switch i32 %81, label %88 [
    i32 2, label %82
    i32 5, label %87
  ]

82:                                               ; preds = %80
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = load i64, ptr %6, align 8, !tbaa !9
  %85 = load i64, ptr %7, align 8, !tbaa !9
  %86 = call ptr @gravity_range_new(ptr noundef %83, i64 noundef %84, i64 noundef %85, i1 noundef zeroext true)
  store ptr %86, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %88

87:                                               ; preds = %80
  store ptr null, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %88

88:                                               ; preds = %87, %82, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %89 = load ptr, ptr %3, align 8
  ret ptr %89
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @gravity_range_new(ptr noundef, i64 noundef, i64 noundef, i1 noundef zeroext) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 willreturn memory(read) "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 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"_json_object_entry", !6, i64 0, !13, i64 8, !6, i64 16}
!16 = !{!15, !6, i64 16}
!17 = !{!18, !13, i64 8}
!18 = !{!"_json_value", !6, i64 0, !13, i64 8, !7, i64 16, !7, i64 32}
!19 = distinct !{!19, !20}
!20 = !{!"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_object_entry = type { ptr, i32, ptr }

@.str.95 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.96 = external hidden unnamed_addr constant [3 x i8], align 1

declare i32 @string_casencmp(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_range_deserialize(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 16
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = icmp ugt i32 %4, 1
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %6 = getelementptr inbounds i8, ptr %1, i64 24
  %wide.trip.count = zext i32 %4 to i64
  br label %7

7:                                                ; preds = %.lr.ph, %31
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %31 ]
  %.02245 = phi i64 [ 0, %.lr.ph ], [ %.1.ph, %31 ]
  %.02344 = phi i64 [ 0, %.lr.ph ], [ %.124.ph, %31 ]
  %8 = load ptr, ptr %6, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct._json_object_entry, ptr %8, i64 %indvars.iv
  %10 = load ptr, ptr %9, align 8, !tbaa !8
  %11 = getelementptr inbounds i8, ptr %9, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %13 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %10) #3
  %14 = tail call i32 @string_casencmp(ptr noundef %10, ptr noundef nonnull @.str.95, i64 noundef %13) #4
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %22

16:                                               ; preds = %7
  %17 = getelementptr inbounds i8, ptr %12, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %.not29 = icmp eq i32 %18, 3
  br i1 %.not29, label %19, label %.thread36

19:                                               ; preds = %16
  %20 = getelementptr inbounds i8, ptr %12, i64 16
  %21 = load i64, ptr %20, align 8, !tbaa !5
  br label %31

22:                                               ; preds = %7
  %23 = tail call i32 @string_casencmp(ptr noundef %10, ptr noundef nonnull @.str.96, i64 noundef %13) #4
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %31

25:                                               ; preds = %22
  %26 = getelementptr inbounds i8, ptr %12, i64 8
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %.not = icmp eq i32 %27, 3
  br i1 %.not, label %28, label %.thread36

28:                                               ; preds = %25
  %29 = getelementptr inbounds i8, ptr %12, i64 16
  %30 = load i64, ptr %29, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %19, %28, %22
  %.124.ph = phi i64 [ %.02344, %22 ], [ %30, %28 ], [ %.02344, %19 ]
  %.1.ph = phi i64 [ %.02245, %22 ], [ %.02245, %28 ], [ %21, %19 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %7, !llvm.loop !15

._crit_edge:                                      ; preds = %31, %2
  %.023.lcssa = phi i64 [ 0, %2 ], [ %.124.ph, %31 ]
  %.022.lcssa = phi i64 [ 0, %2 ], [ %.1.ph, %31 ]
  %32 = tail call ptr @gravity_range_new(ptr noundef %0, i64 noundef %.022.lcssa, i64 noundef %.023.lcssa, i1 noundef zeroext true)
  br label %.thread36

.thread36:                                        ; preds = %16, %25, %._crit_edge
  %.0 = phi ptr [ %32, %._crit_edge ], [ null, %25 ], [ null, %16 ]
  ret ptr %.0
}

; Function Attrs: nounwind uwtable
declare dso_local ptr @gravity_range_new(ptr noundef, i64 noundef, i64 noundef, i1 noundef zeroext) local_unnamed_addr #2

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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 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 #3 = { nounwind willreturn memory(read) }
attributes #4 = { 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_object_entry", !10, i64 0, !11, i64 8, !10, i64 16}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!9, !10, i64 16}
!13 = !{!14, !11, i64 8}
!14 = !{!"_json_value", !10, i64 0, !11, i64 8, !6, i64 16, !6, i64 32}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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