; 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: nounwind uwtable
define dso_local ptr @iwpool_create(i64 noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store i64 %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %6 = load i64, ptr %3, align 8, !tbaa !5
  %7 = icmp ult i64 %6, 1
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  br label %11

9:                                                ; preds = %1
  %10 = load i64, ptr %3, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %9, %8
  %12 = phi i64 [ 8192, %8 ], [ %10, %9 ]
  store i64 %12, ptr %3, align 8, !tbaa !5
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = add i64 %13, 8
  %15 = sub i64 %14, 1
  %16 = and i64 %15, -8
  store i64 %16, ptr %3, align 8, !tbaa !5
  %17 = call noalias ptr @malloc(i64 noundef 80) #5
  store ptr %17, ptr %4, align 8, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !9
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %11
  br label %74

21:                                               ; preds = %11
  %22 = call noalias ptr @malloc(i64 noundef 16) #5
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.iwpool, ptr %23, i32 0, i32 2
  store ptr %22, ptr %24, align 8, !tbaa !11
  %25 = load ptr, ptr %4, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.iwpool, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = icmp ne ptr %27, null
  br i1 %28, label %30, label %29

29:                                               ; preds = %21
  br label %74

30:                                               ; preds = %21
  %31 = load i64, ptr %3, align 8, !tbaa !5
  %32 = call noalias ptr @malloc(i64 noundef %31) #5
  %33 = load ptr, ptr %4, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.iwpool, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = getelementptr inbounds %struct.iwpool_unit, ptr %35, i32 0, i32 0
  store ptr %32, ptr %36, align 8, !tbaa !14
  %37 = load ptr, ptr %4, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.iwpool, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = getelementptr inbounds %struct.iwpool_unit, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = icmp ne ptr %41, null
  br i1 %42, label %44, label %43

43:                                               ; preds = %30
  br label %74

44:                                               ; preds = %30
  %45 = load i64, ptr %3, align 8, !tbaa !5
  %46 = load ptr, ptr %4, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.iwpool, ptr %46, i32 0, i32 1
  store i64 %45, ptr %47, align 8, !tbaa !16
  %48 = load ptr, ptr %4, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.iwpool, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !11
  %51 = getelementptr inbounds %struct.iwpool_unit, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = load ptr, ptr %4, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.iwpool, ptr %53, i32 0, i32 6
  store ptr %52, ptr %54, align 8, !tbaa !17
  %55 = load ptr, ptr %4, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.iwpool, ptr %55, i32 0, i32 5
  store i32 1, ptr %56, align 8, !tbaa !18
  %57 = load ptr, ptr %4, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.iwpool, ptr %57, i32 0, i32 0
  store i64 0, ptr %58, align 8, !tbaa !19
  %59 = load ptr, ptr %4, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.iwpool, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !11
  %62 = getelementptr inbounds %struct.iwpool_unit, ptr %61, i32 0, i32 1
  store ptr null, ptr %62, align 8, !tbaa !20
  %63 = load ptr, ptr %4, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.iwpool, ptr %63, i32 0, i32 3
  store ptr null, ptr %64, align 8, !tbaa !21
  %65 = load ptr, ptr %4, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.iwpool, ptr %65, i32 0, i32 4
  store ptr null, ptr %66, align 8, !tbaa !22
  %67 = load ptr, ptr %4, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.iwpool, ptr %67, i32 0, i32 7
  store ptr null, ptr %68, align 8, !tbaa !23
  %69 = load ptr, ptr %4, align 8, !tbaa !9
  %70 = getelementptr inbounds %struct.iwpool, ptr %69, i32 0, i32 8
  store ptr null, ptr %70, align 8, !tbaa !24
  %71 = load ptr, ptr %4, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.iwpool, ptr %71, i32 0, i32 9
  store ptr null, ptr %72, align 8, !tbaa !25
  %73 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %73, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %101

74:                                               ; preds = %43, %29, %20
  %75 = load ptr, ptr %4, align 8, !tbaa !9
  %76 = icmp ne ptr %75, null
  br i1 %76, label %77, label %100

77:                                               ; preds = %74
  %78 = load ptr, ptr %4, align 8, !tbaa !9
  %79 = getelementptr inbounds %struct.iwpool, ptr %78, i32 0, i32 2
  %80 = load ptr, ptr %79, align 8, !tbaa !11
  %81 = icmp ne ptr %80, null
  br i1 %81, label %82, label %95

82:                                               ; preds = %77
  %83 = load ptr, ptr %4, align 8, !tbaa !9
  %84 = getelementptr inbounds %struct.iwpool, ptr %83, i32 0, i32 2
  %85 = load ptr, ptr %84, align 8, !tbaa !11
  %86 = getelementptr inbounds %struct.iwpool_unit, ptr %85, i32 0, i32 0
  %87 = load ptr, ptr %86, align 8, !tbaa !14
  %88 = icmp ne ptr %87, null
  br i1 %88, label %89, label %95

89:                                               ; preds = %82
  %90 = load ptr, ptr %4, align 8, !tbaa !9
  %91 = getelementptr inbounds %struct.iwpool, ptr %90, i32 0, i32 2
  %92 = load ptr, ptr %91, align 8, !tbaa !11
  %93 = getelementptr inbounds %struct.iwpool_unit, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !14
  call void @free(ptr noundef %94) #4
  br label %95

95:                                               ; preds = %89, %82, %77
  %96 = load ptr, ptr %4, align 8, !tbaa !9
  %97 = getelementptr inbounds %struct.iwpool, ptr %96, i32 0, i32 2
  %98 = load ptr, ptr %97, align 8, !tbaa !11
  call void @free(ptr noundef %98) #4
  %99 = load ptr, ptr %4, align 8, !tbaa !9
  call void @free(ptr noundef %99) #4
  br label %100

100:                                              ; preds = %95, %74
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %101

101:                                              ; preds = %100, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %102 = load ptr, ptr %2, align 8
  ret ptr %102
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"iwpool", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !13, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"iwpool_unit", !10, i64 0, !10, i64 8}
!16 = !{!12, !6, i64 8}
!17 = !{!12, !10, i64 48}
!18 = !{!12, !13, i64 40}
!19 = !{!12, !6, i64 0}
!20 = !{!15, !10, i64 8}
!21 = !{!12, !10, i64 24}
!22 = !{!12, !10, i64 32}
!23 = !{!12, !10, i64 56}
!24 = !{!12, !10, i64 64}
!25 = !{!12, !10, i64 72}


