; LLVM IR from marcobambini/gravity :: src/utils (gravity_json)

; 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_t = type { ptr, i64, i64, ptr, i32, %struct.JSON_CONTEXT_R }
%struct.JSON_CONTEXT_R = type { i64, i64, ptr }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__.json_new = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @json_new() #0 {
  %1 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #5
  %2 = call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 64)
  store ptr %2, ptr %1, align 8, !tbaa !5
  %3 = load ptr, ptr %1, align 8, !tbaa !5
  %4 = icmp ne ptr %3, null
  br i1 %4, label %5, label %6

5:                                                ; preds = %0
  br label %7

6:                                                ; preds = %0
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 92, ptr noundef @__PRETTY_FUNCTION__.json_new) #6
  unreachable

7:                                                ; preds = %5
  %8 = call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 4096)
  %9 = load ptr, ptr %1, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.json_t, ptr %9, i32 0, i32 0
  store ptr %8, ptr %10, align 8, !tbaa !9
  %11 = load ptr, ptr %1, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.json_t, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %7
  br label %17

16:                                               ; preds = %7
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 95, ptr noundef @__PRETTY_FUNCTION__.json_new) #6
  unreachable

17:                                               ; preds = %15
  %18 = load ptr, ptr %1, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.json_t, ptr %18, i32 0, i32 1
  store i64 4096, ptr %19, align 8, !tbaa !14
  %20 = load ptr, ptr %1, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.json_t, ptr %20, i32 0, i32 2
  store i64 0, ptr %21, align 8, !tbaa !15
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.json_t, ptr %22, i32 0, i32 4
  store i32 0, ptr %23, align 8, !tbaa !16
  %24 = load ptr, ptr %1, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.json_t, ptr %24, i32 0, i32 5
  %26 = getelementptr inbounds %struct.JSON_CONTEXT_R, ptr %25, i32 0, i32 1
  store i64 0, ptr %26, align 8, !tbaa !17
  %27 = load ptr, ptr %1, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.json_t, ptr %27, i32 0, i32 5
  %29 = getelementptr inbounds %struct.JSON_CONTEXT_R, ptr %28, i32 0, i32 0
  store i64 0, ptr %29, align 8, !tbaa !18
  %30 = load ptr, ptr %1, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.json_t, ptr %30, i32 0, i32 5
  %32 = getelementptr inbounds %struct.JSON_CONTEXT_R, ptr %31, i32 0, i32 2
  store ptr null, ptr %32, align 8, !tbaa !19
  %33 = load ptr, ptr %1, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.json_t, ptr %33, i32 0, i32 5
  %35 = getelementptr inbounds %struct.JSON_CONTEXT_R, ptr %34, i32 0, i32 0
  %36 = load i64, ptr %35, align 8, !tbaa !18
  %37 = load ptr, ptr %1, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.json_t, ptr %37, i32 0, i32 5
  %39 = getelementptr inbounds %struct.JSON_CONTEXT_R, ptr %38, i32 0, i32 1
  %40 = load i64, ptr %39, align 8, !tbaa !17
  %41 = icmp eq i64 %36, %40
  br i1 %41, label %42, label %73

42:                                               ; preds = %17
  %43 = load ptr, ptr %1, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.json_t, ptr %43, i32 0, i32 5
  %45 = getelementptr inbounds %struct.JSON_CONTEXT_R, ptr %44, i32 0, i32 1
  %46 = load i64, ptr %45, align 8, !tbaa !17
  %47 = icmp ne i64 %46, 0
  br i1 %47, label %48, label %54

48:                                               ; preds = %42
  %49 = load ptr, ptr %1, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.json_t, ptr %49, i32 0, i32 5
  %51 = getelementptr inbounds %struct.JSON_CONTEXT_R, ptr %50, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !17
  %53 = shl i64 %52, 1
  br label %55

54:                                               ; preds = %42
  br label %55

