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

; 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
define dso_local ptr @iwpool_alloc(i64 noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %9 = load i64, ptr %4, align 8, !tbaa !5
  %10 = add i64 %9, 8
  %11 = sub i64 %10, 1
  %12 = and i64 %11, -8
  store i64 %12, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.iwpool, ptr %13, i32 0, i32 0
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = add i64 %15, %16
  store i64 %17, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.iwpool, ptr %18, i32 0, i32 0
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = sub i64 -1, %20
  %22 = load i64, ptr %4, align 8, !tbaa !5
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %70

25:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %26 = load ptr, ptr %5, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.iwpool, ptr %26, i32 0, i32 6
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  store ptr %28, ptr %8, align 8, !tbaa !9
  %29 = load i64, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.iwpool, ptr %30, i32 0, i32 1
  %32 = load i64, ptr %31, align 8, !tbaa !15
  %33 = icmp ugt i64 %29, %32
  br i1 %33, label %34, label %57

34:                                               ; preds = %25
  %35 = load ptr, ptr %5, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.iwpool, ptr %35, i32 0, i32 1
  %37 = load i64, ptr %36, align 8, !tbaa !15
  %38 = sub i64 -1, %37
  %39 = load i64, ptr %6, align 8, !tbaa !5
  %40 = icmp ult i64 %38, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %34
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %69

42:                                               ; preds = %34
  %43 = load i64, ptr %6, align 8, !tbaa !5
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.iwpool, ptr %44, i32 0, i32 1
  %46 = load i64, ptr %45, align 8, !tbaa !15
  %47 = add i64 %43, %46
  store i64 %47, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %5, align 8, !tbaa !9
  %49 = load i64, ptr %6, align 8, !tbaa !5
  %50 = call i32 @iwpool_extend(ptr noundef %48, i64 noundef %49)
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %53, label %52

52:                                               ; preds = %42
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %69

53:                                               ; preds = %42
  %54 = load ptr, ptr %5, align 8, !tbaa !9
  %55 = getelementptr inbounds %struct.iwpool, ptr %54, i32 0, i32 6
  %56 = load ptr, ptr %55, align 8, !tbaa !14
  store ptr %56, ptr %8, align 8, !tbaa !9
  br label %57

57:                                               ; preds = %53, %25
  %58 = load i64, ptr %4, align 8, !tbaa !5
  %59 = load ptr, ptr %5, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.iwpool, ptr %59, i32 0, i32 0
  %61 = load i64, ptr %60, align 8, !tbaa !11
  %62 = add i64 %61, %58
  store i64 %62, ptr %60, align 8, !tbaa !11
  %63 = load i64, ptr %4, align 8, !tbaa !5
  %64 = load ptr, ptr %5, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.iwpool, ptr %64, i32 0, i32 6
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  %67 = getelementptr inbounds i8, ptr %66, i64 %63
  store ptr %67, ptr %65, align 8, !tbaa !14
  %68 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %68, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %69

69:                                               ; preds = %57, %52, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %70

70:                                               ; preds = %69, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %71 = load ptr, ptr %3, align 8
  ret ptr %71
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @iwpool_extend(ptr noundef, i64 noundef) #2

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 = { alwaysinline 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 = !{!"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, !6, i64 0}
!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 = !{!12, !10, i64 48}
!15 = !{!12, !6, i64 8}


; 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: nounwind uwtable
define dso_local ptr @iwpool_alloc(i64 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = add i64 %0, 7
  %4 = and i64 %3, -8
  %5 = load i64, ptr %1, align 8, !tbaa !5
  %6 = add i64 %5, %4
  %7 = xor i64 %5, -1
  %8 = icmp ugt i64 %4, %7
  br i1 %8, label %22, label %9

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %1, i64 48
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !12
  %13 = icmp ugt i64 %6, %12
  br i1 %13, label %14, label %20

14:                                               ; preds = %9
  %15 = xor i64 %12, -1
  %16 = icmp ugt i64 %6, %15
  br i1 %16, label %22, label %17

17:                                               ; preds = %14
  %18 = add i64 %12, %6
  %19 = tail call i32 @iwpool_extend(ptr noundef nonnull %1, i64 noundef %18)
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %22, label %._crit_edge

._crit_edge:                                      ; preds = %17
  %.pre = load i64, ptr %1, align 8, !tbaa !5
  %.pre24 = add i64 %.pre, %4
  br label %20

20:                                               ; preds = %._crit_edge, %9
  %.pre-phi = phi i64 [ %.pre24, %._crit_edge ], [ %6, %9 ]
  %.0 = load ptr, ptr %10, align 8, !tbaa !13
  store i64 %.pre-phi, ptr %1, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %.0, i64 %4
  store ptr %21, ptr %10, align 8, !tbaa !13
  br label %22

22:                                               ; preds = %20, %14, %17, %2
  %.1 = phi ptr [ null, %2 ], [ %.0, %20 ], [ null, %14 ], [ null, %17 ]
  ret ptr %.1
}

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @iwpool_extend(ptr noundef, i64 noundef) local_unnamed_addr #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 = { alwaysinline 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" }

!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 = !{!"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, !7, i64 8}
!13 = !{!6, !10, i64 48}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass