; LLVM IR from Softmotions/iowow :: src/utils (iwhmap)

; 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.iwhmap_iter = type { ptr, ptr, ptr, i32, i32 }
%struct.iwhmap = type { i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i8 }
%struct.bucket_t = type { ptr, i32, i32 }
%struct.entry = type { ptr, ptr, ptr, i32 }

; 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: alwaysinline nounwind uwtable
declare hidden i32 @_n_buckets(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @iwhmap_iter_next(ptr noundef %0) #2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.iwhmap_iter, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %1
  store i1 false, ptr %2, align 1
  br label %105

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.iwhmap_iter, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.iwhmap, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.iwhmap_iter, ptr %19, i32 0, i32 3
  %21 = load i32, ptr %20, align 8, !tbaa !15
  %22 = zext i32 %21 to i64
  %23 = getelementptr inbounds %struct.bucket_t, ptr %18, i64 %22
  store ptr %23, ptr %5, align 8, !tbaa !5
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.iwhmap_iter, ptr %24, i32 0, i32 4
  %26 = load i32, ptr %25, align 4, !tbaa !16
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %25, align 4, !tbaa !16
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.iwhmap_iter, ptr %28, i32 0, i32 4
  %30 = load i32, ptr %29, align 4, !tbaa !16
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.bucket_t, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !17
  %34 = icmp uge i32 %30, %33
  br i1 %34, label %35, label %85

35:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.iwhmap_iter, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = call i32 @_n_buckets(ptr noundef %38)
  store i32 %39, ptr %6, align 4, !tbaa !19
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.iwhmap_iter, ptr %40, i32 0, i32 4
  store i32 0, ptr %41, align 4, !tbaa !16
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.iwhmap_iter, ptr %42, i32 0, i32 3
  %44 = load i32, ptr %43, align 8, !tbaa !15
  %45 = add i32 %44, 1
  store i32 %45, ptr %43, align 8, !tbaa !15
  br label %46

46:                                               ; preds = %69, %35
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.iwhmap_iter, ptr %47, i32 0, i32 3
  %49 = load i32, ptr %48, align 8, !tbaa !15
  %50 = load i32, ptr %6, align 4, !tbaa !19
  %51 = icmp ult i32 %49, %50
  br i1 %51, label %52, label %74

52:                                               ; preds = %46
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.iwhmap_iter, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.iwhmap, ptr %55, i32 0, i32 2
  %57 = load ptr, ptr %56, align 8, !tbaa !12
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.iwhmap_iter, ptr %58, i32 0, i32 3
  %60 = load i32, ptr %59, align 8, !tbaa !15
  %61 = zext i32 %60 to i64
  %62 = getelementptr inbounds %struct.bucket_t, ptr %57, i64 %61
  store ptr %62, ptr %5, align 8, !tbaa !5
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.bucket_t, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %64, align 8, !tbaa !17
  %66 = icmp ugt i32 %65, 0
  br i1 %66, label %67, label %68

67:                                               ; preds = %52
  br label %74

68:                                               ; preds = %52
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.iwhmap_iter, ptr %70, i32 0, i32 3
  %72 = load i32, ptr %71, align 8, !tbaa !15
  %73 = add i32 %72, 1
  store i32 %73, ptr %71, align 8, !tbaa !15
  br label %46, !llvm.loop !20

74:                                               ; preds = %67, %46
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.iwhmap_iter, ptr %75, i32 0, i32 3
  %77 = load i32, ptr %76, align 8, !tbaa !15
  %78 = load i32, ptr %6, align 4, !tbaa !19
  %79 = icmp uge i32 %77, %78
  br i1 %79, label %80, label %81

80:                                               ; preds = %74
  store i1 false, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %82

81:                                               ; preds = %74
  store i32 0, ptr %7, align 4
  br label %82

82:                                               ; preds = %81, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %83 = load i32, ptr %7, align 4
  switch i32 %83, label %104 [
    i32 0, label %84
  ]

84:                                               ; preds = %82
  br label %85

85:                                               ; preds = %84, %13
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.bucket_t, ptr %86, i32 0, i32 0
  %88 = load ptr, ptr %87, align 8, !tbaa !22
  %89 = load ptr, ptr %3, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.iwhmap_iter, ptr %89, i32 0, i32 4
  %91 = load i32, ptr %90, align 4, !tbaa !16
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds %struct.entry, ptr %88, i64 %92
  store ptr %93, ptr %4, align 8, !tbaa !5
  %94 = load ptr, ptr %4, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.entry, ptr %94, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8, !tbaa !23
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.iwhmap_iter, ptr %97, i32 0, i32 1
  store ptr %96, ptr %98, align 8, !tbaa !25
  %99 = load ptr, ptr %4, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.entry, ptr %99, i32 0, i32 1
  %101 = load ptr, ptr %100, align 8, !tbaa !26
  %102 = load ptr, ptr %3, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.iwhmap_iter, ptr %102, i32 0, i32 2
  store ptr %101, ptr %103, align 8, !tbaa !27
  store i1 true, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %104

104:                                              ; preds = %85, %82
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %105

105:                                              ; preds = %104, %12
  %106 = load i1, ptr %2, align 1
  ret i1 %106
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline 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 #2 = { 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 #3 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"iwhmap_iter", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24, !11, i64 28}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 8}
!13 = !{!"iwhmap", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !14, i64 72}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!10, !11, i64 24}
!16 = !{!10, !11, i64 28}
!17 = !{!18, !11, i64 8}
!18 = !{!"", !6, i64 0, !11, i64 8, !11, i64 12}
!19 = !{!11, !11, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!18, !6, i64 0}
!23 = !{!24, !6, i64 0}
!24 = !{!"entry", !6, i64 0, !6, i64 8, !6, i64 16, !11, i64 24}
!25 = !{!10, !6, i64 8}
!26 = !{!24, !6, i64 8}
!27 = !{!10, !6, i64 16}


