; 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 @insert(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = call i32 @hashFunction(i32 noundef %9)
  store i32 %10, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %11 = call noalias ptr @malloc(i64 noundef 12) #4
  store ptr %11, ptr %7, align 8, !tbaa !9
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = load ptr, ptr %7, align 8, !tbaa !9
  %14 = getelementptr inbounds %struct.HashEntry, ptr %13, i32 0, i32 0
  store i32 %12, ptr %14, align 4, !tbaa !11
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load ptr, ptr %7, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.HashEntry, ptr %16, i32 0, i32 1
  store i32 %15, ptr %17, align 4, !tbaa !13
  %18 = load ptr, ptr %7, align 8, !tbaa !9
  %19 = getelementptr inbounds %struct.HashEntry, ptr %18, i32 0, i32 2
  store i32 0, ptr %19, align 4, !tbaa !14
  br label %20

20:                                               ; preds = %58, %2
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %34

26:                                               ; preds = %20
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.HashEntry, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !11
  %33 = icmp ne i32 %32, -1
  br label %34

34:                                               ; preds = %26, %20
  %35 = phi i1 [ false, %20 ], [ %33, %26 ]
  br i1 %35, label %36, label %64

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

45:                                               ; preds = %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !9
  store ptr %49, ptr %8, align 8, !tbaa !9
  %50 = load ptr, ptr %7, align 8, !tbaa !9
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %52
  store ptr %50, ptr %53, align 8, !tbaa !9
  %54 = load ptr, ptr %8, align 8, !tbaa !9
  store ptr %54, ptr %7, align 8, !tbaa !9
  %55 = load ptr, ptr %7, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.HashEntry, ptr %55, i32 0, i32 2
  %57 = load i32, ptr %56, align 4, !tbaa !14
  store i32 %57, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %58

58:                                               ; preds = %45, %36
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  %61 = srem i32 %60, 100
  store i32 %61, ptr %5, align 4, !tbaa !5
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %6, align 4, !tbaa !5
  br label %20, !llvm.loop !15

64:                                               ; preds = %34
  %65 = load ptr, ptr %7, align 8, !tbaa !9
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %67
  store ptr %65, ptr %68, align 8, !tbaa !9
  %69 = load i32, ptr %6, align 4, !tbaa !5
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %71
  %73 = load ptr, ptr %72, align 8, !tbaa !9
  %74 = getelementptr inbounds %struct.HashEntry, ptr %73, i32 0, i32 2
  store i32 %69, ptr %74, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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 allocsize(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 }
attributes #4 = { nounwind allocsize(0) }

!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 @insert(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @hashFunction(i32 noundef %0)
  %4 = tail call noalias dereferenceable_or_null(12) ptr @malloc(i64 noundef 12) #2
  store i32 %0, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 %1, ptr %5, align 4, !tbaa !10
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 0, ptr %6, align 4, !tbaa !11
  %7 = sext i32 %3 to i64
  %8 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %7
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %.not25 = icmp eq ptr %9, null
  br i1 %.not25, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %18
  %10 = phi ptr [ %24, %18 ], [ %9, %2 ]
  %11 = phi ptr [ %23, %18 ], [ %8, %2 ]
  %.028 = phi i32 [ %20, %18 ], [ %3, %2 ]
  %.02027 = phi ptr [ %.1, %18 ], [ %4, %2 ]
  %.02126 = phi i32 [ %21, %18 ], [ 0, %2 ]
  %12 = load i32, ptr %10, align 4, !tbaa !5
  %.not24 = icmp eq i32 %12, -1
  br i1 %.not24, label %.critedge, label %13

13:                                               ; preds = %.lr.ph
  %14 = getelementptr inbounds i8, ptr %10, i64 8
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = icmp slt i32 %15, %.02126
  br i1 %16, label %17, label %18

17:                                               ; preds = %13
  store ptr %.02027, ptr %11, align 8, !tbaa !12
  br label %18

18:                                               ; preds = %17, %13
  %.122 = phi i32 [ %15, %17 ], [ %.02126, %13 ]
  %.1 = phi ptr [ %10, %17 ], [ %.02027, %13 ]
  %19 = add nsw i32 %.028, 1
  %20 = srem i32 %19, 100
  %21 = add nsw i32 %.122, 1
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [100 x ptr], ptr @hashTable, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %.not = icmp eq ptr %24, null
  br i1 %.not, label %.critedge, label %.lr.ph, !llvm.loop !14

.critedge:                                        ; preds = %.lr.ph, %18, %2
  %.021.lcssa = phi i32 [ 0, %2 ], [ %21, %18 ], [ %.02126, %.lr.ph ]
  %.020.lcssa = phi ptr [ %4, %2 ], [ %.1, %18 ], [ %.02027, %.lr.ph ]
  %.lcssa = phi ptr [ %8, %2 ], [ %23, %18 ], [ %11, %.lr.ph ]
  store ptr %.020.lcssa, ptr %.lcssa, align 8, !tbaa !12
  %25 = getelementptr inbounds i8, ptr %.020.lcssa, i64 8
  store i32 %.021.lcssa, ptr %25, align 4, !tbaa !11
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #2 = { nounwind allocsize(0) }

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


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