; LLVM IR from xxks-kkk/algo :: hashTable/open-addressing (oa)

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

@.str.3 = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @initializeTable(i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @find(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %7 = load ptr, ptr %4, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct.HashTbl, ptr %7, i32 0, i32 0
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = call ptr @initializeTable(i32 noundef %9)
  store ptr %10, ptr %6, align 8, !tbaa !9
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.HashTbl, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !11
  %15 = call i32 @hash(i32 noundef %11, i32 noundef %14)
  store i32 %15, ptr %5, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %59, %2
  %17 = load ptr, ptr %4, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.HashTbl, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = zext i32 %20 to i64
  %22 = getelementptr inbounds %struct.HashEntry, ptr %19, i64 %21
  %23 = getelementptr inbounds %struct.HashEntry, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !14
  %25 = icmp ne i32 %24, 1
  br i1 %25, label %26, label %37

26:                                               ; preds = %16
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.HashTbl, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = zext i32 %30 to i64
  %32 = getelementptr inbounds %struct.HashEntry, ptr %29, i64 %31
  %33 = getelementptr inbounds %struct.HashEntry, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 4, !tbaa !16
  %35 = load i32, ptr %3, align 4, !tbaa !5
  %36 = icmp ne i32 %34, %35
  br label %37

37:                                               ; preds = %26, %16
  %38 = phi i1 [ false, %16 ], [ %36, %26 ]
  br i1 %38, label %39, label %62

39:                                               ; preds = %37
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = load ptr, ptr %4, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.HashTbl, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !11
  %44 = icmp uge i32 %40, %43
  br i1 %44, label %45, label %51

45:                                               ; preds = %39
  %46 = load ptr, ptr %4, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.HashTbl, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !11
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = sub i32 %49, %48
  store i32 %50, ptr %5, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %45, %39
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = load ptr, ptr %6, align 8, !tbaa !9
  %54 = call i32 @isTried(i32 noundef %52, ptr noundef %53)
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %59

56:                                               ; preds = %51
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %57)
  br label %62

59:                                               ; preds = %51
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = load ptr, ptr %6, align 8, !tbaa !9
  call void @insert(i32 noundef %60, ptr noundef %61)
  br label %16, !llvm.loop !17

62:                                               ; preds = %56, %37
  %63 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %63
}

; Function Attrs: nounwind uwtable
declare hidden i32 @hash(i32 noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @isTried(i32 noundef, ptr noundef) #0

declare i32 @printf(ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local void @insert(i32 noundef, ptr noundef) #0

attributes #0 = { 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 = { nocallback nofree nosync 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 }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"HashTbl", !6, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = !{!15, !6, i64 4}
!15 = !{!"HashEntry", !6, i64 0, !6, i64 4}
!16 = !{!15, !6, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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.HashEntry = type { i32, i32 }

@.str.3 = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @initializeTable(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @find(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %1, align 8, !tbaa !5
  %4 = tail call ptr @initializeTable(i32 noundef %3)
  %5 = load i32, ptr %1, align 8, !tbaa !5
  %6 = tail call i32 @hash(i32 noundef %0, i32 noundef %5)
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = zext i32 %6 to i64
  %10 = getelementptr inbounds %struct.HashEntry, ptr %8, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %.not23 = icmp eq i32 %12, 1
  br i1 %.not23, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %21
  %13 = phi ptr [ %24, %21 ], [ %10, %2 ]
  %.024 = phi i32 [ %spec.select, %21 ], [ %6, %2 ]
  %14 = load i32, ptr %13, align 4, !tbaa !14
  %.not19 = icmp eq i32 %14, %0
  br i1 %.not19, label %.critedge, label %15

15:                                               ; preds = %.lr.ph
  %16 = load i32, ptr %1, align 8, !tbaa !5
  %.not20 = icmp ult i32 %.024, %16
  %17 = select i1 %.not20, i32 0, i32 %16
  %spec.select = sub i32 %.024, %17
  %18 = tail call i32 @isTried(i32 noundef %spec.select, ptr noundef %4)
  %.not21 = icmp eq i32 %18, 0
  br i1 %.not21, label %21, label %19

19:                                               ; preds = %15
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %0)
  br label %.critedge

21:                                               ; preds = %15
  tail call void @insert(i32 noundef %spec.select, ptr noundef %4)
  %22 = load ptr, ptr %7, align 8, !tbaa !11
  %23 = zext i32 %spec.select to i64
  %24 = getelementptr inbounds %struct.HashEntry, ptr %22, i64 %23
  %25 = getelementptr inbounds i8, ptr %24, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !12
  %.not = icmp eq i32 %26, 1
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !15

.critedge:                                        ; preds = %.lr.ph, %21, %2, %19
  %.2 = phi i32 [ %spec.select, %19 ], [ %6, %2 ], [ %.024, %.lr.ph ], [ %spec.select, %21 ]
  ret i32 %.2
}

; Function Attrs: nounwind uwtable
declare hidden i32 @hash(i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @insert(i32 noundef, ptr noundef) local_unnamed_addr #0

attributes #0 = { 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 = { nofree nounwind "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" }

!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 = !{!"HashTbl", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!13, !7, i64 4}
!13 = !{!"HashEntry", !7, i64 0, !7, i64 4}
!14 = !{!13, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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