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

13:                                               ; preds = %1
  store i64 70011, ptr %2, align 8
  br label %96

14:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.iwulist, ptr %15, i32 0, i32 2
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = sub i64 %17, 1
  store i64 %18, ptr %4, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.iwulist, ptr %19, i32 0, i32 4
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = add i64 %21, 1
  store i64 %22, ptr %5, align 8, !tbaa !12
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.iwulist, ptr %23, i32 0, i32 3
  %25 = load i64, ptr %24, align 8, !tbaa !14
  %26 = icmp ugt i64 %25, 32
  br i1 %26, label %27, label %88

27:                                               ; preds = %14
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.iwulist, ptr %28, i32 0, i32 3
  %30 = load i64, ptr %29, align 8, !tbaa !14
  %31 = load i64, ptr %4, align 8, !tbaa !12
  %32 = mul i64 %31, 2
  %33 = icmp uge i64 %30, %32
  br i1 %33, label %34, label %88

34:                                               ; preds = %27
  %35 = load i64, ptr %5, align 8, !tbaa !12
  %36 = icmp ne i64 %35, 0
  br i1 %36, label %37, label %55

37:                                               ; preds = %34
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.iwulist, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.iwulist, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = load i64, ptr %5, align 8, !tbaa !12
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.iwulist, ptr %45, i32 0, i32 1
  %47 = load i64, ptr %46, align 8, !tbaa !16
  %48 = mul i64 %44, %47
  %49 = getelementptr inbounds i8, ptr %43, i64 %48
  %50 = load i64, ptr %4, align 8, !tbaa !12
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.iwulist, ptr %51, i32 0, i32 1
  %53 = load i64, ptr %52, align 8, !tbaa !16
  %54 = mul i64 %50, %53
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %40, ptr align 1 %49, i64 %54, i1 false)
  store i64 0, ptr %5, align 8, !tbaa !12
  br label %55

55:                                               ; preds = %37, %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %56 = load i64, ptr %4, align 8, !tbaa !12
  %57 = icmp ugt i64 %56, 32
  br i1 %57, label %58, label %60

58:                                               ; preds = %55
  %59 = load i64, ptr %4, align 8, !tbaa !12
  br label %61

60:                                               ; preds = %55
  br label %61

61:                                               ; preds = %60, %58
  %62 = phi i64 [ %59, %58 ], [ 32, %60 ]
  store i64 %62, ptr %6, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.iwulist, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !15
  %66 = load i64, ptr %6, align 8, !tbaa !12
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.iwulist, ptr %67, i32 0, i32 1
  %69 = load i64, ptr %68, align 8, !tbaa !16
  %70 = mul i64 %66, %69
  %71 = call ptr @realloc(ptr noundef %65, i64 noundef %70) #7
  store ptr %71, ptr %7, align 8, !tbaa !5
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = icmp ne ptr %72, null
  br i1 %73, label %78, label %74

74:                                               ; preds = %61
  %75 = call ptr @__errno_location() #8
  %76 = load i32, ptr %75, align 4, !tbaa !17
  %77 = call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %76)
  store i64 %77, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %85

78:                                               ; preds = %61
  %79 = load i64, ptr %6, align 8, !tbaa !12
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.iwulist, ptr %80, i32 0, i32 3
  store i64 %79, ptr %81, align 8, !tbaa !14
  %82 = load ptr, ptr %7, align 8, !tbaa !5
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.iwulist, ptr %83, i32 0, i32 0
  store ptr %82, ptr %84, align 8, !tbaa !15
  store i32 0, ptr %8, align 4
  br label %85

85:                                               ; preds = %78, %74
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %86 = load i32, ptr %8, align 4
  switch i32 %86, label %95 [
    i32 0, label %87
  ]

87:                                               ; preds = %85
  br label %88

88:                                               ; preds = %87, %27, %14
  %89 = load i64, ptr %5, align 8, !tbaa !12
  %90 = load ptr, ptr %3, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.iwulist, ptr %90, i32 0, i32 4
  store i64 %89, ptr %91, align 8, !tbaa !13
  %92 = load i64, ptr %4, align 8, !tbaa !12
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.iwulist, ptr %93, i32 0, i32 2
  store i64 %92, ptr %94, align 8, !tbaa !9
  store i64 0, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %95

95:                                               ; preds = %88, %85
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  br label %96

96:                                               ; preds = %95, %13
  %97 = load i64, ptr %2, align 8
  ret i64 %97
}

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

4:                                                ; preds = %1
  %5 = add i64 %3, -1
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  %7 = load i64, ptr %6, align 8, !tbaa !11
  %8 = add i64 %7, 1
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load i64, ptr %9, align 8, !tbaa !12
  %11 = icmp ult i64 %10, 33
  %12 = shl i64 %5, 1
  %.not36 = icmp ult i64 %10, %12
  %or.cond = or i1 %11, %.not36
  br i1 %or.cond, label %32, label %13

13:                                               ; preds = %4
  %.not37 = icmp eq i64 %8, 0
  br i1 %.not37, label %21, label %14

14:                                               ; preds = %13
  %15 = load ptr, ptr %0, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load i64, ptr %16, align 8, !tbaa !14
  %18 = mul i64 %17, %8
  %19 = getelementptr inbounds i8, ptr %15, i64 %18
  %20 = mul i64 %17, %5
  tail call void @llvm.memmove.p0.p0.i64(ptr align 1 %15, ptr align 1 %19, i64 %20, i1 false)
  br label %21

21:                                               ; preds = %14, %13
  %22 = tail call i64 @llvm.umax.i64(i64 %5, i64 32)
  %23 = load ptr, ptr %0, align 8, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  %25 = load i64, ptr %24, align 8, !tbaa !14
  %26 = mul i64 %25, %22
  %27 = tail call ptr @realloc(ptr noundef %23, i64 noundef %26) #6
  %.not38.not = icmp eq ptr %27, null
  br i1 %.not38.not, label %.thread, label %31

.thread:                                          ; preds = %21
  %28 = tail call ptr @__errno_location() #7
  %29 = load i32, ptr %28, align 4, !tbaa !15
  %30 = tail call i64 @iwrc_set_errno(i64 noundef 70013, i32 noundef %29) #8
  br label %33

31:                                               ; preds = %21
  store i64 %22, ptr %9, align 8, !tbaa !12
  store ptr %27, ptr %0, align 8, !tbaa !13
  br label %32

32:                                               ; preds = %31, %4
  %.130 = phi i64 [ 0, %31 ], [ %8, %4 ]
  store i64 %.130, ptr %6, align 8, !tbaa !11
  store i64 %5, ptr %2, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %.thread, %32, %1
  %.2 = phi i64 [ 70011, %1 ], [ 0, %32 ], [ %30, %.thread ]
  ret i64 %.2
}

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