; 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #1

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

declare i64 @iwrc_set_errno(i64 noundef, i32 noundef) #3

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #4

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #5

; Function Attrs: nounwind uwtable
define dso_local i64 @iwlist_insert(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #6 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  %13 = load i64, ptr %7, align 8, !tbaa !9
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.iwlist, ptr %14, i32 0, i32 3
  %16 = load i64, ptr %15, align 8, !tbaa !11
  %17 = icmp ugt i64 %13, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %4
  store i64 70011, ptr %5, align 8
  br label %127

19:                                               ; preds = %4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.iwlist, ptr %20, i32 0, i32 2
  %22 = load i64, ptr %21, align 8, !tbaa !13
  %23 = load i64, ptr %7, align 8, !tbaa !9
  %24 = add i64 %23, %22
  store i64 %24, ptr %7, align 8, !tbaa !9
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.iwlist, ptr %25, i32 0, i32 2
  %27 = load i64, ptr %26, align 8, !tbaa !13
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.iwlist, ptr %28, i32 0, i32 3
  %30 = load i64, ptr %29, align 8, !tbaa !11
  %31 = add i64 %27, %30
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.iwlist, ptr %32, i32 0, i32 1
  %34 = load i64, ptr %33, align 8, !tbaa !14
  %35 = icmp uge i64 %31, %34
  br i1 %35, label %36, label %67

36:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #7
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.iwlist, ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !14
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.iwlist, ptr %40, i32 0, i32 3
  %42 = load i64, ptr %41, align 8, !tbaa !11
  %43 = add i64 %39, %42
  %44 = add i64 %43, 1
  store i64 %44, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.iwlist, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  %48 = load i64, ptr %10, align 8, !tbaa !9
  %49 = mul i64 %48, 16
  %50 = call ptr @realloc(ptr noundef %47, i64 noundef %49) #8
  store ptr %50, ptr %11, align 8, !tbaa !5
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %57, label %53

53:                                               ; preds = %36
  %54 = call ptr @__errno_location() #9
  %55 = load i32, ptr %54, align 4, !tbaa !16
  %56 = call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %55)
  store i64 %56, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %64

57:                                               ; preds = %36
  %58 = load i64, ptr %10, align 8, !tbaa !9
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.iwlist, ptr %59, i32 0, i32 1
  store i64 %58, ptr %60, align 8, !tbaa !14
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.iwlist, ptr %62, i32 0, i32 0
  store ptr %61, ptr %63, align 8, !tbaa !15
  store i32 0, ptr %12, align 4
  br label %64

64:                                               ; preds = %57, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  %65 = load i32, ptr %12, align 4
  switch i32 %65, label %129 [
    i32 0, label %66
    i32 1, label %127
  ]

66:                                               ; preds = %64
  br label %67

67:                                               ; preds = %66, %19
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.iwlist, ptr %68, i32 0, i32 0
  %70 = load ptr, ptr %69, align 8, !tbaa !15
  %71 = load i64, ptr %7, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.iwlistitem, ptr %70, i64 %71
  %73 = getelementptr inbounds %struct.iwlistitem, ptr %72, i64 1
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.iwlist, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !15
  %77 = load i64, ptr %7, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.iwlistitem, ptr %76, i64 %77
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.iwlist, ptr %79, i32 0, i32 2
  %81 = load i64, ptr %80, align 8, !tbaa !13
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.iwlist, ptr %82, i32 0, i32 3
  %84 = load i64, ptr %83, align 8, !tbaa !11
  %85 = add i64 %81, %84
  %86 = load i64, ptr %7, align 8, !tbaa !9
  %87 = sub i64 %85, %86
  %88 = mul i64 16, %87
  call void @llvm.memmove.p0.p0.i64(ptr align 8 %73, ptr align 8 %78, i64 %88, i1 false)
  %89 = load i64, ptr %9, align 8, !tbaa !9
  %90 = add i64 %89, 1
  %91 = call noalias ptr @malloc(i64 noundef %90) #10
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.iwlist, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !15
  %95 = load i64, ptr %7, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct.iwlistitem, ptr %94, i64 %95
  %97 = getelementptr inbounds %struct.iwlistitem, ptr %96, i32 0, i32 0
  store ptr %91, ptr %97, align 8, !tbaa !18
  %98 = load ptr, ptr %6, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.iwlist, ptr %98, i32 0, i32 0
  %100 = load ptr, ptr %99, align 8, !tbaa !15
  %101 = load i64, ptr %7, align 8, !tbaa !9
  %102 = getelementptr inbounds %struct.iwlistitem, ptr %100, i64 %101
  %103 = getelementptr inbounds %struct.iwlistitem, ptr %102, i32 0, i32 0
  %104 = load ptr, ptr %103, align 8, !tbaa !18
  %105 = load ptr, ptr %8, align 8, !tbaa !5
  %106 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %104, ptr align 1 %105, i64 %106, i1 false)
  %107 = load ptr, ptr %6, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.iwlist, ptr %107, i32 0, i32 0
  %109 = load ptr, ptr %108, align 8, !tbaa !15
  %110 = load i64, ptr %7, align 8, !tbaa !9
  %111 = getelementptr inbounds %struct.iwlistitem, ptr %109, i64 %110
  %112 = getelementptr inbounds %struct.iwlistitem, ptr %111, i32 0, i32 0
  %113 = load ptr, ptr %112, align 8, !tbaa !18
  %114 = load i64, ptr %9, align 8, !tbaa !9
  %115 = getelementptr inbounds i8, ptr %113, i64 %114
  store i8 0, ptr %115, align 1, !tbaa !20
  %116 = load i64, ptr %9, align 8, !tbaa !9
  %117 = load ptr, ptr %6, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.iwlist, ptr %117, i32 0, i32 0
  %119 = load ptr, ptr %118, align 8, !tbaa !15
  %120 = load i64, ptr %7, align 8, !tbaa !9
  %121 = getelementptr inbounds %struct.iwlistitem, ptr %119, i64 %120
  %122 = getelementptr inbounds %struct.iwlistitem, ptr %121, i32 0, i32 1
  store i64 %116, ptr %122, align 8, !tbaa !21
  %123 = load ptr, ptr %6, align 8, !tbaa !5
  %124 = getelementptr inbounds %struct.iwlist, ptr %123, i32 0, i32 3
  %125 = load i64, ptr %124, align 8, !tbaa !11
  %126 = add i64 %125, 1
  store i64 %126, ptr %124, align 8, !tbaa !11
  store i64 0, ptr %5, align 8
  br label %127

127:                                              ; preds = %67, %64, %18
  %128 = load i64, ptr %5, align 8
  ret i64 %128

129:                                              ; preds = %64
  unreachable
}

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 = { "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 willreturn memory(none) "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 allocsize(1) "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 #6 = { 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 #7 = { nounwind }
attributes #8 = { nounwind allocsize(1) }
attributes #9 = { nounwind willreturn memory(none) }
attributes #10 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"iwlist", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !6, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !7, i64 0}
!18 = !{!19, !6, i64 0}
!19 = !{!"iwlistitem", !6, i64 0, !10, i64 8}
!20 = !{!7, !7, i64 0}
!21 = !{!19, !10, 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 nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr 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

declare i64 @iwrc_set_errno(i64 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local i64 @iwlist_insert(ptr nocapture noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2, i64 noundef %3) local_unnamed_addr #5 {
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp ult i64 %6, %1
  br i1 %7, label %41, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load i64, ptr %9, align 8, !tbaa !11
  %11 = add i64 %10, %1
  %12 = add i64 %10, %6
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !12
  %.not = icmp ult i64 %12, %14
  %.pre = load ptr, ptr %0, align 8, !tbaa !13
  br i1 %.not, label %24, label %15

15:                                               ; preds = %8
  %16 = add i64 %6, 1
  %17 = add i64 %16, %14
  %18 = shl i64 %17, 4
  %19 = tail call ptr @realloc(ptr noundef %.pre, i64 noundef %18) #6
  %.not43 = icmp eq ptr %19, null
  br i1 %.not43, label %20, label %.thread

.thread:                                          ; preds = %15
  store i64 %17, ptr %13, align 8, !tbaa !12
  store ptr %19, ptr %0, align 8, !tbaa !13
  %.pre46 = load i64, ptr %9, align 8, !tbaa !11
  %.pre47 = load i64, ptr %5, align 8, !tbaa !5
  br label %24

20:                                               ; preds = %15
  %21 = tail call ptr @__errno_location() #7
  %22 = load i32, ptr %21, align 4, !tbaa !14
  %23 = tail call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %22) #8
  br label %41

24:                                               ; preds = %.thread, %8
  %25 = phi i64 [ %.pre47, %.thread ], [ %6, %8 ]
  %26 = phi i64 [ %.pre46, %.thread ], [ %10, %8 ]
  %27 = phi ptr [ %19, %.thread ], [ %.pre, %8 ]
  %28 = getelementptr inbounds %struct.iwlistitem, ptr %27, i64 %11
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  %30 = sub i64 %26, %11
  %31 = add i64 %30, %25
  %32 = shl i64 %31, 4
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 8 %29, ptr align 8 %28, i64 %32, i1 false)
  %33 = add i64 %3, 1
  %34 = tail call noalias ptr @malloc(i64 noundef %33) #9
  %35 = load ptr, ptr %0, align 8, !tbaa !13
  %36 = getelementptr inbounds %struct.iwlistitem, ptr %35, i64 %11
  store ptr %34, ptr %36, align 8, !tbaa !16
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %34, ptr align 1 %2, i64 %3, i1 false)
  %37 = getelementptr inbounds i8, ptr %34, i64 %3
  store i8 0, ptr %37, align 1, !tbaa !18
  %38 = getelementptr inbounds %struct.iwlistitem, ptr %35, i64 %11, i32 1
  store i64 %3, ptr %38, align 8, !tbaa !19
  %39 = load i64, ptr %5, align 8, !tbaa !5
  %40 = add i64 %39, 1
  store i64 %40, ptr %5, align 8, !tbaa !5
  br label %41

41:                                               ; preds = %20, %4, %24
  %.1 = phi i64 [ %23, %20 ], [ 0, %24 ], [ 70011, %4 ]
  ret i64 %.1
}

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 = { "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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) 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 #5 = { 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 #6 = { nounwind allocsize(1) }
attributes #7 = { nounwind willreturn memory(none) }
attributes #8 = { nounwind }
attributes #9 = { 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, !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, !10, i64 16}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !8, i64 0}
!16 = !{!17, !7, i64 0}
!17 = !{!"iwlistitem", !7, i64 0, !10, i64 8}
!18 = !{!8, !8, i64 0}
!19 = !{!17, !10, i64 8}


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