; 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 memory(readwrite, argmem: none) uwtable
define dso_local noalias noundef ptr @iwpool_create(i64 noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq i64 %0, 0
  %3 = add i64 %0, 7
  %4 = and i64 %3, -8
  %5 = select i1 %2, i64 8192, i64 %4
  %6 = tail call noalias dereferenceable_or_null(80) ptr @malloc(i64 noundef 80) #4
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %.critedge, label %7

7:                                                ; preds = %1
  %8 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #4
  %9 = getelementptr inbounds i8, ptr %6, i64 16
  store ptr %8, ptr %9, align 8, !tbaa !5
  %.not31 = icmp eq ptr %8, null
  br i1 %.not31, label %.thread, label %10

10:                                               ; preds = %7
  %11 = tail call noalias ptr @malloc(i64 noundef %5) #4
  store ptr %11, ptr %8, align 8, !tbaa !12
  %.not32 = icmp eq ptr %11, null
  br i1 %.not32, label %.thread, label %12

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %6, i64 8
  store i64 %5, ptr %13, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %6, i64 48
  store ptr %11, ptr %14, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %6, i64 40
  store i32 1, ptr %15, align 8, !tbaa !16
  store i64 0, ptr %6, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr null, ptr %16, align 8, !tbaa !18
  %17 = getelementptr inbounds i8, ptr %6, i64 24
  %18 = getelementptr inbounds i8, ptr %6, i64 56
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %17, i8 0, i64 16, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %18, i8 0, i64 24, i1 false)
  br label %.critedge

.thread:                                          ; preds = %10, %7
  tail call void @free(ptr noundef %8) #5
  tail call void @free(ptr noundef nonnull %6) #5
  br label %.critedge

.critedge:                                        ; preds = %.thread, %1, %12
  %.0 = phi ptr [ %6, %12 ], [ null, %1 ], [ null, %.thread ]
  ret ptr %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { mustprogress nounwind willreturn memory(readwrite, argmem: none) 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind allocsize(0) }
attributes #5 = { 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, !10, i64 16}
!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 = !{!13, !10, i64 0}
!13 = !{!"iwpool_unit", !10, i64 0, !10, i64 8}
!14 = !{!6, !7, i64 8}
!15 = !{!6, !10, i64 48}
!16 = !{!6, !11, i64 40}
!17 = !{!6, !7, i64 0}
!18 = !{!13, !10, i64 8}


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