55:                                               ; preds = %54, %48
  %56 = phi i64 [ %53, %48 ], [ 8, %54 ]
  %57 = load ptr, ptr %1, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.json_t, ptr %57, i32 0, i32 5
  %59 = getelementptr inbounds %struct.JSON_CONTEXT_R, ptr %58, i32 0, i32 1
  store i64 %56, ptr %59, align 8, !tbaa !17
  %60 = load ptr, ptr %1, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.json_t, ptr %60, i32 0, i32 5
  %62 = getelementptr inbounds %struct.JSON_CONTEXT_R, ptr %61, i32 0, i32 2
  %63 = load ptr, ptr %62, align 8, !tbaa !19
  %64 = load ptr, ptr %1, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.json_t, ptr %64, i32 0, i32 5
  %66 = getelementptr inbounds %struct.JSON_CONTEXT_R, ptr %65, i32 0, i32 1
  %67 = load i64, ptr %66, align 8, !tbaa !17
  %68 = mul i64 4, %67
  %69 = call ptr @realloc(ptr noundef %63, i64 noundef %68) #7
  %70 = load ptr, ptr %1, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.json_t, ptr %70, i32 0, i32 5
  %72 = getelementptr inbounds %struct.JSON_CONTEXT_R, ptr %71, i32 0, i32 2
  store ptr %69, ptr %72, align 8, !tbaa !19
  br label %73

73:                                               ; preds = %55, %17
  %74 = load ptr, ptr %1, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.json_t, ptr %74, i32 0, i32 5
  %76 = getelementptr inbounds %struct.JSON_CONTEXT_R, ptr %75, i32 0, i32 2
  %77 = load ptr, ptr %76, align 8, !tbaa !19
  %78 = load ptr, ptr %1, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.json_t, ptr %78, i32 0, i32 5
  %80 = getelementptr inbounds %struct.JSON_CONTEXT_R, ptr %79, i32 0, i32 0
  %81 = load i64, ptr %80, align 8, !tbaa !18
  %82 = add i64 %81, 1
  store i64 %82, ptr %80, align 8, !tbaa !18
  %83 = getelementptr inbounds i32, ptr %77, i64 %81
  store i32 0, ptr %83, align 4, !tbaa !20
  %84 = load ptr, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #5
  ret ptr %84
}

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

declare ptr @gravity_calloc(ptr noundef, i64 noundef, i64 noundef) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { noreturn nounwind "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 allocsize(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 #5 = { nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { nounwind allocsize(1) }

!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, !6, i64 0}
!10 = !{!"json_t", !6, i64 0, !11, i64 8, !11, i64 16, !6, i64 24, !12, i64 32, !13, i64 40}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !11, i64 0, !11, i64 8, !6, i64 16}
!14 = !{!10, !11, i64 8}
!15 = !{!10, !11, i64 16}
!16 = !{!10, !12, i64 32}
!17 = !{!10, !11, i64 48}
!18 = !{!10, !11, i64 40}
!19 = !{!10, !6, i64 56}
!20 = !{!12, !12, 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"

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@__PRETTY_FUNCTION__.json_new = external hidden unnamed_addr constant [23 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @json_new() local_unnamed_addr #0 {
  %1 = tail call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 64) #4
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %2, label %3

2:                                                ; preds = %0
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 92, ptr noundef nonnull @__PRETTY_FUNCTION__.json_new) #5
  unreachable

3:                                                ; preds = %0
  %4 = tail call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 4096) #4
  store ptr %4, ptr %1, align 8, !tbaa !5
  %.not21 = icmp eq ptr %4, null
  br i1 %.not21, label %5, label %6

5:                                                ; preds = %3
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 95, ptr noundef nonnull @__PRETTY_FUNCTION__.json_new) #5
  unreachable

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  store i64 4096, ptr %7, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %1, i64 16
  store i64 0, ptr %8, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %1, i64 32
  store i32 0, ptr %9, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %1, i64 40
  %11 = getelementptr inbounds i8, ptr %1, i64 48
  %12 = getelementptr inbounds i8, ptr %1, i64 56
  store i64 8, ptr %11, align 8, !tbaa !16
  %malloc = tail call dereferenceable_or_null(32) ptr @malloc(i64 32)
  store ptr %malloc, ptr %12, align 8, !tbaa !17
  store i64 1, ptr %10, align 8, !tbaa !18
  store i32 0, ptr %malloc, align 4, !tbaa !19
  ret ptr %1
}

declare ptr @gravity_calloc(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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

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 = { noreturn nounwind "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 = { nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #4 = { nounwind }
attributes #5 = { noreturn 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_t", !7, i64 0, !10, i64 8, !10, i64 16, !7, i64 24, !11, i64 32, !12, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 8, !7, i64 16}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !11, i64 32}
!16 = !{!6, !10, i64 48}
!17 = !{!6, !7, i64 56}
!18 = !{!6, !10, i64 40}
!19 = !{!11, !11, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass