; LLVM IR from caryll/otfcc :: dep/extern (json-builder)

; 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, %union.anon.2 }
%union.anon = type { %struct.anon }
%struct.anon = type { i32, ptr }
%union.anon.2 = type { ptr }
%struct.json_builder_value = type { %struct._json_value, i32, i64, i64 }
%struct.anon.0 = type { i32, ptr }
%struct._json_object_entry = type { ptr, i32, ptr }

@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [28 x i8], align 1
@__PRETTY_FUNCTION__.json_object_push_nocopy = external hidden unnamed_addr constant [86 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

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

; Function Attrs: nounwind uwtable
declare hidden i32 @builderize(ptr noundef) #2

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

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

17:                                               ; preds = %4
  br label %19

18:                                               ; preds = %4
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 200, ptr noundef @__PRETTY_FUNCTION__.json_object_push_nocopy) #5
  unreachable

19:                                               ; preds = %17
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = call i32 @builderize(ptr noundef %20)
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = call i32 @builderize(ptr noundef %24)
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %23, %19
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %91

28:                                               ; preds = %23
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.json_builder_value, ptr %29, i32 0, i32 2
  %31 = load i64, ptr %30, align 8, !tbaa !13
  %32 = icmp ugt i64 %31, 0
  br i1 %32, label %33, label %38

33:                                               ; preds = %28
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.json_builder_value, ptr %34, i32 0, i32 2
  %36 = load i64, ptr %35, align 8, !tbaa !13
  %37 = add i64 %36, -1
  store i64 %37, ptr %35, align 8, !tbaa !13
  br label %62

38:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._json_value, ptr %39, i32 0, i32 2
  %41 = getelementptr inbounds %struct.anon.0, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct._json_value, ptr %43, i32 0, i32 2
  %45 = getelementptr inbounds %struct.anon.0, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !16
  %47 = add i32 %46, 1
  %48 = zext i32 %47 to i64
  %49 = mul i64 24, %48
  %50 = call ptr @realloc(ptr noundef %42, i64 noundef %49) #6
  store ptr %50, ptr %12, align 8, !tbaa !5
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %54, label %53

53:                                               ; preds = %38
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %59

54:                                               ; preds = %38
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._json_value, ptr %56, i32 0, i32 2
  %58 = getelementptr inbounds %struct.anon.0, ptr %57, i32 0, i32 1
  store ptr %55, ptr %58, align 8, !tbaa !16
  store i32 0, ptr %11, align 4
  br label %59

59:                                               ; preds = %54, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %60 = load i32, ptr %11, align 4
  switch i32 %60, label %91 [
    i32 0, label %61
  ]

61:                                               ; preds = %59
  br label %62

62:                                               ; preds = %61, %33
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._json_value, ptr %63, i32 0, i32 2
  %65 = getelementptr inbounds %struct.anon.0, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !16
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._json_value, ptr %67, i32 0, i32 2
  %69 = getelementptr inbounds %struct.anon.0, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %69, align 8, !tbaa !16
  %71 = zext i32 %70 to i64
  %72 = getelementptr inbounds %struct._json_object_entry, ptr %66, i64 %71
  store ptr %72, ptr %10, align 8, !tbaa !5
  %73 = load i32, ptr %7, align 4, !tbaa !9
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct._json_object_entry, ptr %74, i32 0, i32 1
  store i32 %73, ptr %75, align 8, !tbaa !17
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct._json_object_entry, ptr %77, i32 0, i32 0
  store ptr %76, ptr %78, align 8, !tbaa !19
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct._json_object_entry, ptr %80, i32 0, i32 2
  store ptr %79, ptr %81, align 8, !tbaa !20
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct._json_value, ptr %82, i32 0, i32 2
  %84 = getelementptr inbounds %struct.anon.0, ptr %83, i32 0, i32 0
  %85 = load i32, ptr %84, align 8, !tbaa !16
  %86 = add i32 %85, 1
  store i32 %86, ptr %84, align 8, !tbaa !16
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = load ptr, ptr %9, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct._json_value, ptr %88, i32 0, i32 0
  store ptr %87, ptr %89, align 8, !tbaa !21
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %90, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %91

91:                                               ; preds = %62, %59, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %92 = load ptr, ptr %5, align 8
  ret ptr %92
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 #4 = { nounwind }
attributes #5 = { noreturn nounwind }
attributes #6 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_json_value", !6, i64 0, !10, i64 8, !7, i64 16, !7, i64 32}
!13 = !{!14, !15, i64 48}
!14 = !{!"json_builder_value", !12, i64 0, !10, i64 40, !15, i64 48, !15, i64 56}
!15 = !{!"long", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !10, i64 8}
!18 = !{!"_json_object_entry", !6, i64 0, !10, i64 8, !6, i64 16}
!19 = !{!18, !6, i64 0}
!20 = !{!18, !6, i64 16}
!21 = !{!12, !6, 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"

%struct._json_object_entry = type { ptr, i32, ptr }

@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [28 x i8], align 1
@__PRETTY_FUNCTION__.json_object_push_nocopy = external hidden unnamed_addr constant [86 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @builderize(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @json_object_push_nocopy(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #1 {
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %9, label %8

8:                                                ; preds = %4
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 200, ptr noundef nonnull @__PRETTY_FUNCTION__.json_object_push_nocopy) #3
  unreachable

9:                                                ; preds = %4
  %10 = tail call i32 @builderize(ptr noundef nonnull %0)
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %.critedge, label %11

11:                                               ; preds = %9
  %12 = tail call i32 @builderize(ptr noundef %3)
  %.not25 = icmp eq i32 %12, 0
  br i1 %.not25, label %.critedge, label %13

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %0, i64 48
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %.not26 = icmp eq i64 %15, 0
  br i1 %.not26, label %18, label %16

16:                                               ; preds = %13
  %17 = add i64 %15, -1
  store i64 %17, ptr %14, align 8, !tbaa !11
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 24
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !14
  br label %28

18:                                               ; preds = %13
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = getelementptr inbounds i8, ptr %0, i64 24
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = load i32, ptr %19, align 8, !tbaa !14
  %23 = add i32 %22, 1
  %24 = zext i32 %23 to i64
  %25 = mul nuw nsw i64 %24, 24
  %26 = tail call ptr @realloc(ptr noundef %21, i64 noundef %25) #4
  %.not27.not = icmp eq ptr %26, null
  br i1 %.not27.not, label %.critedge, label %27

27:                                               ; preds = %18
  store ptr %26, ptr %20, align 8, !tbaa !14
  br label %28

28:                                               ; preds = %27, %16
  %29 = phi ptr [ %26, %27 ], [ %.pre, %16 ]
  %30 = getelementptr inbounds i8, ptr %0, i64 16
  %31 = load i32, ptr %30, align 8, !tbaa !14
  %32 = zext i32 %31 to i64
  %33 = getelementptr inbounds %struct._json_object_entry, ptr %29, i64 %32
  %34 = getelementptr inbounds i8, ptr %33, i64 8
  store i32 %1, ptr %34, align 8, !tbaa !15
  store ptr %2, ptr %33, align 8, !tbaa !17
  %35 = getelementptr inbounds i8, ptr %33, i64 16
  store ptr %3, ptr %35, align 8, !tbaa !18
  %36 = load i32, ptr %30, align 8, !tbaa !14
  %37 = add i32 %36, 1
  store i32 %37, ptr %30, align 8, !tbaa !14
  store ptr %0, ptr %3, align 8, !tbaa !19
  br label %.critedge

.critedge:                                        ; preds = %18, %9, %11, %28
  %.1 = phi ptr [ %3, %28 ], [ null, %11 ], [ null, %9 ], [ null, %18 ]
  ret ptr %.1
}

attributes #0 = { 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 #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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, 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 #3 = { noreturn nounwind }
attributes #4 = { 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, !10, i64 8}
!6 = !{!"_json_value", !7, i64 0, !10, i64 8, !8, i64 16, !8, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !13, i64 48}
!12 = !{!"json_builder_value", !6, i64 0, !10, i64 40, !13, i64 48, !13, i64 56}
!13 = !{!"long", !8, i64 0}
!14 = !{!8, !8, i64 0}
!15 = !{!16, !10, i64 8}
!16 = !{!"_json_object_entry", !7, i64 0, !10, i64 8, !7, i64 16}
!17 = !{!16, !7, i64 0}
!18 = !{!16, !7, i64 16}
!19 = !{!6, !7, i64 0}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass