; 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._slot = type { ptr, ptr, i64 }
%struct._gqlDir = type { ptr, ptr, ptr, ptr, ptr, i8, i8 }

@gql_directives = external dso_local global ptr, align 8
@buckets = external hidden global [64 x ptr], align 16
@inited = external hidden global i8, align 1
@_gql_root_type = external global ptr, align 8

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

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

6:                                                ; preds = %27, %0
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = icmp slt i32 0, %7
  br i1 %8, label %9, label %32

9:                                                ; preds = %6
  %10 = load ptr, ptr %1, align 8, !tbaa !5
  %11 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %11, ptr %2, align 8, !tbaa !5
  %12 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr null, ptr %12, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %24, %9
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = icmp ne ptr null, %14
  br i1 %15, label %16, label %26

16:                                               ; preds = %13
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._slot, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  store ptr %19, ptr %3, align 8, !tbaa !5
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct._slot, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !14
  call void @type_destroy(ptr noundef %22)
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %23) #3
  br label %24

24:                                               ; preds = %16
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %25, ptr %2, align 8, !tbaa !5
  br label %13, !llvm.loop !15

26:                                               ; preds = %13
  br label %27

27:                                               ; preds = %26
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = add nsw i32 %28, -1
  store i32 %29, ptr %4, align 4, !tbaa !9
  %30 = load ptr, ptr %1, align 8, !tbaa !5
  %31 = getelementptr inbounds ptr, ptr %30, i32 1
  store ptr %31, ptr %1, align 8, !tbaa !5
  br label %6, !llvm.loop !17

32:                                               ; preds = %6
  br label %33

33:                                               ; preds = %36, %32
  %34 = load ptr, ptr @gql_directives, align 8, !tbaa !5
  store ptr %34, ptr %5, align 8, !tbaa !5
  %35 = icmp ne ptr null, %34
  br i1 %35, label %36, label %41

36:                                               ; preds = %33
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct._gqlDir, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !18
  store ptr %39, ptr @gql_directives, align 8, !tbaa !5
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  call void @dir_destroy(ptr noundef %40)
  br label %33, !llvm.loop !21

41:                                               ; preds = %33
  store ptr null, ptr @_gql_root_type, align 8, !tbaa !5
  store i8 0, ptr @inited, align 1, !tbaa !22
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #3
  ret void
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #2

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

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 = { 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 }

!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, !6, i64 0}
!12 = !{!"_slot", !6, i64 0, !6, i64 8, !13, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = !{!19, !6, i64 0}
!19 = !{!"_gqlDir", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !20, i64 40, !20, i64 41}
!20 = !{!"_Bool", !7, i64 0}
!21 = distinct !{!21, !16}
!22 = !{!20, !20, 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"

@gql_directives = external dso_local local_unnamed_addr global ptr, align 8
@buckets = external hidden local_unnamed_addr global [64 x ptr], align 16
@inited = external hidden local_unnamed_addr global i8, align 1
@_gql_root_type = external local_unnamed_addr global ptr, align 8

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

; Function Attrs: nounwind uwtable
define dso_local void @gql_destroy() local_unnamed_addr #0 {
  br label %2

.preheader:                                       ; preds = %._crit_edge
  %1 = load ptr, ptr @gql_directives, align 8, !tbaa !5
  %.not19 = icmp eq ptr %1, null
  br i1 %.not19, label %._crit_edge21, label %.lr.ph20

2:                                                ; preds = %0, %._crit_edge
  %.018 = phi ptr [ @buckets, %0 ], [ %8, %._crit_edge ]
  %.01117 = phi i32 [ 64, %0 ], [ %7, %._crit_edge ]
  %3 = load ptr, ptr %.018, align 8, !tbaa !5
  store ptr null, ptr %.018, align 8, !tbaa !5
  %.not1415 = icmp eq ptr %3, null
  br i1 %.not1415, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.01216 = phi ptr [ %4, %.lr.ph ], [ %3, %2 ]
  %4 = load ptr, ptr %.01216, align 8, !tbaa !9
  %5 = getelementptr inbounds i8, ptr %.01216, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  tail call void @type_destroy(ptr noundef %6)
  tail call void @free(ptr noundef nonnull %.01216) #2
  %.not14 = icmp eq ptr %4, null
  br i1 %.not14, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %2
  %7 = add nsw i32 %.01117, -1
  %8 = getelementptr inbounds i8, ptr %.018, i64 8
  %9 = icmp ugt i32 %.01117, 1
  br i1 %9, label %2, label %.preheader, !llvm.loop !15

.lr.ph20:                                         ; preds = %.preheader, %.lr.ph20
  %10 = phi ptr [ %12, %.lr.ph20 ], [ %1, %.preheader ]
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  store ptr %11, ptr @gql_directives, align 8, !tbaa !5
  tail call void @dir_destroy(ptr noundef nonnull %10)
  %12 = load ptr, ptr @gql_directives, align 8, !tbaa !5
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %._crit_edge21, label %.lr.ph20, !llvm.loop !19

._crit_edge21:                                    ; preds = %.lr.ph20, %.preheader
  store ptr null, ptr @_gql_root_type, align 8, !tbaa !5
  store i8 0, ptr @inited, align 1, !tbaa !20
  ret void
}

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

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

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 = { 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 #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, !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 = !{!"_slot", !6, i64 0, !6, i64 8, !11, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{!17, !6, i64 0}
!17 = !{!"_gqlDir", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !18, i64 40, !18, i64 41}
!18 = !{!"_Bool", !7, i64 0}
!19 = distinct !{!19, !14}
!20 = !{!18, !18, i64 0}


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