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

; 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.iwlist = type { ptr, i64, i64, i64 }
%struct.iwlistitem = type { ptr, i64 }

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local noalias ptr @iwlist_create(i64 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local noalias ptr @iwlist_clone(ptr noundef %0) #4 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.iwlist, ptr %11, i32 0, i32 3
  %13 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %13, ptr %4, align 8, !tbaa !12
  %14 = load i64, ptr %4, align 8, !tbaa !12
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %18, label %16

16:                                               ; preds = %1
  %17 = call noalias ptr @iwlist_create(i64 noundef 0)
  store ptr %17, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %102

18:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %19 = call noalias ptr @malloc(i64 noundef 32) #6
  store ptr %19, ptr %6, align 8, !tbaa !5
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %101

23:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.iwlist, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.iwlist, ptr %27, i32 0, i32 2
  %29 = load i64, ptr %28, align 8, !tbaa !14
  %30 = getelementptr inbounds %struct.iwlistitem, ptr %26, i64 %29
  store ptr %30, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %31 = load i64, ptr %4, align 8, !tbaa !12
  %32 = mul i64 16, %31
  %33 = call noalias ptr @malloc(i64 noundef %32) #6
  store ptr %33, ptr %8, align 8, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = icmp ne ptr %34, null
  br i1 %35, label %38, label %36

36:                                               ; preds = %23
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %37) #5
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %100

38:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store i64 0, ptr %9, align 8, !tbaa !12
  br label %39

39:                                               ; preds = %82, %38
  %40 = load i64, ptr %9, align 8, !tbaa !12
  %41 = load i64, ptr %4, align 8, !tbaa !12
  %42 = icmp ult i64 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  store i32 2, ptr %5, align 4
  br label %85

44:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load i64, ptr %9, align 8, !tbaa !12
  %47 = getelementptr inbounds %struct.iwlistitem, ptr %45, i64 %46
  %48 = getelementptr inbounds %struct.iwlistitem, ptr %47, i32 0, i32 1
  %49 = load i64, ptr %48, align 8, !tbaa !15
  %50 = add i64 %49, 1
  store i64 %50, ptr %10, align 8, !tbaa !12
  %51 = load i64, ptr %10, align 8, !tbaa !12
  %52 = call noalias ptr @malloc(i64 noundef %51) #6
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load i64, ptr %9, align 8, !tbaa !12
  %55 = getelementptr inbounds %struct.iwlistitem, ptr %53, i64 %54
  %56 = getelementptr inbounds %struct.iwlistitem, ptr %55, i32 0, i32 0
  store ptr %52, ptr %56, align 8, !tbaa !17
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  %58 = load i64, ptr %9, align 8, !tbaa !12
  %59 = getelementptr inbounds %struct.iwlistitem, ptr %57, i64 %58
  %60 = getelementptr inbounds %struct.iwlistitem, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !17
  %62 = icmp ne ptr %61, null
  br i1 %62, label %66, label %63

63:                                               ; preds = %44
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %64) #5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %65) #5
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %79

66:                                               ; preds = %44
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = load i64, ptr %9, align 8, !tbaa !12
  %69 = getelementptr inbounds %struct.iwlistitem, ptr %67, i64 %68
  %70 = getelementptr inbounds %struct.iwlistitem, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !17
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = load i64, ptr %9, align 8, !tbaa !12
  %74 = getelementptr inbounds %struct.iwlistitem, ptr %72, i64 %73
  %75 = getelementptr inbounds %struct.iwlistitem, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !17
  %77 = load i64, ptr %10, align 8, !tbaa !12
  %78 = add i64 %77, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %71, ptr align 1 %76, i64 %78, i1 false)
  store i32 0, ptr %5, align 4
  br label %79

79:                                               ; preds = %66, %63
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %80 = load i32, ptr %5, align 4
  switch i32 %80, label %85 [
    i32 0, label %81
  ]

81:                                               ; preds = %79
  br label %82

82:                                               ; preds = %81
  %83 = load i64, ptr %9, align 8, !tbaa !12
  %84 = add i64 %83, 1
  store i64 %84, ptr %9, align 8, !tbaa !12
  br label %39, !llvm.loop !18

85:                                               ; preds = %79, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  %86 = load i32, ptr %5, align 4
  switch i32 %86, label %100 [
    i32 2, label %87
  ]

