; 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

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_push(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 i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.iwlist, ptr %13, i32 0, i32 2
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.iwlist, ptr %16, i32 0, i32 3
  %18 = load i64, ptr %17, align 8, !tbaa !13
  %19 = add i64 %15, %18
  store i64 %19, ptr %8, align 8, !tbaa !9
  %20 = load i64, ptr %8, align 8, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.iwlist, ptr %21, i32 0, i32 1
  %23 = load i64, ptr %22, align 8, !tbaa !14
  %24 = icmp uge i64 %20, %23
  br i1 %24, label %25, label %56

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

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

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

53:                                               ; preds = %46, %42
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  %54 = load i32, ptr %11, align 4
  switch i32 %54, label %102 [
    i32 0, label %55
  ]

55:                                               ; preds = %53
  br label %56

56:                                               ; preds = %55, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.iwlist, ptr %57, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !15
  store ptr %59, ptr %12, align 8, !tbaa !5
  %60 = load i64, ptr %7, align 8, !tbaa !9
  %61 = add i64 %60, 1
  %62 = call noalias ptr @malloc(i64 noundef %61) #10
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.iwlistitem, ptr %63, i64 %64
  %66 = getelementptr inbounds %struct.iwlistitem, ptr %65, i32 0, i32 0
  store ptr %62, ptr %66, align 8, !tbaa !18
  %67 = load ptr, ptr %12, align 8, !tbaa !5
  %68 = load i64, ptr %8, align 8, !tbaa !9
  %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 !18
  %72 = icmp ne ptr %71, null
  br i1 %72, label %77, label %73

73:                                               ; preds = %56
  %74 = call ptr @__errno_location() #9
  %75 = load i32, ptr %74, align 4, !tbaa !16
  %76 = call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %75)
  store i64 %76, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %101

77:                                               ; preds = %56
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  %79 = load i64, ptr %8, align 8, !tbaa !9
  %80 = getelementptr inbounds %struct.iwlistitem, ptr %78, i64 %79
  %81 = getelementptr inbounds %struct.iwlistitem, ptr %80, i32 0, i32 0
  %82 = load ptr, ptr %81, align 8, !tbaa !18
  %83 = load ptr, ptr %6, align 8, !tbaa !5
  %84 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %82, ptr align 1 %83, i64 %84, i1 false)
  %85 = load ptr, ptr %12, align 8, !tbaa !5
  %86 = load i64, ptr %8, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.iwlistitem, ptr %85, i64 %86
  %88 = getelementptr inbounds %struct.iwlistitem, ptr %87, i32 0, i32 0
  %89 = load ptr, ptr %88, align 8, !tbaa !18
  %90 = load i64, ptr %7, align 8, !tbaa !9
  %91 = getelementptr inbounds i8, ptr %89, i64 %90
  store i8 0, ptr %91, align 1, !tbaa !20
  %92 = load i64, ptr %7, align 8, !tbaa !9
  %93 = load ptr, ptr %12, align 8, !tbaa !5
  %94 = load i64, ptr %8, align 8, !tbaa !9
  %95 = getelementptr inbounds %struct.iwlistitem, ptr %93, i64 %94
  %96 = getelementptr inbounds %struct.iwlistitem, ptr %95, i32 0, i32 1
  store i64 %92, ptr %96, align 8, !tbaa !21
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.iwlist, ptr %97, i32 0, i32 3
  %99 = load i64, ptr %98, align 8, !tbaa !13
  %100 = add i64 %99, 1
  store i64 %100, ptr %98, align 8, !tbaa !13
  store i64 0, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %101

101:                                              ; preds = %77, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  br label %102

102:                                              ; preds = %101, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  %103 = load i64, ptr %4, align 8
  ret i64 %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 = { "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 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_push(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
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %8 = add i64 %7, %5
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !12
  %.not = icmp ult i64 %8, %10
  %.pre = load ptr, ptr %0, align 8, !tbaa !13
  br i1 %.not, label %20, label %11

11:                                               ; preds = %3
  %12 = add i64 %7, 1
  %13 = add i64 %12, %10
  %14 = shl i64 %13, 4
  %15 = tail call ptr @realloc(ptr noundef %.pre, i64 noundef %14) #6
  %.not35.not = icmp eq ptr %15, null
  br i1 %.not35.not, label %.thread, label %19

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

19:                                               ; preds = %11
  store i64 %13, ptr %9, align 8, !tbaa !12
  store ptr %15, ptr %0, align 8, !tbaa !13
  br label %20

20:                                               ; preds = %19, %3
  %21 = phi ptr [ %15, %19 ], [ %.pre, %3 ]
  %22 = add i64 %2, 1
  %23 = tail call noalias ptr @malloc(i64 noundef %22) #9
  %24 = getelementptr inbounds %struct.iwlistitem, ptr %21, i64 %8
  store ptr %23, ptr %24, align 8, !tbaa !16
  %.not36 = icmp eq ptr %23, null
  br i1 %.not36, label %25, label %29

25:                                               ; preds = %20
  %26 = tail call ptr @__errno_location() #7
  %27 = load i32, ptr %26, align 4, !tbaa !14
  %28 = tail call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %27) #8
  br label %34

29:                                               ; preds = %20
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %23, ptr align 1 %1, i64 %2, i1 false)
  %30 = getelementptr inbounds i8, ptr %23, i64 %2
  store i8 0, ptr %30, align 1, !tbaa !18
  %31 = getelementptr inbounds i8, ptr %24, i64 8
  store i64 %2, ptr %31, align 8, !tbaa !19
  %32 = load i64, ptr %6, align 8, !tbaa !11
  %33 = add i64 %32, 1
  store i64 %33, ptr %6, align 8, !tbaa !11
  br label %34

34:                                               ; preds = %.thread, %25, %29
  %.2 = phi i64 [ 0, %29 ], [ %28, %25 ], [ %18, %.thread ]
  ret i64 %.2
}

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,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass