; 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.iwulist = type { ptr, i64, i64, i64, 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

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

16:                                               ; preds = %3
  store i64 70011, ptr %4, align 8
  br label %118

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

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

54:                                               ; preds = %34
  %55 = call ptr @__errno_location() #8
  %56 = load i32, ptr %55, align 4, !tbaa !17
  %57 = call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %56)
  store i64 %57, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %65

58:                                               ; preds = %34
  %59 = load i64, ptr %8, align 8, !tbaa !9
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.iwulist, ptr %60, i32 0, i32 3
  store i64 %59, ptr %61, align 8, !tbaa !14
  %62 = load ptr, ptr %9, align 8, !tbaa !5
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.iwulist, ptr %63, i32 0, i32 0
  store ptr %62, ptr %64, align 8, !tbaa !15
  store i32 0, ptr %10, align 4
  br label %65

65:                                               ; preds = %58, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %66 = load i32, ptr %10, align 4
  switch i32 %66, label %120 [
    i32 0, label %67
    i32 1, label %118
  ]

67:                                               ; preds = %65
  br label %68

68:                                               ; preds = %67, %17
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.iwulist, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !15
  %72 = load i64, ptr %6, align 8, !tbaa !9
  %73 = add i64 %72, 1
  %74 = load ptr, ptr %5, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.iwulist, ptr %74, i32 0, i32 1
  %76 = load i64, ptr %75, align 8, !tbaa !16
  %77 = mul i64 %73, %76
  %78 = getelementptr inbounds i8, ptr %71, i64 %77
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.iwulist, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !15
  %82 = load i64, ptr %6, align 8, !tbaa !9
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.iwulist, ptr %83, i32 0, i32 1
  %85 = load i64, ptr %84, align 8, !tbaa !16
  %86 = mul i64 %82, %85
  %87 = getelementptr inbounds i8, ptr %81, i64 %86
  %88 = load ptr, ptr %5, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.iwulist, ptr %88, i32 0, i32 4
  %90 = load i64, ptr %89, align 8, !tbaa !13
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.iwulist, ptr %91, i32 0, i32 2
  %93 = load i64, ptr %92, align 8, !tbaa !11
  %94 = add i64 %90, %93
  %95 = load i64, ptr %6, align 8, !tbaa !9
  %96 = sub i64 %94, %95
  %97 = load ptr, ptr %5, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.iwulist, ptr %97, i32 0, i32 1
  %99 = load i64, ptr %98, align 8, !tbaa !16
  %100 = mul i64 %96, %99
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %78, ptr align 1 %87, i64 %100, i1 false)
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.iwulist, ptr %101, i32 0, i32 0
  %103 = load ptr, ptr %102, align 8, !tbaa !15
  %104 = load i64, ptr %6, align 8, !tbaa !9
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.iwulist, ptr %105, i32 0, i32 1
  %107 = load i64, ptr %106, align 8, !tbaa !16
  %108 = mul i64 %104, %107
  %109 = getelementptr inbounds i8, ptr %103, i64 %108
  %110 = load ptr, ptr %7, align 8, !tbaa !5
  %111 = load ptr, ptr %5, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.iwulist, ptr %111, i32 0, i32 1
  %113 = load i64, ptr %112, align 8, !tbaa !16
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %109, ptr align 1 %110, i64 %113, i1 false)
  %114 = load ptr, ptr %5, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.iwulist, ptr %114, i32 0, i32 2
  %116 = load i64, ptr %115, align 8, !tbaa !11
  %117 = add i64 %116, 1
  store i64 %117, ptr %115, align 8, !tbaa !11
  store i64 0, ptr %4, align 8
  br label %118

118:                                              ; preds = %68, %65, %16
  %119 = load i64, ptr %4, align 8
  ret i64 %119

120:                                              ; preds = %65
  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 16}
!12 = !{!"iwulist", !6, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!13 = !{!12, !10, i64 32}
!14 = !{!12, !10, i64 24}
!15 = !{!12, !6, i64 0}
!16 = !{!12, !10, i64 8}
!17 = !{!18, !18, i64 0}
!18 = !{!"int", !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"

; 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

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 @iwulist_insert(ptr nocapture noundef %0, i64 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #4 {
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = icmp ult i64 %5, %1
  br i1 %6, label %45, label %7

7:                                                ; preds = %3
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = add i64 %9, %1
  %11 = add i64 %9, %5
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = load i64, ptr %12, align 8, !tbaa !12
  %.not = icmp ult i64 %11, %13
  %.pre = load ptr, ptr %0, align 8, !tbaa !13
  br i1 %.not, label %25, label %14

14:                                               ; preds = %7
  %15 = add i64 %5, 1
  %16 = add i64 %15, %13
  %17 = getelementptr inbounds i8, ptr %0, i64 8
  %18 = load i64, ptr %17, align 8, !tbaa !14
  %19 = mul i64 %18, %16
  %20 = tail call ptr @realloc(ptr noundef %.pre, i64 noundef %19) #5
  %.not39 = icmp eq ptr %20, null
  br i1 %.not39, label %21, label %.thread

.thread:                                          ; preds = %14
  store i64 %16, ptr %12, align 8, !tbaa !12
  store ptr %20, ptr %0, align 8, !tbaa !13
  %.pre42 = load i64, ptr %8, align 8, !tbaa !11
  %.pre43 = load i64, ptr %4, align 8, !tbaa !5
  br label %25

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

25:                                               ; preds = %.thread, %7
  %26 = phi i64 [ %.pre43, %.thread ], [ %5, %7 ]
  %27 = phi i64 [ %.pre42, %.thread ], [ %9, %7 ]
  %28 = phi ptr [ %20, %.thread ], [ %.pre, %7 ]
  %29 = add i64 %10, 1
  %30 = getelementptr inbounds i8, ptr %0, i64 8
  %31 = load i64, ptr %30, align 8, !tbaa !14
  %32 = mul i64 %31, %29
  %33 = getelementptr inbounds i8, ptr %28, i64 %32
  %34 = mul i64 %31, %10
  %35 = getelementptr inbounds i8, ptr %28, i64 %34
  %36 = sub i64 %27, %10
  %37 = add i64 %36, %26
  %38 = mul i64 %37, %31
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %33, ptr align 1 %35, i64 %38, i1 false)
  %39 = load ptr, ptr %0, align 8, !tbaa !13
  %40 = load i64, ptr %30, align 8, !tbaa !14
  %41 = mul i64 %40, %10
  %42 = getelementptr inbounds i8, ptr %39, i64 %41
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %42, ptr align 1 %2, i64 %40, i1 false)
  %43 = load i64, ptr %4, align 8, !tbaa !5
  %44 = add i64 %43, 1
  store i64 %44, ptr %4, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %21, %3, %25
  %.1 = phi i64 [ %24, %21 ], [ 0, %25 ], [ 70011, %3 ]
  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 16}
!6 = !{!"iwulist", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!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 32}
!12 = !{!6, !10, i64 24}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !10, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !8, i64 0}


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