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

; 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 dso_local ptr @iwpool_alloc(i64 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @iwpool_strdup2(ptr noundef, ptr noundef) #1

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

11:                                               ; preds = %20, %2
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %18

14:                                               ; preds = %11
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br label %18

18:                                               ; preds = %14, %11
  %19 = phi i1 [ false, %11 ], [ %17, %14 ]
  br i1 %19, label %20, label %23

20:                                               ; preds = %18
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds ptr, ptr %21, i32 1
  store ptr %22, ptr %6, align 8, !tbaa !5
  br label %11, !llvm.loop !9

23:                                               ; preds = %18
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = icmp ugt ptr %24, %25
  br i1 %26, label %27, label %62

27:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = ptrtoint ptr %28 to i64
  %31 = ptrtoint ptr %29 to i64
  %32 = sub i64 %30, %31
  %33 = sdiv exact i64 %32, 8
  %34 = add nsw i64 %33, 1
  %35 = mul i64 8, %34
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call ptr @iwpool_alloc(i64 noundef %35, ptr noundef %36)
  store ptr %37, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %38, ptr %8, align 8, !tbaa !5
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %60

41:                                               ; preds = %27
  br label %42

42:                                               ; preds = %52, %41
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %57

46:                                               ; preds = %42
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = call ptr @iwpool_strdup2(ptr noundef %47, ptr noundef %49)
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %50, ptr %51, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %46
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds ptr, ptr %53, i32 1
  store ptr %54, ptr %8, align 8, !tbaa !5
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds ptr, ptr %55, i32 1
  store ptr %56, ptr %4, align 8, !tbaa !5
  br label %42, !llvm.loop !11

57:                                               ; preds = %42
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds ptr, ptr %58, i32 1
  store ptr %59, ptr %8, align 8, !tbaa !5
  store ptr null, ptr %59, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %57, %27
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %61, ptr %3, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %63

62:                                               ; preds = %23
  store ptr null, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %63

63:                                               ; preds = %62, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %64 = load ptr, ptr %3, align 8
  ret ptr %64
}

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 }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; 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
declare dso_local ptr @iwpool_alloc(i64 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @iwpool_strdup2(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @iwpool_copy_cstring_array(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %.not29 = icmp eq ptr %0, null
  br i1 %.not29, label %.critedge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %.02130 = phi ptr [ %4, %.lr.ph ], [ %0, %2 ]
  %3 = load ptr, ptr %.02130, align 8, !tbaa !5
  %.not26 = icmp eq ptr %3, null
  %4 = getelementptr inbounds i8, ptr %.02130, i64 8
  br i1 %.not26, label %.critedge, label %.lr.ph

.critedge:                                        ; preds = %.lr.ph
  %5 = icmp ugt ptr %.02130, %0
  br i1 %5, label %6, label %.critedge.thread

6:                                                ; preds = %.critedge
  %7 = ptrtoint ptr %.02130 to i64
  %8 = ptrtoint ptr %0 to i64
  %reass.sub = sub i64 %7, %8
  %9 = add i64 %reass.sub, 8
  %10 = tail call ptr @iwpool_alloc(i64 noundef %9, ptr noundef %1)
  %.not27 = icmp eq ptr %10, null
  br i1 %.not27, label %.critedge.thread, label %.preheader

.preheader:                                       ; preds = %6
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %.not2833 = icmp eq ptr %11, null
  br i1 %.not2833, label %._crit_edge, label %.lr.ph36

.lr.ph36:                                         ; preds = %.preheader, %.lr.ph36
  %12 = phi ptr [ %16, %.lr.ph36 ], [ %11, %.preheader ]
  %.035 = phi ptr [ %14, %.lr.ph36 ], [ %10, %.preheader ]
  %.02234 = phi ptr [ %15, %.lr.ph36 ], [ %0, %.preheader ]
  %13 = tail call ptr @iwpool_strdup2(ptr noundef %1, ptr noundef nonnull %12)
  store ptr %13, ptr %.035, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %.035, i64 8
  %15 = getelementptr inbounds i8, ptr %.02234, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %.not28 = icmp eq ptr %16, null
  br i1 %.not28, label %._crit_edge, label %.lr.ph36, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph36, %.preheader
  %.0.lcssa = phi ptr [ %10, %.preheader ], [ %14, %.lr.ph36 ]
  %17 = getelementptr inbounds i8, ptr %.0.lcssa, i64 8
  store ptr null, ptr %17, align 8, !tbaa !5
  br label %.critedge.thread

.critedge.thread:                                 ; preds = %2, %.critedge, %6, %._crit_edge
  %.020 = phi ptr [ %10, %._crit_edge ], [ null, %6 ], [ null, %.critedge ], [ null, %2 ]
  ret ptr %.020
}

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass