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

; 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
declare void @free(ptr noundef) #1

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

7:                                                ; preds = %1
  store i32 1, ptr %4, align 4
  br label %102

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct._json_value, ptr %9, i32 0, i32 0
  store ptr null, ptr %10, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %95, %76, %29, %8
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %101

14:                                               ; preds = %11
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._json_value, ptr %15, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !12
  switch i32 %17, label %94 [
    i32 2, label %18
    i32 1, label %42
    i32 5, label %89
  ]

18:                                               ; preds = %14
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._json_value, ptr %19, i32 0, i32 2
  %21 = getelementptr inbounds %struct.anon.1, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !13
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %29, label %24

24:                                               ; preds = %18
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._json_value, ptr %25, i32 0, i32 2
  %27 = getelementptr inbounds %struct.anon.1, ptr %26, i32 0, i32 1
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  call void @free(ptr noundef %28) #3
  br label %95

29:                                               ; preds = %18
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._json_value, ptr %30, i32 0, i32 2
  %32 = getelementptr inbounds %struct.anon.1, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load ptr, ptr %2, 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 0
  %37 = load i32, ptr %36, align 8, !tbaa !13
  %38 = add i32 %37, -1
  store i32 %38, ptr %36, align 8, !tbaa !13
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds ptr, ptr %33, i64 %39
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  store ptr %41, ptr %2, align 8, !tbaa !5
  br label %11, !llvm.loop !14

42:                                               ; preds = %14
  %43 = load ptr, ptr %2, 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 !13
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %53, label %48

48:                                               ; preds = %42
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._json_value, ptr %49, i32 0, i32 2
  %51 = getelementptr inbounds %struct.anon.0, ptr %50, i32 0, i32 1
  %52 = load ptr, ptr %51, align 8, !tbaa !13
  call void @free(ptr noundef %52) #3
  br label %95

53:                                               ; preds = %42
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._json_value, ptr %54, i32 0, i32 2
  %56 = getelementptr inbounds %struct.anon.0, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %56, align 8, !tbaa !13
  %58 = add i32 %57, -1
  store i32 %58, ptr %56, align 8, !tbaa !13
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.json_builder_value, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 8, !tbaa !16
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %76

63:                                               ; preds = %53
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct._json_value, ptr %64, i32 0, i32 2
  %66 = getelementptr inbounds %struct.anon.0, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct._json_value, ptr %68, i32 0, i32 2
  %70 = getelementptr inbounds %struct.anon.0, ptr %69, i32 0, i32 0
  %71 = load i32, ptr %70, align 8, !tbaa !13
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds %struct._json_object_entry, ptr %67, i64 %72
  %74 = getelementptr inbounds %struct._json_object_entry, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !19
  call void @free(ptr noundef %75) #3
  br label %76

76:                                               ; preds = %63, %53
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct._json_value, ptr %77, i32 0, i32 2
  %79 = getelementptr inbounds %struct.anon.0, ptr %78, i32 0, i32 1
  %80 = load ptr, ptr %79, align 8, !tbaa !13
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct._json_value, ptr %81, i32 0, i32 2
  %83 = getelementptr inbounds %struct.anon.0, ptr %82, i32 0, i32 0
  %84 = load i32, ptr %83, align 8, !tbaa !13
  %85 = zext i32 %84 to i64
  %86 = getelementptr inbounds %struct._json_object_entry, ptr %80, i64 %85
  %87 = getelementptr inbounds %struct._json_object_entry, ptr %86, i32 0, i32 2
  %88 = load ptr, ptr %87, align 8, !tbaa !21
  store ptr %88, ptr %2, align 8, !tbaa !5
  br label %11, !llvm.loop !14

89:                                               ; preds = %14
  %90 = load ptr, ptr %2, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct._json_value, ptr %90, i32 0, i32 2
  %92 = getelementptr inbounds %struct.anon, ptr %91, i32 0, i32 1
  %93 = load ptr, ptr %92, align 8, !tbaa !13
  call void @free(ptr noundef %93) #3
  br label %95

94:                                               ; preds = %14
  br label %95

95:                                               ; preds = %94, %89, %48, %24
  %96 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %96, ptr %3, align 8, !tbaa !5
  %97 = load ptr, ptr %2, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct._json_value, ptr %97, i32 0, i32 0
  %99 = load ptr, ptr %98, align 8, !tbaa !9
  store ptr %99, ptr %2, align 8, !tbaa !5
  %100 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %100) #3
  br label %11, !llvm.loop !14

101:                                              ; preds = %11
  store i32 0, ptr %4, align 4
  br label %102

