; LLVM IR from Softmotions/iowow :: src/utils (iwpool)

; 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.iwpool = type { i64, i64, ptr, ptr, ptr, i32, ptr, ptr, ptr, ptr }
%struct.iwpool_unit = type { 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: nounwind
declare void @free(ptr noundef) #1

; 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 zeroext i1 @iwpool_destroy(ptr noundef %0) #2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %15

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.iwpool, ptr %10, i32 0, i32 5
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = add nsw i32 %12, -1
  store i32 %13, ptr %11, align 8, !tbaa !9
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %9, %1
  store i1 false, ptr %2, align 1
  br label %75

16:                                               ; preds = %9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.iwpool, ptr %17, i32 0, i32 7
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %26

21:                                               ; preds = %16
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.iwpool, ptr %22, i32 0, i32 7
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  call void @_parent_remove_child(ptr noundef %24, ptr noundef %25)
  br label %26

26:                                               ; preds = %21, %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.iwpool, ptr %27, i32 0, i32 8
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  store ptr %29, ptr %4, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %39, %26
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %43

34:                                               ; preds = %30
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.iwpool, ptr %35, i32 0, i32 7
  store ptr null, ptr %36, align 8, !tbaa !13
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = call zeroext i1 @iwpool_destroy(ptr noundef %37)
  br label %39

39:                                               ; preds = %34
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.iwpool, ptr %40, i32 0, i32 9
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  store ptr %42, ptr %4, align 8, !tbaa !5
  br label %30, !llvm.loop !16

43:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.iwpool, ptr %44, i32 0, i32 2
  %46 = load ptr, ptr %45, align 8, !tbaa !18
  store ptr %46, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  br label %47

47:                                               ; preds = %59, %43
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %51, label %50

50:                                               ; preds = %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %61

51:                                               ; preds = %47
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.iwpool_unit, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !19
  store ptr %54, ptr %6, align 8, !tbaa !5
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.iwpool_unit, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !21
  call void @free(ptr noundef %57) #3
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %58) #3
  br label %59

59:                                               ; preds = %51
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %60, ptr %5, align 8, !tbaa !5
  br label %47, !llvm.loop !22

61:                                               ; preds = %50
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.iwpool, ptr %62, i32 0, i32 4
  %64 = load ptr, ptr %63, align 8, !tbaa !23
  %65 = icmp ne ptr %64, null
  br i1 %65, label %66, label %73

66:                                               ; preds = %61
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.iwpool, ptr %67, i32 0, i32 4
  %69 = load ptr, ptr %68, align 8, !tbaa !23
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.iwpool, ptr %70, i32 0, i32 3
  %72 = load ptr, ptr %71, align 8, !tbaa !24
  call void %69(ptr noundef %72)
  br label %73

73:                                               ; preds = %66, %61
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %74) #3
  store i1 true, ptr %2, align 1
  br label %75

75:                                               ; preds = %73, %15
  %76 = load i1, ptr %2, align 1
  ret i1 %76
}

; Function Attrs: nounwind uwtable
declare hidden void @_parent_remove_child(ptr noundef, 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, !12, i64 40}
!10 = !{!"iwpool", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !12, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72}
!11 = !{!"long", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !6, i64 56}
!14 = !{!10, !6, i64 64}
!15 = !{!10, !6, i64 72}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !6, i64 16}
!19 = !{!20, !6, i64 8}
!20 = !{!"iwpool_unit", !6, i64 0, !6, i64 8}
!21 = !{!20, !6, i64 0}
!22 = distinct !{!22, !17}
!23 = !{!10, !6, i64 32}
!24 = !{!10, !6, i64 24}


; 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
define dso_local noundef zeroext i1 @iwpool_destroy(ptr noundef %0) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %27, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = add nsw i32 %4, -1
  store i32 %5, ptr %3, align 8, !tbaa !5
  %6 = icmp sgt i32 %4, 1
  br i1 %6, label %27, label %7

7:                                                ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 56
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %.not26 = icmp eq ptr %9, null
  br i1 %.not26, label %11, label %10

10:                                               ; preds = %7
  tail call void @_parent_remove_child(ptr noundef nonnull %9, ptr noundef nonnull %0)
  br label %11

11:                                               ; preds = %10, %7
  %12 = getelementptr inbounds i8, ptr %0, i64 64
  %.02230 = load ptr, ptr %12, align 8, !tbaa !13
  %.not2731 = icmp eq ptr %.02230, null
  br i1 %.not2731, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %11
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %.not2833 = icmp eq ptr %14, null
  br i1 %.not2833, label %._crit_edge37, label %.lr.ph36

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.02232 = phi ptr [ %.022, %.lr.ph ], [ %.02230, %11 ]
  %15 = getelementptr inbounds i8, ptr %.02232, i64 56
  store ptr null, ptr %15, align 8, !tbaa !12
  %16 = tail call zeroext i1 @iwpool_destroy(ptr noundef nonnull %.02232)
  %17 = getelementptr inbounds i8, ptr %.02232, i64 72
  %.022 = load ptr, ptr %17, align 8, !tbaa !13
  %.not27 = icmp eq ptr %.022, null
  br i1 %.not27, label %._crit_edge, label %.lr.ph, !llvm.loop !15

._crit_edge37:                                    ; preds = %.lr.ph36, %._crit_edge
  %18 = getelementptr inbounds i8, ptr %0, i64 32
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  %.not29 = icmp eq ptr %19, null
  br i1 %.not29, label %26, label %23

.lr.ph36:                                         ; preds = %._crit_edge, %.lr.ph36
  %.02134 = phi ptr [ %21, %.lr.ph36 ], [ %14, %._crit_edge ]
  %20 = getelementptr inbounds i8, ptr %.02134, i64 8
  %21 = load ptr, ptr %20, align 8, !tbaa !18
  %22 = load ptr, ptr %.02134, align 8, !tbaa !20
  tail call void @free(ptr noundef %22) #2
  tail call void @free(ptr noundef nonnull %.02134) #2
  %.not28 = icmp eq ptr %21, null
  br i1 %.not28, label %._crit_edge37, label %.lr.ph36, !llvm.loop !21

23:                                               ; preds = %._crit_edge37
  %24 = getelementptr inbounds i8, ptr %0, i64 24
  %25 = load ptr, ptr %24, align 8, !tbaa !22
  tail call void %19(ptr noundef %25) #2
  br label %26

26:                                               ; preds = %23, %._crit_edge37
  tail call void @free(ptr noundef nonnull %0) #2
  br label %27

27:                                               ; preds = %1, %2, %26
  %.0 = phi i1 [ true, %26 ], [ false, %2 ], [ false, %1 ]
  ret i1 %.0
}

; Function Attrs: nounwind uwtable
declare hidden void @_parent_remove_child(ptr noundef, 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, !11, i64 40}
!6 = !{!"iwpool", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !11, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !10, i64 56}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !10, i64 16}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!6, !10, i64 32}
!18 = !{!19, !10, i64 8}
!19 = !{!"iwpool_unit", !10, i64 0, !10, i64 8}
!20 = !{!19, !10, i64 0}
!21 = distinct !{!21, !16}
!22 = !{!6, !10, i64 24}


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