87:                                               ; preds = %85
  %88 = load i64, ptr %4, align 8, !tbaa !12
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.iwlist, ptr %89, i32 0, i32 1
  store i64 %88, ptr %90, align 8, !tbaa !20
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.iwlist, ptr %92, i32 0, i32 0
  store ptr %91, ptr %93, align 8, !tbaa !13
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.iwlist, ptr %94, i32 0, i32 2
  store i64 0, ptr %95, align 8, !tbaa !14
  %96 = load i64, ptr %4, align 8, !tbaa !12
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.iwlist, ptr %97, i32 0, i32 3
  store i64 %96, ptr %98, align 8, !tbaa !9
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %99, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %100

100:                                              ; preds = %87, %85, %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %101

101:                                              ; preds = %100, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %102

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 24}
!10 = !{!"iwlist", !6, i64 0, !11, i64 8, !11, i64 16, !11, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 0}
!14 = !{!10, !11, i64 16}
!15 = !{!16, !11, i64 8}
!16 = !{!"iwlistitem", !6, i64 0, !11, i64 8}
!17 = !{!16, !6, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!10, !11, 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"

%struct.iwlistitem = type { ptr, i64 }

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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: nounwind uwtable
declare dso_local noalias ptr @iwlist_create(i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local noalias ptr @iwlist_clone(ptr nocapture noundef readonly %0) local_unnamed_addr #3 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %4, label %6

4:                                                ; preds = %1
  %5 = tail call noalias ptr @iwlist_create(i64 noundef 0)
  br label %30

6:                                                ; preds = %1
  %7 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #4
  %.not43 = icmp eq ptr %7, null
  br i1 %.not43, label %30, label %8

8:                                                ; preds = %6
  %9 = load ptr, ptr %0, align 8, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load i64, ptr %10, align 8, !tbaa !12
  %12 = getelementptr inbounds %struct.iwlistitem, ptr %9, i64 %11
  %13 = shl i64 %3, 4
  %14 = tail call noalias ptr @malloc(i64 noundef %13) #4
  %.not44 = icmp eq ptr %14, null
  br i1 %.not44, label %15, label %.preheader

15:                                               ; preds = %8
  tail call void @free(ptr noundef nonnull %7) #5
  br label %30

.preheader:                                       ; preds = %8, %22
  %.03647 = phi i64 [ %25, %22 ], [ 0, %8 ]
  %16 = getelementptr inbounds %struct.iwlistitem, ptr %12, i64 %.03647
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load i64, ptr %17, align 8, !tbaa !13
  %19 = add i64 %18, 1
  %20 = tail call noalias ptr @malloc(i64 noundef %19) #4
  %21 = getelementptr inbounds %struct.iwlistitem, ptr %14, i64 %.03647
  store ptr %20, ptr %21, align 8, !tbaa !15
  %.not45.not = icmp eq ptr %20, null
  br i1 %.not45.not, label %26, label %22

22:                                               ; preds = %.preheader
  %23 = load ptr, ptr %16, align 8, !tbaa !15
  %24 = add i64 %18, 2
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %20, ptr align 1 %23, i64 %24, i1 false)
  %25 = add nuw i64 %.03647, 1
  %exitcond.not = icmp eq i64 %25, %3
  br i1 %exitcond.not, label %.critedge, label %.preheader, !llvm.loop !16

26:                                               ; preds = %.preheader
  tail call void @free(ptr noundef nonnull %14) #5
  tail call void @free(ptr noundef %7) #5
  br label %30

.critedge:                                        ; preds = %22
  %27 = getelementptr inbounds i8, ptr %7, i64 8
  store i64 %3, ptr %27, align 8, !tbaa !18
  store ptr %14, ptr %7, align 8, !tbaa !11
  %28 = getelementptr inbounds i8, ptr %7, i64 16
  store i64 0, ptr %28, align 8, !tbaa !12
  %29 = getelementptr inbounds i8, ptr %7, i64 24
  store i64 %3, ptr %29, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %26, %6, %.critedge, %15, %4
  %.5 = phi ptr [ %5, %4 ], [ null, %6 ], [ %7, %.critedge ], [ null, %26 ], [ null, %15 ]
  ret ptr %.5
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 24}
!6 = !{!"iwlist", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 16}
!13 = !{!14, !10, i64 8}
!14 = !{!"iwlistitem", !7, i64 0, !10, i64 8}
!15 = !{!14, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!6, !10, i64 8}


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