; 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.1 = type { i32, ptr }

@.str = external hidden unnamed_addr constant [26 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@__PRETTY_FUNCTION__.json_array_push = external hidden unnamed_addr constant [56 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: nounwind uwtable
define dso_local ptr @json_array_push(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct._json_value, ptr %8, i32 0, i32 1
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp eq i32 %10, 2
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  br label %14

13:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 132, ptr noundef @__PRETTY_FUNCTION__.json_array_push) #4
  unreachable

14:                                               ; preds = %12
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = call i32 @builderize(ptr noundef %15)
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %22

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

22:                                               ; preds = %18, %14
  store ptr null, ptr %3, align 8
  br label %78

23:                                               ; preds = %18
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.json_builder_value, ptr %24, i32 0, i32 2
  %26 = load i64, ptr %25, align 8, !tbaa !12
  %27 = icmp ugt i64 %26, 0
  br i1 %27, label %28, label %33

28:                                               ; preds = %23
  %29 = load ptr, ptr %4, 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 !12
  %32 = add i64 %31, -1
  store i64 %32, ptr %30, align 8, !tbaa !12
  br label %57

33:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._json_value, ptr %34, i32 0, i32 2
  %36 = getelementptr inbounds %struct.anon.1, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._json_value, ptr %38, i32 0, i32 2
  %40 = getelementptr inbounds %struct.anon.1, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !15
  %42 = add i32 %41, 1
  %43 = zext i32 %42 to i64
  %44 = mul i64 8, %43
  %45 = call ptr @realloc(ptr noundef %37, i64 noundef %44) #6
  store ptr %45, ptr %6, align 8, !tbaa !5
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %49, label %48

48:                                               ; preds = %33
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %54

49:                                               ; preds = %33
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._json_value, ptr %51, i32 0, i32 2
  %53 = getelementptr inbounds %struct.anon.1, ptr %52, i32 0, i32 1
  store ptr %50, ptr %53, align 8, !tbaa !15
  store i32 0, ptr %7, align 4
  br label %54

54:                                               ; preds = %49, %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %55 = load i32, ptr %7, align 4
  switch i32 %55, label %80 [
    i32 0, label %56
    i32 1, label %78
  ]

56:                                               ; preds = %54
  br label %57

57:                                               ; preds = %56, %28
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._json_value, ptr %59, i32 0, i32 2
  %61 = getelementptr inbounds %struct.anon.1, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !15
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct._json_value, ptr %63, i32 0, i32 2
  %65 = getelementptr inbounds %struct.anon.1, ptr %64, i32 0, i32 0
  %66 = load i32, ptr %65, align 8, !tbaa !15
  %67 = zext i32 %66 to i64
  %68 = getelementptr inbounds ptr, ptr %62, i64 %67
  store ptr %58, ptr %68, align 8, !tbaa !5
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._json_value, ptr %69, i32 0, i32 2
  %71 = getelementptr inbounds %struct.anon.1, ptr %70, i32 0, i32 0
  %72 = load i32, ptr %71, align 8, !tbaa !15
  %73 = add i32 %72, 1
  store i32 %73, ptr %71, align 8, !tbaa !15
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct._json_value, ptr %75, i32 0, i32 0
  store ptr %74, ptr %76, align 8, !tbaa !16
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %77, ptr %3, align 8
  br label %78

78:                                               ; preds = %57, %54, %22
  %79 = load ptr, ptr %3, align 8
  ret ptr %79

80:                                               ; preds = %54
  unreachable
}

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

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

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

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 = { 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 = { 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 = { noreturn nounwind }
attributes #5 = { 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, !11, i64 8}
!10 = !{!"_json_value", !6, i64 0, !11, i64 8, !7, i64 16, !7, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !14, i64 48}
!13 = !{!"json_builder_value", !10, i64 0, !11, i64 40, !14, i64 48, !14, i64 56}
!14 = !{!"long", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!10, !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"

@.str = external hidden unnamed_addr constant [26 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@__PRETTY_FUNCTION__.json_array_push = external hidden unnamed_addr constant [56 x i8], align 1

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

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

7:                                                ; preds = %2
  %8 = tail call i32 @builderize(ptr noundef nonnull %0)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %33, label %9

9:                                                ; preds = %7
  %10 = tail call i32 @builderize(ptr noundef %1)
  %.not21 = icmp eq i32 %10, 0
  br i1 %.not21, label %33, label %11

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

14:                                               ; preds = %11
  %15 = add i64 %13, -1
  store i64 %15, ptr %12, 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 %25

16:                                               ; preds = %11
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = getelementptr inbounds i8, ptr %0, i64 24
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = load i32, ptr %17, align 8, !tbaa !14
  %21 = add i32 %20, 1
  %22 = zext i32 %21 to i64
  %23 = shl nuw nsw i64 %22, 3
  %24 = tail call ptr @realloc(ptr noundef %19, i64 noundef %23) #4
  %.not23 = icmp eq ptr %24, null
  br i1 %.not23, label %33, label %.thread

.thread:                                          ; preds = %16
  store ptr %24, ptr %18, align 8, !tbaa !14
  br label %25

25:                                               ; preds = %.thread, %14
  %26 = phi ptr [ %24, %.thread ], [ %.pre, %14 ]
  %27 = getelementptr inbounds i8, ptr %0, i64 16
  %28 = load i32, ptr %27, align 8, !tbaa !14
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %26, i64 %29
  store ptr %1, ptr %30, align 8, !tbaa !15
  %31 = load i32, ptr %27, align 8, !tbaa !14
  %32 = add i32 %31, 1
  store i32 %32, ptr %27, align 8, !tbaa !14
  store ptr %0, ptr %1, align 8, !tbaa !16
  br label %33

33:                                               ; preds = %16, %7, %9, %25
  %.1 = phi ptr [ %1, %25 ], [ null, %9 ], [ null, %7 ], [ null, %16 ]
  ret ptr %.1
}

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

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

; 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

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


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