; 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_unshift(ptr noundef %0, ptr noundef %1, i64 noundef %2) #6 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.iwlist, ptr %12, i32 0, i32 2
  %14 = load i64, ptr %13, align 8, !tbaa !11
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %79, label %16

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.iwlist, ptr %17, i32 0, i32 3
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.iwlist, ptr %20, i32 0, i32 1
  %22 = load i64, ptr %21, align 8, !tbaa !14
  %23 = icmp uge i64 %19, %22
  br i1 %23, label %24, label %55

24:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.iwlist, ptr %25, i32 0, i32 1
  %27 = load i64, ptr %26, align 8, !tbaa !14
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.iwlist, ptr %28, i32 0, i32 3
  %30 = load i64, ptr %29, align 8, !tbaa !13
  %31 = add i64 %27, %30
  %32 = add i64 %31, 1
  store i64 %32, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.iwlist, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = mul i64 %36, 16
  %38 = call ptr @realloc(ptr noundef %35, i64 noundef %37) #8
  store ptr %38, ptr %9, align 8, !tbaa !5
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %45, label %41

41:                                               ; preds = %24
  %42 = call ptr @__errno_location() #9
  %43 = load i32, ptr %42, align 4, !tbaa !16
  %44 = call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %43)
  store i64 %44, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %52

45:                                               ; preds = %24
  %46 = load i64, ptr %8, align 8, !tbaa !9
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.iwlist, ptr %47, i32 0, i32 1
  store i64 %46, ptr %48, align 8, !tbaa !14
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.iwlist, ptr %50, i32 0, i32 0
  store ptr %49, ptr %51, align 8, !tbaa !15
  store i32 0, ptr %10, align 4
  br label %52

52:                                               ; preds = %45, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  %53 = load i32, ptr %10, align 4
  switch i32 %53, label %128 [
    i32 0, label %54
    i32 1, label %126
  ]

54:                                               ; preds = %52
  br label %55

55:                                               ; preds = %54, %16
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.iwlist, ptr %56, i32 0, i32 1
  %58 = load i64, ptr %57, align 8, !tbaa !14
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.iwlist, ptr %59, i32 0, i32 3
  %61 = load i64, ptr %60, align 8, !tbaa !13
  %62 = sub i64 %58, %61
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.iwlist, ptr %63, i32 0, i32 2
  store i64 %62, ptr %64, align 8, !tbaa !11
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.iwlist, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !15
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.iwlist, ptr %68, i32 0, i32 2
  %70 = load i64, ptr %69, align 8, !tbaa !11
  %71 = getelementptr inbounds %struct.iwlistitem, ptr %67, i64 %70
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.iwlist, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !15
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.iwlist, ptr %75, i32 0, i32 1
  %77 = load i64, ptr %76, align 8, !tbaa !14
  %78 = mul i64 %77, 16
  call void @llvm.memmove.p0.p0.i64(ptr align 8 %71, ptr align 8 %74, i64 %78, i1 false)
  br label %79

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

126:                                              ; preds = %79, %52
  %127 = load i64, ptr %4, align 8
  ret i64 %127

128:                                              ; preds = %52
  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 16}
!12 = !{!"iwlist", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 24}
!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_unshift(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #5 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %6, label %26

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i64, ptr %7, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !12
  %.not40 = icmp ult i64 %8, %10
  %.pre44 = load ptr, ptr %0, align 8, !tbaa !13
  br i1 %.not40, label %._crit_edge, label %11

._crit_edge:                                      ; preds = %6
  %.pre46 = shl i64 %10, 4
  br label %20

11:                                               ; preds = %6
  %12 = add i64 %8, 1
  %13 = add i64 %12, %10
  %14 = shl i64 %13, 4
  %15 = tail call ptr @realloc(ptr noundef %.pre44, i64 noundef %14) #6
  %.not41 = icmp eq ptr %15, null
  br i1 %.not41, label %16, label %.thread

.thread:                                          ; preds = %11
  store i64 %13, ptr %9, align 8, !tbaa !12
  store ptr %15, ptr %0, align 8, !tbaa !13
  %.pre = load i64, ptr %7, align 8, !tbaa !11
  br label %20

16:                                               ; preds = %11
  %17 = tail call ptr @__errno_location() #7
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %19 = tail call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %18) #8
  br label %38

20:                                               ; preds = %._crit_edge, %.thread
  %.pre-phi = phi i64 [ %.pre46, %._crit_edge ], [ %14, %.thread ]
  %21 = phi ptr [ %.pre44, %._crit_edge ], [ %15, %.thread ]
  %22 = phi i64 [ %8, %._crit_edge ], [ %.pre, %.thread ]
  %23 = phi i64 [ %10, %._crit_edge ], [ %13, %.thread ]
  %24 = sub i64 %23, %22
  store i64 %24, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.iwlistitem, ptr %21, i64 %24
  tail call void @llvm.memmove.p0.p0.i64(ptr align 8 %25, ptr align 8 %21, i64 %.pre-phi, i1 false)
  %.pre45 = load i64, ptr %4, align 8, !tbaa !5
  br label %26

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

38:                                               ; preds = %16, %26
  %.1 = phi i64 [ 0, %26 ], [ %19, %16 ]
  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 16}
!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 24}
!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