; LLVM IR from AlgoGenesis/C :: Hash Algorithms/Robin Hood Hashing (Program)

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

@hashTable = external dso_local global [100 x ptr], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @hashFunction(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 void @delete(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = call i32 @hashFunction(i32 noundef %6)
  store i32 %7, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %49, %1
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %55

14:                                               ; preds = %8
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %16
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.HashEntry, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 4, !tbaa !11
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = icmp eq i32 %20, %21
  br i1 %22, label %23, label %39

23:                                               ; preds = %14
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.HashEntry, ptr %27, i32 0, i32 0
  store i32 -1, ptr %28, align 4, !tbaa !11
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.HashEntry, ptr %32, i32 0, i32 1
  store i32 0, ptr %33, align 4, !tbaa !13
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.HashEntry, ptr %37, i32 0, i32 2
  store i32 0, ptr %38, align 4, !tbaa !14
  store i32 1, ptr %5, align 4
  br label %56

39:                                               ; preds = %14
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %41
  %43 = load ptr, ptr %42, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.HashEntry, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 4, !tbaa !14
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = icmp slt i32 %45, %46
  br i1 %47, label %48, label %49

48:                                               ; preds = %39
  br label %55

49:                                               ; preds = %39
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  %52 = srem i32 %51, 100
  store i32 %52, ptr %3, align 4, !tbaa !5
  %53 = load i32, ptr %4, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %4, align 4, !tbaa !5
  br label %8, !llvm.loop !15

55:                                               ; preds = %48, %8
  store i32 0, ptr %5, align 4
  br label %56

56:                                               ; preds = %55, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  %57 = load i32, ptr %5, align 4
  switch i32 %57, label %59 [
    i32 0, label %58
    i32 1, label %58
  ]

58:                                               ; preds = %56, %56
  ret void

59:                                               ; preds = %56
  unreachable
}

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 = { 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 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@hashTable = external dso_local local_unnamed_addr global [100 x ptr], align 16

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

; Function Attrs: nounwind uwtable
define dso_local void @delete(i32 noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @hashFunction(i32 noundef %0)
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %3
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %.not14 = icmp eq ptr %5, null
  br i1 %.not14, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %1, %16
  %6 = phi ptr [ %22, %16 ], [ %5, %1 ]
  %.016 = phi i32 [ %19, %16 ], [ 0, %1 ]
  %.01115 = phi i32 [ %18, %16 ], [ %2, %1 ]
  %7 = load i32, ptr %6, align 4, !tbaa !9
  %8 = icmp eq i32 %7, %0
  br i1 %8, label %9, label %12

9:                                                ; preds = %.lr.ph
  store i32 -1, ptr %6, align 4, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %6, i64 4
  store i32 0, ptr %10, align 4, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 0, ptr %11, align 4, !tbaa !13
  br label %.loopexit

12:                                               ; preds = %.lr.ph
  %13 = getelementptr inbounds i8, ptr %6, i64 8
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = icmp slt i32 %14, %.016
  br i1 %15, label %.loopexit, label %16

16:                                               ; preds = %12
  %17 = add nsw i32 %.01115, 1
  %18 = srem i32 %17, 100
  %19 = add nuw nsw i32 %.016, 1
  %20 = sext i32 %18 to i64
  %21 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %20
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  %.not = icmp eq ptr %22, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !14

.loopexit:                                        ; preds = %12, %16, %1, %9
  ret void
}

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" }

!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 0}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !11, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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