; 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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i64 @iwlist_set(ptr noundef %0, i64 noundef %1, ptr noundef %2, i64 noundef %3) #5 {
  %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 ptr, align 8
  %11 = 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
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.iwlist, ptr %13, i32 0, i32 3
  %15 = load i64, ptr %14, align 8, !tbaa !11
  %16 = icmp uge i64 %12, %15
  br i1 %16, label %17, label %18

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

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

33:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.iwlist, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = load i64, ptr %7, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.iwlistitem, ptr %36, i64 %37
  %39 = getelementptr inbounds %struct.iwlistitem, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !17
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = add i64 %41, 1
  %43 = call ptr @realloc(ptr noundef %40, i64 noundef %42) #7
  store ptr %43, ptr %10, align 8, !tbaa !5
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %50, label %46

46:                                               ; preds = %33
  %47 = call ptr @__errno_location() #8
  %48 = load i32, ptr %47, align 4, !tbaa !18
  %49 = call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %48)
  store i64 %49, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %58

50:                                               ; preds = %33
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.iwlist, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  %55 = load i64, ptr %7, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.iwlistitem, ptr %54, i64 %55
  %57 = getelementptr inbounds %struct.iwlistitem, ptr %56, i32 0, i32 0
  store ptr %51, ptr %57, align 8, !tbaa !17
  store i32 0, ptr %11, align 4
  br label %58

58:                                               ; preds = %50, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  %59 = load i32, ptr %11, align 4
  switch i32 %59, label %89 [
    i32 0, label %60
    i32 1, label %87
  ]

60:                                               ; preds = %58
  br label %61

61:                                               ; preds = %60, %18
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.iwlist, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !14
  %65 = load i64, ptr %7, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.iwlistitem, ptr %64, i64 %65
  %67 = getelementptr inbounds %struct.iwlistitem, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !17
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %68, ptr align 1 %69, i64 %70, i1 false)
  %71 = load i64, ptr %9, align 8, !tbaa !9
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.iwlist, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !14
  %75 = load i64, ptr %7, align 8, !tbaa !9
  %76 = getelementptr inbounds %struct.iwlistitem, ptr %74, i64 %75
  %77 = getelementptr inbounds %struct.iwlistitem, ptr %76, i32 0, i32 1
  store i64 %71, ptr %77, align 8, !tbaa !15
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.iwlist, ptr %78, i32 0, i32 0
  %80 = load ptr, ptr %79, align 8, !tbaa !14
  %81 = load i64, ptr %7, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct.iwlistitem, ptr %80, i64 %81
  %83 = getelementptr inbounds %struct.iwlistitem, ptr %82, i32 0, i32 0
  %84 = load ptr, ptr %83, align 8, !tbaa !17
  %85 = load i64, ptr %9, align 8, !tbaa !9
  %86 = getelementptr inbounds i8, ptr %84, i64 %85
  store i8 0, ptr %86, align 1, !tbaa !20
  store i64 0, ptr %5, align 8
  br label %87

87:                                               ; preds = %61, %58, %17
  %88 = load i64, ptr %5, align 8
  ret i64 %88

89:                                               ; preds = %58
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #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 }
attributes #7 = { nounwind allocsize(1) }
attributes #8 = { nounwind willreturn memory(none) }

!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, !6, i64 0}
!15 = !{!16, !10, i64 8}
!16 = !{!"iwlistitem", !6, i64 0, !10, i64 8}
!17 = !{!16, !6, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"int", !7, i64 0}
!20 = !{!7, !7, i64 0}


; 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

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

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

; 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 #3

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

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = add i64 %9, %1
  %11 = load ptr, ptr %0, align 8, !tbaa !12
  %12 = getelementptr inbounds %struct.iwlistitem, ptr %11, i64 %10
  %13 = getelementptr inbounds i8, ptr %12, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !13
  %15 = icmp ult i64 %14, %3
  %16 = load ptr, ptr %12, align 8, !tbaa !15
  br i1 %15, label %17, label %._crit_edge

17:                                               ; preds = %7
  %18 = add i64 %3, 1
  %19 = tail call ptr @realloc(ptr noundef %16, i64 noundef %18) #5
  %.not29 = icmp eq ptr %19, null
  br i1 %.not29, label %22, label %.thread

.thread:                                          ; preds = %17
  %20 = load ptr, ptr %0, align 8, !tbaa !12
  %21 = getelementptr inbounds %struct.iwlistitem, ptr %20, i64 %10
  store ptr %19, ptr %21, align 8, !tbaa !15
  br label %._crit_edge

22:                                               ; preds = %17
  %23 = tail call ptr @__errno_location() #6
  %24 = load i32, ptr %23, align 4, !tbaa !16
  %25 = tail call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %24) #7
  br label %32

._crit_edge:                                      ; preds = %7, %.thread
  %26 = phi ptr [ %19, %.thread ], [ %16, %7 ]
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %26, ptr align 1 %2, i64 %3, i1 false)
  %27 = load ptr, ptr %0, align 8, !tbaa !12
  %28 = getelementptr inbounds %struct.iwlistitem, ptr %27, i64 %10, i32 1
  store i64 %3, ptr %28, align 8, !tbaa !13
  %29 = getelementptr inbounds %struct.iwlistitem, ptr %27, i64 %10
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = getelementptr inbounds i8, ptr %30, i64 %3
  store i8 0, ptr %31, align 1, !tbaa !18
  br label %32

32:                                               ; preds = %22, %4, %._crit_edge
  %.1 = phi i64 [ %25, %22 ], [ 0, %._crit_edge ], [ 70011, %4 ]
  ret i64 %.1
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #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 #2 = { 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 #3 = { 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 #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 allocsize(1) }
attributes #6 = { nounwind willreturn memory(none) }
attributes #7 = { 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, !10, i64 16}
!12 = !{!6, !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"iwlistitem", !7, i64 0, !10, i64 8}
!15 = !{!14, !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !8, i64 0}
!18 = !{!8, !8, i64 0}


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