102:                                              ; preds = %101, %7
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %103 = load i32, ptr %4, align 4
  switch i32 %103, label %105 [
    i32 0, label %104
    i32 1, label %104
  ]

104:                                              ; preds = %102, %102
  ret void

105:                                              ; preds = %102
  unreachable
}

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

!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_value", !6, i64 0, !11, i64 8, !7, i64 16, !7, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !11, i64 40}
!17 = !{!"json_builder_value", !10, i64 0, !11, i64 40, !18, i64 48, !18, i64 56}
!18 = !{!"long", !7, i64 0}
!19 = !{!20, !6, i64 0}
!20 = !{!"_json_object_entry", !6, i64 0, !11, i64 8, !6, i64 16}
!21 = !{!20, !6, i64 16}


; 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 }

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @json_builder_free(ptr noundef %0) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.loopexit, label %2

2:                                                ; preds = %1
  store ptr null, ptr %0, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %2, %.backedge
  %.027 = phi ptr [ %0, %2 ], [ %.0.be, %.backedge ]
  %4 = getelementptr inbounds i8, ptr %.027, i64 8
  %5 = load i32, ptr %4, align 8, !tbaa !11
  switch i32 %5, label %38 [
    i32 2, label %6
    i32 1, label %16
    i32 5, label %.sink.split.sink.split
  ]

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %.027, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !12
  %.not26 = icmp eq i32 %8, 0
  %9 = getelementptr inbounds i8, ptr %.027, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  br i1 %.not26, label %.sink.split, label %11

11:                                               ; preds = %6
  %12 = add i32 %8, -1
  store i32 %12, ptr %7, align 8, !tbaa !12
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds ptr, ptr %10, i64 %13
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  br label %.backedge

.backedge:                                        ; preds = %11, %29, %38
  %.0.be = phi ptr [ %39, %38 ], [ %35, %29 ], [ %15, %11 ]
  %.not23 = icmp eq ptr %.0.be, null
  br i1 %.not23, label %.loopexit, label %3, !llvm.loop !14

16:                                               ; preds = %3
  %17 = getelementptr inbounds i8, ptr %.027, i64 16
  %18 = load i32, ptr %17, align 8, !tbaa !12
  %.not24 = icmp eq i32 %18, 0
  br i1 %.not24, label %.sink.split.sink.split, label %19

19:                                               ; preds = %16
  %20 = add i32 %18, -1
  store i32 %20, ptr %17, align 8, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %.027, i64 40
  %22 = load i32, ptr %21, align 8, !tbaa !16
  %.not25 = icmp eq i32 %22, 0
  br i1 %.not25, label %29, label %23

23:                                               ; preds = %19
  %24 = getelementptr inbounds i8, ptr %.027, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !12
  %26 = zext i32 %20 to i64
  %27 = getelementptr inbounds %struct._json_object_entry, ptr %25, i64 %26
  %28 = load ptr, ptr %27, align 8, !tbaa !19
  tail call void @free(ptr noundef %28) #2
  %.pre = load i32, ptr %17, align 8, !tbaa !12
  br label %29

29:                                               ; preds = %23, %19
  %30 = phi i32 [ %.pre, %23 ], [ %20, %19 ]
  %31 = getelementptr inbounds i8, ptr %.027, i64 24
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  %33 = zext i32 %30 to i64
  %34 = getelementptr inbounds %struct._json_object_entry, ptr %32, i64 %33, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !21
  br label %.backedge

.sink.split.sink.split:                           ; preds = %3, %16
  %36 = getelementptr inbounds i8, ptr %.027, i64 24
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  br label %.sink.split

.sink.split:                                      ; preds = %.sink.split.sink.split, %6
  %.sink = phi ptr [ %10, %6 ], [ %37, %.sink.split.sink.split ]
  tail call void @free(ptr noundef %.sink) #2
  br label %38

38:                                               ; preds = %.sink.split, %3
  %39 = load ptr, ptr %.027, align 8, !tbaa !5
  tail call void @free(ptr noundef nonnull %.027) #2
  br label %.backedge

.loopexit:                                        ; preds = %.backedge, %1
  ret void
}

attributes #0 = { mustprogress nounwind willreturn allockind("free") 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 #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 = { 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_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 = !{!6, !10, i64 8}
!12 = !{!8, !8, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !10, i64 40}
!17 = !{!"json_builder_value", !6, i64 0, !10, i64 40, !18, i64 48, !18, i64 56}
!18 = !{!"long", !8, i64 0}
!19 = !{!20, !7, i64 0}
!20 = !{!"_json_object_entry", !7, i64 0, !10, i64 8, !7, i64 16}
!21 = !{!20, !7, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass