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

14:                                               ; preds = %2
  store i64 70011, ptr %3, align 8
  br label %137

15:                                               ; preds = %2
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.iwulist, ptr %16, i32 0, i32 4
  %18 = load i64, ptr %17, align 8, !tbaa !13
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = add i64 %19, %18
  store i64 %20, ptr %5, align 8, !tbaa !9
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.iwulist, ptr %21, i32 0, i32 2
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = add i64 %23, -1
  store i64 %24, ptr %22, align 8, !tbaa !11
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.iwulist, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = load i64, ptr %5, align 8, !tbaa !9
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.iwulist, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !15
  %32 = mul i64 %28, %31
  %33 = getelementptr inbounds i8, ptr %27, i64 %32
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.iwulist, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = load i64, ptr %5, align 8, !tbaa !9
  %38 = add i64 %37, 1
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.iwulist, ptr %39, i32 0, i32 1
  %41 = load i64, ptr %40, align 8, !tbaa !15
  %42 = mul i64 %38, %41
  %43 = getelementptr inbounds i8, ptr %36, i64 %42
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.iwulist, ptr %44, i32 0, i32 4
  %46 = load i64, ptr %45, align 8, !tbaa !13
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.iwulist, ptr %47, i32 0, i32 2
  %49 = load i64, ptr %48, align 8, !tbaa !11
  %50 = add i64 %46, %49
  %51 = load i64, ptr %5, align 8, !tbaa !9
  %52 = sub i64 %50, %51
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.iwulist, ptr %53, i32 0, i32 1
  %55 = load i64, ptr %54, align 8, !tbaa !15
  %56 = mul i64 %52, %55
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %33, ptr align 1 %43, i64 %56, i1 false)
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.iwulist, ptr %57, i32 0, i32 3
  %59 = load i64, ptr %58, align 8, !tbaa !16
  %60 = icmp ugt i64 %59, 32
  br i1 %60, label %61, label %136

61:                                               ; preds = %15
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.iwulist, ptr %62, i32 0, i32 3
  %64 = load i64, ptr %63, align 8, !tbaa !16
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.iwulist, ptr %65, i32 0, i32 2
  %67 = load i64, ptr %66, align 8, !tbaa !11
  %68 = mul i64 %67, 2
  %69 = icmp uge i64 %64, %68
  br i1 %69, label %70, label %136

70:                                               ; preds = %61
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.iwulist, ptr %71, i32 0, i32 4
  %73 = load i64, ptr %72, align 8, !tbaa !13
  %74 = icmp ne i64 %73, 0
  br i1 %74, label %75, label %99

75:                                               ; preds = %70
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.iwulist, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !14
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.iwulist, ptr %79, i32 0, i32 0
  %81 = load ptr, ptr %80, align 8, !tbaa !14
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.iwulist, ptr %82, i32 0, i32 4
  %84 = load i64, ptr %83, align 8, !tbaa !13
  %85 = load ptr, ptr %4, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.iwulist, ptr %85, i32 0, i32 1
  %87 = load i64, ptr %86, align 8, !tbaa !15
  %88 = mul i64 %84, %87
  %89 = getelementptr inbounds i8, ptr %81, i64 %88
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.iwulist, ptr %90, i32 0, i32 2
  %92 = load i64, ptr %91, align 8, !tbaa !11
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.iwulist, ptr %93, i32 0, i32 1
  %95 = load i64, ptr %94, align 8, !tbaa !15
  %96 = mul i64 %92, %95
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %78, ptr align 1 %89, i64 %96, i1 false)
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.iwulist, ptr %97, i32 0, i32 4
  store i64 0, ptr %98, align 8, !tbaa !13
  br label %99

99:                                               ; preds = %75, %70
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.iwulist, ptr %100, i32 0, i32 2
  %102 = load i64, ptr %101, align 8, !tbaa !11
  %103 = icmp ugt i64 %102, 32
  br i1 %103, label %104, label %108

104:                                              ; preds = %99
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.iwulist, ptr %105, i32 0, i32 2
  %107 = load i64, ptr %106, align 8, !tbaa !11
  br label %109

108:                                              ; preds = %99
  br label %109

109:                                              ; preds = %108, %104
  %110 = phi i64 [ %107, %104 ], [ 32, %108 ]
  store i64 %110, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %111 = load ptr, ptr %4, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.iwulist, ptr %111, i32 0, i32 0
  %113 = load ptr, ptr %112, align 8, !tbaa !14
  %114 = load i64, ptr %6, align 8, !tbaa !9
  %115 = load ptr, ptr %4, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.iwulist, ptr %115, i32 0, i32 1
  %117 = load i64, ptr %116, align 8, !tbaa !15
  %118 = mul i64 %114, %117
  %119 = call ptr @realloc(ptr noundef %113, i64 noundef %118) #7
  store ptr %119, ptr %7, align 8, !tbaa !5
  %120 = load ptr, ptr %7, align 8, !tbaa !5
  %121 = icmp ne ptr %120, null
  br i1 %121, label %126, label %122

122:                                              ; preds = %109
  %123 = call ptr @__errno_location() #8
  %124 = load i32, ptr %123, align 4, !tbaa !17
  %125 = call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %124)
  store i64 %125, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %133

126:                                              ; preds = %109
  %127 = load i64, ptr %6, align 8, !tbaa !9
  %128 = load ptr, ptr %4, align 8, !tbaa !5
  %129 = getelementptr inbounds %struct.iwulist, ptr %128, i32 0, i32 3
  store i64 %127, ptr %129, align 8, !tbaa !16
  %130 = load ptr, ptr %7, align 8, !tbaa !5
  %131 = load ptr, ptr %4, align 8, !tbaa !5
  %132 = getelementptr inbounds %struct.iwulist, ptr %131, i32 0, i32 0
  store ptr %130, ptr %132, align 8, !tbaa !14
  store i32 0, ptr %8, align 4
  br label %133

133:                                              ; preds = %126, %122
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %134 = load i32, ptr %8, align 4
  switch i32 %134, label %139 [
    i32 0, label %135
    i32 1, label %137
  ]

135:                                              ; preds = %133
  br label %136

136:                                              ; preds = %135, %61, %15
  store i64 0, ptr %3, align 8
  br label %137

137:                                              ; preds = %136, %133, %14
  %138 = load i64, ptr %3, align 8
  ret i64 %138

139:                                              ; preds = %133
  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, !6, i64 0}
!15 = !{!12, !10, i64 8}
!16 = !{!12, !10, i64 24}
!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.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_remove(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #4 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not = icmp ugt i64 %4, %1
  br i1 %.not, label %5, label %45

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %8 = add i64 %7, %1
  %9 = add i64 %4, -1
  store i64 %9, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %0, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !13
  %13 = mul i64 %12, %8
  %14 = getelementptr inbounds i8, ptr %10, i64 %13
  %15 = add i64 %8, 1
  %16 = mul i64 %12, %15
  %17 = getelementptr inbounds i8, ptr %10, i64 %16
  %18 = add i64 %7, %9
  %19 = sub i64 %18, %8
  %20 = mul i64 %12, %19
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %14, ptr align 1 %17, i64 %20, i1 false)
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = load i64, ptr %21, align 8, !tbaa !14
  %23 = icmp ugt i64 %22, 32
  br i1 %23, label %24, label %45

24:                                               ; preds = %5
  %25 = load i64, ptr %3, align 8, !tbaa !5
  %26 = shl i64 %25, 1
  %.not44 = icmp ult i64 %22, %26
  br i1 %.not44, label %45, label %27

27:                                               ; preds = %24
  %28 = load i64, ptr %6, align 8, !tbaa !11
  %.not45 = icmp eq i64 %28, 0
  br i1 %.not45, label %35, label %29

29:                                               ; preds = %27
  %30 = load ptr, ptr %0, align 8, !tbaa !12
  %31 = load i64, ptr %11, align 8, !tbaa !13
  %32 = mul i64 %31, %28
  %33 = getelementptr inbounds i8, ptr %30, i64 %32
  %34 = mul i64 %31, %25
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %30, ptr align 1 %33, i64 %34, i1 false)
  store i64 0, ptr %6, align 8, !tbaa !11
  %.pre = load i64, ptr %3, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %29, %27
  %36 = phi i64 [ %.pre, %29 ], [ %25, %27 ]
  %spec.select = tail call i64 @llvm.umax.i64(i64 %36, i64 32)
  %37 = load ptr, ptr %0, align 8, !tbaa !12
  %38 = load i64, ptr %11, align 8, !tbaa !13
  %39 = mul i64 %38, %spec.select
  %40 = tail call ptr @realloc(ptr noundef %37, i64 noundef %39) #6
  %.not46 = icmp eq ptr %40, null
  br i1 %.not46, label %41, label %.thread

.thread:                                          ; preds = %35
  store i64 %spec.select, ptr %21, align 8, !tbaa !14
  store ptr %40, ptr %0, align 8, !tbaa !12
  br label %45

41:                                               ; preds = %35
  %42 = tail call ptr @__errno_location() #7
  %43 = load i32, ptr %42, align 4, !tbaa !15
  %44 = tail call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %43) #8
  br label %45

45:                                               ; preds = %5, %24, %.thread, %41, %2
  %.1 = phi i64 [ %44, %41 ], [ 70011, %2 ], [ 0, %.thread ], [ 0, %24 ], [ 0, %5 ]
  ret i64 %.1
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #5

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind allocsize(1) }
attributes #7 = { nounwind willreturn memory(none) }
attributes #8 = { 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, !7, i64 0}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !10, i64 24}
!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