; LLVM IR from fcimeson/cbTSP :: cbLKH/SRC (Hashing)

; 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.HashTable = type { [65521 x %struct.HashTableEntry], i32 }
%struct.HashTableEntry = type { i32, 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: nounwind uwtable
define dso_local i32 @HashSearch(ptr noundef %0, i32 noundef %1, i64 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i64 %2, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = urem i32 %9, 65521
  store i32 %10, ptr %7, align 4, !tbaa !9
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = urem i32 %11, 97
  %13 = add i32 %12, 1
  store i32 %13, ptr %8, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %53, %3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.HashTable, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [65521 x %struct.HashTableEntry], ptr %16, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.HashTableEntry, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !13
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = icmp ne i32 %21, %22
  br i1 %23, label %34, label %24

24:                                               ; preds = %14
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.HashTable, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [65521 x %struct.HashTableEntry], ptr %26, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.HashTableEntry, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !15
  %32 = load i64, ptr %6, align 8, !tbaa !11
  %33 = icmp ne i64 %31, %32
  br i1 %33, label %34, label %43

34:                                               ; preds = %24, %14
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.HashTable, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [65521 x %struct.HashTableEntry], ptr %36, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.HashTableEntry, ptr %39, i32 0, i32 1
  %41 = load i64, ptr %40, align 8, !tbaa !15
  %42 = icmp ne i64 %41, -9223372036854775808
  br label %43

43:                                               ; preds = %34, %24
  %44 = phi i1 [ false, %24 ], [ %42, %34 ]
  br i1 %44, label %45, label %54

45:                                               ; preds = %43
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = sub nsw i32 %47, %46
  store i32 %48, ptr %7, align 4, !tbaa !9
  %49 = icmp slt i32 %48, 0
  br i1 %49, label %50, label %53

50:                                               ; preds = %45
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = add nsw i32 %51, 65521
  store i32 %52, ptr %7, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %50, %45
  br label %14, !llvm.loop !16

54:                                               ; preds = %43
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.HashTable, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [65521 x %struct.HashTableEntry], ptr %56, i64 0, i64 %58
  %60 = getelementptr inbounds %struct.HashTableEntry, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !13
  %62 = load i32, ptr %5, align 4, !tbaa !9
  %63 = icmp eq i32 %61, %62
  %64 = zext i1 %63 to i32
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i32 %64
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"HashTableEntry", !10, i64 0, !12, i64 8}
!15 = !{!14, !12, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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.HashTableEntry = type { i32, i64 }

; Function Attrs: nofree norecurse nosync nounwind memory(argmem: read) uwtable
define dso_local range(i32 0, 2) i32 @HashSearch(ptr nocapture noundef readonly %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = urem i32 %1, 65521
  %5 = urem i32 %1, 97
  %.neg = xor i32 %5, -1
  %6 = zext nneg i32 %4 to i64
  %7 = getelementptr inbounds [65521 x %struct.HashTableEntry], ptr %0, i64 0, i64 %6
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %.not20 = icmp eq i32 %8, %1
  %9 = getelementptr inbounds i8, ptr %7, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !11
  %.not1721 = icmp eq i64 %10, %2
  %or.cond22 = select i1 %.not20, i1 %.not1721, i1 false
  %.not1823 = icmp eq i64 %10, -9223372036854775808
  %or.cond1924 = select i1 %or.cond22, i1 true, i1 %.not1823
  br i1 %or.cond1924, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.025 = phi i32 [ %spec.select, %.lr.ph ], [ %4, %3 ]
  %11 = add i32 %.025, %.neg
  %12 = icmp slt i32 %11, 0
  %13 = add nsw i32 %11, 65521
  %spec.select = select i1 %12, i32 %13, i32 %11
  %14 = zext nneg i32 %spec.select to i64
  %15 = getelementptr inbounds [65521 x %struct.HashTableEntry], ptr %0, i64 0, i64 %14
  %16 = load i32, ptr %15, align 8, !tbaa !5
  %.not = icmp eq i32 %16, %1
  %17 = getelementptr inbounds i8, ptr %15, i64 8
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %.not17 = icmp eq i64 %18, %2
  %or.cond = select i1 %.not, i1 %.not17, i1 false
  %.not18 = icmp eq i64 %18, -9223372036854775808
  %or.cond19 = select i1 %or.cond, i1 true, i1 %.not18
  br i1 %or.cond19, label %.critedge, label %.lr.ph, !llvm.loop !12

.critedge:                                        ; preds = %.lr.ph, %3
  %.not.lcssa = phi i1 [ %.not20, %3 ], [ %.not, %.lr.ph ]
  %19 = zext i1 %.not.lcssa to i32
  ret i32 %19
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: read) 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, !7, i64 0}
!6 = !{!"HashTableEntry", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass