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

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.iwulist, ptr %14, i32 0, i32 2
  %16 = load i64, ptr %15, align 8, !tbaa !12
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.iwulist, ptr %17, i32 0, i32 3
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = icmp uge i64 %16, %19
  br i1 %20, label %21, label %55

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

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

45:                                               ; preds = %21
  %46 = load i64, ptr %6, align 8, !tbaa !14
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.iwulist, ptr %47, i32 0, i32 3
  store i64 %46, ptr %48, align 8, !tbaa !13
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.iwulist, ptr %50, i32 0, i32 0
  store ptr %49, ptr %51, align 8, !tbaa !15
  store i32 0, ptr %8, align 4
  br label %52

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

54:                                               ; preds = %52
  br label %55

55:                                               ; preds = %54, %13
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.iwulist, ptr %56, i32 0, i32 3
  %58 = load i64, ptr %57, align 8, !tbaa !13
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.iwulist, ptr %59, i32 0, i32 2
  %61 = load i64, ptr %60, align 8, !tbaa !12
  %62 = sub i64 %58, %61
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.iwulist, ptr %63, i32 0, i32 4
  store i64 %62, ptr %64, align 8, !tbaa !9
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.iwulist, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !15
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.iwulist, ptr %68, i32 0, i32 4
  %70 = load i64, ptr %69, align 8, !tbaa !9
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.iwulist, ptr %71, i32 0, i32 1
  %73 = load i64, ptr %72, align 8, !tbaa !16
  %74 = mul i64 %70, %73
  %75 = getelementptr inbounds i8, ptr %67, i64 %74
  %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 !15
  %79 = load ptr, ptr %4, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.iwulist, ptr %79, i32 0, i32 2
  %81 = load i64, ptr %80, align 8, !tbaa !12
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.iwulist, ptr %82, i32 0, i32 1
  %84 = load i64, ptr %83, align 8, !tbaa !16
  %85 = mul i64 %81, %84
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %75, ptr align 1 %78, i64 %85, i1 false)
  br label %86

86:                                               ; preds = %55, %2
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.iwulist, ptr %87, i32 0, i32 0
  %89 = load ptr, ptr %88, align 8, !tbaa !15
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.iwulist, ptr %90, i32 0, i32 4
  %92 = load i64, ptr %91, align 8, !tbaa !9
  %93 = sub i64 %92, 1
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.iwulist, ptr %94, i32 0, i32 1
  %96 = load i64, ptr %95, align 8, !tbaa !16
  %97 = mul i64 %93, %96
  %98 = getelementptr inbounds i8, ptr %89, i64 %97
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.iwulist, ptr %100, i32 0, i32 1
  %102 = load i64, ptr %101, align 8, !tbaa !16
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %98, ptr align 1 %99, i64 %102, i1 false)
  %103 = load ptr, ptr %4, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.iwulist, ptr %103, i32 0, i32 4
  %105 = load i64, ptr %104, align 8, !tbaa !9
  %106 = add i64 %105, -1
  store i64 %106, ptr %104, align 8, !tbaa !9
  %107 = load ptr, ptr %4, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.iwulist, ptr %107, i32 0, i32 2
  %109 = load i64, ptr %108, align 8, !tbaa !12
  %110 = add i64 %109, 1
  store i64 %110, ptr %108, align 8, !tbaa !12
  store i64 0, ptr %3, align 8
  br label %111

111:                                              ; preds = %86, %52
  %112 = load i64, ptr %3, align 8
  ret i64 %112

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

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load i64, ptr %8, align 8, !tbaa !12
  %.not34 = icmp ult i64 %7, %9
  %.pre38 = load ptr, ptr %0, align 8, !tbaa !13
  br i1 %.not34, label %21, label %10

10:                                               ; preds = %5
  %11 = add i64 %7, 1
  %12 = add i64 %11, %9
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load i64, ptr %13, align 8, !tbaa !14
  %15 = mul i64 %14, %12
  %16 = tail call ptr @realloc(ptr noundef %.pre38, i64 noundef %15) #5
  %.not35 = icmp eq ptr %16, null
  br i1 %.not35, label %17, label %.thread

.thread:                                          ; preds = %10
  store i64 %12, ptr %8, align 8, !tbaa !12
  store ptr %16, ptr %0, align 8, !tbaa !13
  %.pre = load i64, ptr %6, align 8, !tbaa !11
  br label %21

17:                                               ; preds = %10
  %18 = tail call ptr @__errno_location() #6
  %19 = load i32, ptr %18, align 4, !tbaa !15
  %20 = tail call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %19) #7
  br label %44

21:                                               ; preds = %.thread, %5
  %22 = phi ptr [ %16, %.thread ], [ %.pre38, %5 ]
  %23 = phi i64 [ %.pre, %.thread ], [ %7, %5 ]
  %24 = phi i64 [ %12, %.thread ], [ %9, %5 ]
  %25 = sub i64 %24, %23
  store i64 %25, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  %27 = load i64, ptr %26, align 8, !tbaa !14
  %28 = mul i64 %27, %25
  %29 = getelementptr inbounds i8, ptr %22, i64 %28
  %30 = mul i64 %27, %23
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %29, ptr align 1 %22, i64 %30, i1 false)
  %.pre39 = load i64, ptr %3, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %21, %2
  %32 = phi i64 [ %.pre39, %21 ], [ %4, %2 ]
  %33 = load ptr, ptr %0, align 8, !tbaa !13
  %34 = add i64 %32, -1
  %35 = getelementptr inbounds i8, ptr %0, i64 8
  %36 = load i64, ptr %35, align 8, !tbaa !14
  %37 = mul i64 %34, %36
  %38 = getelementptr inbounds i8, ptr %33, i64 %37
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %38, ptr align 1 %1, i64 %36, i1 false)
  %39 = load i64, ptr %3, align 8, !tbaa !5
  %40 = add i64 %39, -1
  store i64 %40, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %0, i64 16
  %42 = load i64, ptr %41, align 8, !tbaa !11
  %43 = add i64 %42, 1
  store i64 %43, ptr %41, align 8, !tbaa !11
  br label %44

44:                                               ; preds = %17, %31
  %.1 = phi i64 [ 0, %31 ], [ %20, %17 ]
  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 32}
!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 16}
!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