; LLVM IR from ohler55/agoo :: ext/agoo (graphql)

; 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._gqlDoc = type { ptr, ptr, ptr, ptr, %struct._gqlFuncs, ptr, ptr, ptr }
%struct._gqlFuncs = type { ptr, ptr }
%struct._gqlOp = type { ptr, ptr, ptr, ptr, ptr, i32 }
%struct._gqlVar = type { ptr, ptr, ptr, ptr }
%struct._gqlFrag = type { ptr, ptr, ptr, ptr, 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
declare dso_local void @gql_op_destroy(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @var_destroy(ptr noundef) #2

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

6:                                                ; preds = %11, %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._gqlDoc, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %9, ptr %3, align 8, !tbaa !5
  %10 = icmp ne ptr null, %9
  br i1 %10, label %11, label %18

11:                                               ; preds = %6
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._gqlOp, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._gqlDoc, ptr %15, i32 0, i32 0
  store ptr %14, ptr %16, align 8, !tbaa !9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  call void @gql_op_destroy(ptr noundef %17)
  br label %6, !llvm.loop !15

18:                                               ; preds = %6
  br label %19

19:                                               ; preds = %24, %18
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._gqlDoc, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  store ptr %22, ptr %5, align 8, !tbaa !5
  %23 = icmp ne ptr null, %22
  br i1 %23, label %24, label %31

24:                                               ; preds = %19
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct._gqlVar, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !18
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct._gqlDoc, ptr %28, i32 0, i32 1
  store ptr %27, ptr %29, align 8, !tbaa !17
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  call void @var_destroy(ptr noundef %30)
  br label %19, !llvm.loop !20

31:                                               ; preds = %19
  br label %32

32:                                               ; preds = %37, %31
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._gqlDoc, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !21
  store ptr %35, ptr %4, align 8, !tbaa !5
  %36 = icmp ne ptr null, %35
  br i1 %36, label %37, label %44

37:                                               ; preds = %32
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct._gqlFrag, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !22
  %41 = load ptr, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct._gqlDoc, ptr %41, i32 0, i32 2
  store ptr %40, ptr %42, align 8, !tbaa !21
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  call void @gql_frag_destroy(ptr noundef %43)
  br label %32, !llvm.loop !24

44:                                               ; preds = %32
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._gqlDoc, ptr %45, i32 0, i32 7
  %47 = load ptr, ptr %46, align 8, !tbaa !25
  %48 = icmp ne ptr null, %47
  br i1 %48, label %49, label %56

49:                                               ; preds = %44
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct._gqlDoc, ptr %50, i32 0, i32 7
  %52 = load ptr, ptr %51, align 8, !tbaa !25
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._gqlDoc, ptr %53, i32 0, i32 6
  %55 = load ptr, ptr %54, align 8, !tbaa !26
  call void %52(ptr noundef %55)
  br label %56

56:                                               ; preds = %49, %44
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %57) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @gql_frag_destroy(ptr noundef) #2

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 = !{!"_gqlDoc", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !6, i64 48, !6, i64 56, !6, i64 64}
!11 = !{!"_gqlFuncs", !6, i64 0, !6, i64 8}
!12 = !{!13, !6, i64 0}
!13 = !{!"_gqlOp", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !14, i64 40}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!10, !6, i64 8}
!18 = !{!19, !6, i64 0}
!19 = !{!"_gqlVar", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!20 = distinct !{!20, !16}
!21 = !{!10, !6, i64 16}
!22 = !{!23, !6, i64 0}
!23 = !{!"_gqlFrag", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!24 = distinct !{!24, !16}
!25 = !{!10, !6, i64 64}
!26 = !{!10, !6, i64 56}


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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @gql_doc_destroy(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %.not23 = icmp eq ptr %2, null
  br i1 %.not23, label %.preheader22, label %.lr.ph

.preheader22:                                     ; preds = %.lr.ph, %1
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !11
  %.not1924 = icmp eq ptr %4, null
  br i1 %.not1924, label %.preheader, label %.lr.ph25

.lr.ph:                                           ; preds = %1, %.lr.ph
  %5 = phi ptr [ %7, %.lr.ph ], [ %2, %1 ]
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  store ptr %6, ptr %0, align 8, !tbaa !5
  tail call void @gql_op_destroy(ptr noundef nonnull %5)
  %7 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %.preheader22, label %.lr.ph, !llvm.loop !15

.preheader:                                       ; preds = %.lr.ph25, %.preheader22
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load ptr, ptr %8, align 8, !tbaa !17
  %.not2026 = icmp eq ptr %9, null
  br i1 %.not2026, label %._crit_edge, label %.lr.ph27

.lr.ph25:                                         ; preds = %.preheader22, %.lr.ph25
  %10 = phi ptr [ %12, %.lr.ph25 ], [ %4, %.preheader22 ]
  %11 = load ptr, ptr %10, align 8, !tbaa !18
  store ptr %11, ptr %3, align 8, !tbaa !11
  tail call void @var_destroy(ptr noundef nonnull %10)
  %12 = load ptr, ptr %3, align 8, !tbaa !11
  %.not19 = icmp eq ptr %12, null
  br i1 %.not19, label %.preheader, label %.lr.ph25, !llvm.loop !20

.lr.ph27:                                         ; preds = %.preheader, %.lr.ph27
  %13 = phi ptr [ %15, %.lr.ph27 ], [ %9, %.preheader ]
  %14 = load ptr, ptr %13, align 8, !tbaa !21
  store ptr %14, ptr %8, align 8, !tbaa !17
  tail call void @gql_frag_destroy(ptr noundef nonnull %13)
  %15 = load ptr, ptr %8, align 8, !tbaa !17
  %.not20 = icmp eq ptr %15, null
  br i1 %.not20, label %._crit_edge, label %.lr.ph27, !llvm.loop !23

._crit_edge:                                      ; preds = %.lr.ph27, %.preheader
  %16 = getelementptr inbounds i8, ptr %0, i64 64
  %17 = load ptr, ptr %16, align 8, !tbaa !24
  %.not21 = icmp eq ptr %17, null
  br i1 %.not21, label %21, label %18

18:                                               ; preds = %._crit_edge
  %19 = getelementptr inbounds i8, ptr %0, i64 56
  %20 = load ptr, ptr %19, align 8, !tbaa !25
  tail call void %17(ptr noundef %20) #2
  br label %21

21:                                               ; preds = %18, %._crit_edge
  tail call void @free(ptr noundef nonnull %0) #2
  ret void
}

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

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 = !{!"_gqlDoc", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !7, i64 48, !7, i64 56, !7, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_gqlFuncs", !7, i64 0, !7, i64 8}
!11 = !{!6, !7, i64 8}
!12 = !{!13, !7, i64 0}
!13 = !{!"_gqlOp", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !14, i64 40}
!14 = !{!"int", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!6, !7, i64 16}
!18 = !{!19, !7, i64 0}
!19 = !{!"_gqlVar", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!20 = distinct !{!20, !16}
!21 = !{!22, !7, i64 0}
!22 = !{!"_gqlFrag", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!23 = distinct !{!23, !16}
!24 = !{!6, !7, i64 64}
!25 = !{!6, !7, i64 56}


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