; 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.bucket_t = type { ptr, i32, i32 }
%struct.entry = type { ptr, ptr, ptr, i32 }

; Function Attrs: alwaysinline nounwind uwtable
declare hidden i32 @_n_buckets(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @iwhmap_iter_next(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %35, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %2, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load i32, ptr %6, align 8, !tbaa !14
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds %struct.bucket_t, ptr %5, i64 %8
  %10 = getelementptr inbounds i8, ptr %0, i64 28
  %11 = load i32, ptr %10, align 4, !tbaa !15
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr %10, align 4, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %9, i64 8
  %14 = load i32, ptr %13, align 8, !tbaa !16
  %.not30 = icmp ult i32 %12, %14
  br i1 %.not30, label %.thread, label %15

15:                                               ; preds = %3
  %16 = tail call i32 @_n_buckets(ptr noundef nonnull %2)
  store i32 0, ptr %10, align 4, !tbaa !15
  %17 = load i32, ptr %6, align 8, !tbaa !14
  %18 = add i32 %17, 1
  %umax = tail call i32 @llvm.umax.i32(i32 %16, i32 %18)
  br label %19

19:                                               ; preds = %21, %15
  %storemerge.in = phi i32 [ %17, %15 ], [ %storemerge, %21 ]
  %storemerge = add i32 %storemerge.in, 1
  %20 = icmp ult i32 %storemerge, %16
  br i1 %20, label %21, label %.loopexit

21:                                               ; preds = %19
  %22 = load ptr, ptr %0, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = zext i32 %storemerge to i64
  %26 = getelementptr inbounds %struct.bucket_t, ptr %24, i64 %25
  %27 = getelementptr inbounds i8, ptr %26, i64 8
  %28 = load i32, ptr %27, align 8, !tbaa !16
  %.not31 = icmp eq i32 %28, 0
  br i1 %.not31, label %19, label %.thread.loopexit, !llvm.loop !18

.thread.loopexit:                                 ; preds = %21
  store i32 %storemerge, ptr %6, align 8, !tbaa !14
  br label %.thread

.thread:                                          ; preds = %.thread.loopexit, %3
  %29 = phi i32 [ %12, %3 ], [ 0, %.thread.loopexit ]
  %.227 = phi ptr [ %9, %3 ], [ %26, %.thread.loopexit ]
  %30 = load ptr, ptr %.227, align 8, !tbaa !20
  %31 = sext i32 %29 to i64
  %32 = getelementptr inbounds %struct.entry, ptr %30, i64 %31
  %33 = getelementptr inbounds i8, ptr %0, i64 8
  %34 = load <2 x ptr>, ptr %32, align 8, !tbaa !21
  store <2 x ptr> %34, ptr %33, align 8, !tbaa !21
  br label %35

.loopexit:                                        ; preds = %19
  store i32 %umax, ptr %6, align 8, !tbaa !14
  br label %35

35:                                               ; preds = %.loopexit, %.thread, %1
  %.2 = phi i1 [ false, %1 ], [ true, %.thread ], [ false, %.loopexit ]
  ret i1 %.2
}

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

attributes #0 = { alwaysinline 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 #1 = { 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 #2 = { nocallback nofree nosync nounwind speculatable 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, !7, i64 0}
!6 = !{!"iwhmap_iter", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 8}
!12 = !{!"iwhmap", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !13, i64 72}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{!6, !10, i64 24}
!15 = !{!6, !10, i64 28}
!16 = !{!17, !10, i64 8}
!17 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!17, !7, i64 0}
!21 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass